/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: Jelmer Vernooij
  • Date: 2020-12-29 23:20:51 UTC
  • mto: (7490.40.131 work)
  • mto: This revision was merged to the branch mainline in revision 7532.
  • Revision ID: jelmer@jelmer.uk-20201229232051-fu51kn0s5s87gn2r
Parse out patch timestamps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
            raise MalformedPatchHeader("No orig name", line)
90
90
        else:
91
91
            orig_name = line[4:].rstrip(b"\n")
 
92
            try:
 
93
                (orig_name, orig_ts) = orig_name.split(b'\t')
 
94
            except ValueError:
 
95
                orig_ts = None
92
96
    except StopIteration:
93
97
        raise MalformedPatchHeader("No orig line", "")
94
98
    try:
97
101
            raise PatchSyntax("No mod name")
98
102
        else:
99
103
            mod_name = line[4:].rstrip(b"\n")
 
104
            try:
 
105
                (mod_name, mod_ts) = mod_name.split(b'\t')
 
106
            except ValueError:
 
107
                mod_ts = None
100
108
    except StopIteration:
101
109
        raise MalformedPatchHeader("No mod line", "")
102
 
    return (orig_name, mod_name)
 
110
    return ((orig_name, orig_ts), (mod_name, mod_ts))
103
111
 
104
112
 
105
113
def parse_range(textrange):
320
328
        self.newname = newname
321
329
 
322
330
    def as_bytes(self):
323
 
        return b'Binary files %s and %s differ\n' % (self.oldname, self.newname)
 
331
        return b'Binary files %s and %s differ\n' % (
 
332
            self.oldname, self.newname)
324
333
 
325
334
 
326
335
class Patch(BinaryPatch):
327
336
 
328
 
    def __init__(self, oldname, newname):
 
337
    def __init__(self, oldname, newname, oldts=None, newts=None):
329
338
        BinaryPatch.__init__(self, oldname, newname)
 
339
        self.oldts = oldts
 
340
        self.newts = newts
330
341
        self.hunks = []
331
342
 
332
343
    def as_bytes(self):
334
345
        ret += b"".join([h.as_bytes() for h in self.hunks])
335
346
        return ret
336
347
 
 
348
    @classmethod
 
349
    def _headerline(cls, start, name, ts):
 
350
        l = start + b' ' + name
 
351
        if ts is not None:
 
352
            l += b'\t%s' % ts
 
353
        l += b'\n'
 
354
        return l
 
355
 
337
356
    def get_header(self):
338
 
        return b"--- %s\n+++ %s\n" % (self.oldname, self.newname)
 
357
        return (
 
358
            self._headerline(b'---', self.oldname, self.oldts) +
 
359
            self._headerline(b'+++', self.newname, self.newts))
339
360
 
340
361
    def stats_values(self):
341
362
        """Calculate the number of inserts and removes."""
387
408
    '''
388
409
    iter_lines = iter_lines_handle_nl(iter_lines)
389
410
    try:
390
 
        (orig_name, mod_name) = get_patch_names(iter_lines)
 
411
        ((orig_name, orig_ts), (mod_name, mod_ts)) = get_patch_names(
 
412
            iter_lines)
391
413
    except BinaryFiles as e:
392
414
        return BinaryPatch(e.orig_name, e.mod_name)
393
415
    else:
394
 
        patch = Patch(orig_name, mod_name)
 
416
        patch = Patch(orig_name, mod_name, orig_ts, mod_ts)
395
417
        for hunk in iter_hunks(iter_lines, allow_dirty):
396
418
            patch.hunks.append(hunk)
397
419
        return patch