/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/patches.py

  • Committer: Breezy landing bot
  • Author(s): Gustav Hartvigsson
  • Date: 2021-01-10 18:46:30 UTC
  • mfrom: (7526.1.1 brz-removed-api-doc)
  • mto: This revision was merged to the branch mainline in revision 7532.
  • Revision ID: breezy.the.bot@gmail.com-20210110184630-dxu0g9dqq020uiw6
Drop documentation for removed API API.

Merged from https://code.launchpad.net/~gustav-hartvigsson/brz/removed-api-doc/+merge/396033

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
            raise MalformedPatchHeader("No orig name", line)
88
88
        else:
89
89
            orig_name = line[4:].rstrip(b"\n")
 
90
            try:
 
91
                (orig_name, orig_ts) = orig_name.split(b'\t')
 
92
            except ValueError:
 
93
                orig_ts = None
90
94
    except StopIteration:
91
95
        raise MalformedPatchHeader("No orig line", "")
92
96
    try:
95
99
            raise PatchSyntax("No mod name")
96
100
        else:
97
101
            mod_name = line[4:].rstrip(b"\n")
 
102
            try:
 
103
                (mod_name, mod_ts) = mod_name.split(b'\t')
 
104
            except ValueError:
 
105
                mod_ts = None
98
106
    except StopIteration:
99
107
        raise MalformedPatchHeader("No mod line", "")
100
 
    return (orig_name, mod_name)
 
108
    return ((orig_name, orig_ts), (mod_name, mod_ts))
101
109
 
102
110
 
103
111
def parse_range(textrange):
318
326
        self.newname = newname
319
327
 
320
328
    def as_bytes(self):
321
 
        return b'Binary files %s and %s differ\n' % (self.oldname, self.newname)
 
329
        return b'Binary files %s and %s differ\n' % (
 
330
            self.oldname, self.newname)
322
331
 
323
332
 
324
333
class Patch(BinaryPatch):
325
334
 
326
 
    def __init__(self, oldname, newname):
 
335
    def __init__(self, oldname, newname, oldts=None, newts=None):
327
336
        BinaryPatch.__init__(self, oldname, newname)
 
337
        self.oldts = oldts
 
338
        self.newts = newts
328
339
        self.hunks = []
329
340
 
330
341
    def as_bytes(self):
332
343
        ret += b"".join([h.as_bytes() for h in self.hunks])
333
344
        return ret
334
345
 
 
346
    @classmethod
 
347
    def _headerline(cls, start, name, ts):
 
348
        l = start + b' ' + name
 
349
        if ts is not None:
 
350
            l += b'\t%s' % ts
 
351
        l += b'\n'
 
352
        return l
 
353
 
335
354
    def get_header(self):
336
 
        return b"--- %s\n+++ %s\n" % (self.oldname, self.newname)
 
355
        return (
 
356
            self._headerline(b'---', self.oldname, self.oldts) +
 
357
            self._headerline(b'+++', self.newname, self.newts))
337
358
 
338
359
    def stats_values(self):
339
360
        """Calculate the number of inserts and removes."""
385
406
    '''
386
407
    iter_lines = iter_lines_handle_nl(iter_lines)
387
408
    try:
388
 
        (orig_name, mod_name) = get_patch_names(iter_lines)
 
409
        ((orig_name, orig_ts), (mod_name, mod_ts)) = get_patch_names(
 
410
            iter_lines)
389
411
    except BinaryFiles as e:
390
412
        return BinaryPatch(e.orig_name, e.mod_name)
391
413
    else:
392
 
        patch = Patch(orig_name, mod_name)
 
414
        patch = Patch(orig_name, mod_name, orig_ts, mod_ts)
393
415
        for hunk in iter_hunks(iter_lines, allow_dirty):
394
416
            patch.hunks.append(hunk)
395
417
        return patch
417
439
 
418
440
    for line in iter_lines:
419
441
        if line.startswith(b'=== '):
420
 
            if len(saved_lines) > 0:
 
442
            if allow_dirty and beginning:
 
443
                # Patches can have "junk" at the beginning
 
444
                # Stripping junk from the end of patches is handled when we
 
445
                # parse the patch
 
446
                pass
 
447
            elif len(saved_lines) > 0:
421
448
                if keep_dirty and len(dirty_head) > 0:
422
449
                    yield {'saved_lines': saved_lines,
423
450
                           'dirty_head': dirty_head}
610
637
        self.prefix = prefix
611
638
 
612
639
    def __enter__(self):
613
 
        from .transform import TransformPreview
614
 
        self._tt = TransformPreview(self.tree)
 
640
        self._tt = self.tree.preview_transform()
615
641
        apply_patches(self._tt, self.patches, prefix=self.prefix)
616
642
        return self._tt.get_preview_tree()
617
643