/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/bundle/serializer/v08.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-17 00:47:52 UTC
  • mfrom: (7182 work)
  • mto: This revision was merged to the branch mainline in revision 7305.
  • Revision ID: jelmer@jelmer.uk-20181117004752-6ywampe5pfywlby4
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
 
74
74
    def write(self, to_file):
75
75
        """Write action as to a file"""
76
 
        p_texts = [' '.join([self.name]+self.parameters)]
 
76
        p_texts = [' '.join([self.name] + self.parameters)]
77
77
        for prop in self.properties:
78
78
            if len(prop) == 1:
79
79
                p_texts.append(prop[0])
91
91
            text_line = text_line[available:]
92
92
            to_file.write(b'\n... ')
93
93
            available = 79 - len(b'... ')
94
 
        to_file.write(text_line+b'\n')
 
94
        to_file.write(text_line + b'\n')
95
95
 
96
96
 
97
97
class BundleSerializerV08(BundleSerializer):
128
128
 
129
129
    def write_bundle(self, repository, revision_id, base_revision_id, out):
130
130
        """Helper function for translating write_bundle to write"""
131
 
        forced_bases = {revision_id:base_revision_id}
 
131
        forced_bases = {revision_id: base_revision_id}
132
132
        if base_revision_id is NULL_REVISION:
133
133
            base_revision_id = None
134
134
        graph = repository.get_graph()
135
135
        revision_ids = graph.find_unique_ancestors(revision_id,
136
 
            [base_revision_id])
 
136
                                                   [base_revision_id])
137
137
        revision_ids = list(repository.get_graph().iter_topo_order(
138
138
            revision_ids))
139
139
        revision_ids.reverse()
176
176
        else:
177
177
            f.write(b':\n')
178
178
            for entry in value:
179
 
                f.write(b'#' + (b' ' * (indent+2)))
 
179
                f.write(b'#' + (b' ' * (indent + 2)))
180
180
                if isinstance(entry, bytes):
181
181
                    f.write(entry)
182
182
                else:
259
259
            properties = []
260
260
        p_texts = ['%s:%s' % v for v in properties]
261
261
        self.to_file.write(b'=== ')
262
 
        self.to_file.write(' '.join([name]+parameters).encode('utf-8'))
 
262
        self.to_file.write(' '.join([name] + parameters).encode('utf-8'))
263
263
        self.to_file.write(' // '.join(p_texts).encode('utf-8'))
264
264
        self.to_file.write(b'\n')
265
265
 
273
273
        def do_diff(file_id, old_path, new_path, action, force_binary):
274
274
            def tree_lines(tree, path, require_text=False):
275
275
                if tree.has_id(file_id):
276
 
                    tree_file = tree.get_file(path, file_id)
 
276
                    tree_file = tree.get_file(path)
277
277
                    if require_text is True:
278
278
                        tree_file = text_file(tree_file)
279
279
                    return tree_file.readlines()
316
316
            action = Action('removed', [kind, path]).write(self.to_file)
317
317
 
318
318
        for path, file_id, kind in delta.added:
319
 
            action = Action('added', [kind, path], [('file-id', file_id.decode('utf-8'))])
320
 
            meta_modified = (kind=='file' and
321
 
                             new_tree.is_executable(path, file_id))
 
319
            action = Action(
 
320
                'added', [kind, path], [('file-id', file_id.decode('utf-8'))])
 
321
            meta_modified = (kind == 'file' and
 
322
                             new_tree.is_executable(path))
322
323
            finish_action(action, file_id, kind, meta_modified, True,
323
324
                          DEVNULL, path)
324
325
 
335
336
                          path, path)
336
337
 
337
338
        for path, file_id, kind in delta.unchanged:
338
 
            new_rev = new_tree.get_file_revision(path, file_id)
 
339
            new_rev = new_tree.get_file_revision(path)
339
340
            if new_rev is None:
340
341
                continue
341
 
            old_rev = old_tree.get_file_revision(old_tree.id2path(file_id), file_id)
 
342
            old_rev = old_tree.get_file_revision(old_tree.id2path(file_id))
342
343
            if new_rev != old_rev:
343
 
                action = Action('modified', [new_tree.kind(path, file_id),
344
 
                                             path])
 
344
                action = Action('modified', [new_tree.kind(path), path])
345
345
                action.add_utf8_property('last-changed', new_rev)
346
346
                action.write(self.to_file)
347
347
 
350
350
    """This class reads in a bundle from a file, and returns
351
351
    a Bundle object, which can then be applied against a tree.
352
352
    """
 
353
 
353
354
    def __init__(self, from_file):
354
355
        """Read in the bundle from the file.
355
356
 
425
426
        """
426
427
        if not line.startswith(b'#'):
427
428
            raise errors.MalformedHeader('Bzr header did not start with #')
428
 
        line = line[1:-1].decode('utf-8') # Remove the '#' and '\n'
429
 
        if line[:indent] == ' '*indent:
 
429
        line = line[1:-1].decode('utf-8')  # Remove the '#' and '\n'
 
430
        if line[:indent] == ' ' * indent:
430
431
            line = line[indent:]
431
432
        if not line:
432
 
            return None, None # Ignore blank lines
 
433
            return None, None  # Ignore blank lines
433
434
 
434
435
        loc = line.find(': ')
435
436
        if loc != -1:
436
437
            key = line[:loc]
437
 
            value = line[loc+2:]
 
438
            value = line[loc + 2:]
438
439
            if not value:
439
 
                value = self._read_many(indent=indent+2)
 
440
                value = self._read_many(indent=indent + 2)
440
441
        elif line[-1:] == ':':
441
442
            key = line[:-1]
442
 
            value = self._read_many(indent=indent+2)
 
443
            value = self._read_many(indent=indent + 2)
443
444
        else:
444
445
            raise errors.MalformedHeader('While looking for key: value pairs,'
445
 
                    ' did not find the colon %r' % (line))
 
446
                                         ' did not find the colon %r' % (line))
446
447
 
447
448
        key = key.replace(' ', '_')
448
449
        #mutter('found %s: %s' % (key, value))
480
481
        does not start properly indented.
481
482
        """
482
483
        values = []
483
 
        start = b'#' + (b' '*indent)
 
484
        start = b'#' + (b' ' * indent)
484
485
 
485
486
        if self._next_line is None or not self._next_line.startswith(start):
486
487
            return values
508
509
            if first:
509
510
                if not line.startswith(b'==='):
510
511
                    raise errors.MalformedPatches('The first line of all patches'
511
 
                        ' should be a bzr meta line "==="'
512
 
                        ': %r' % line)
 
512
                                                  ' should be a bzr meta line "==="'
 
513
                                                  ': %r' % line)
513
514
                action = line[4:-1].decode('utf-8')
514
515
            elif line.startswith(b'... '):
515
516
                action += line[len(b'... '):-1].decode('utf-8')
516
517
 
517
518
            if (self._next_line is not None and
518
 
                self._next_line.startswith(b'===')):
 
519
                    self._next_line.startswith(b'===')):
519
520
                return action, lines, True
520
521
            elif self._next_line is None or self._next_line.startswith(b'#'):
521
522
                return action, lines, False
553
554
                next(self._next())
554
555
                break
555
556
 
 
557
 
556
558
class BundleInfo08(BundleInfo):
557
559
 
558
560
    def _update_tree(self, bundle_tree, revision_id):