/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): Jelmer Vernooij
  • Date: 2021-01-10 01:31:27 UTC
  • mfrom: (7526.2.2 merge-3.1)
  • mto: This revision was merged to the branch mainline in revision 7532.
  • Revision ID: breezy.the.bot@gmail.com-20210110013127-vn6x2k2uv21p805n
Merge lp:brz/3.1

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/396037

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