~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/patches.py

  • Committer: Kit Randel
  • Date: 2014-12-09 22:45:08 UTC
  • mto: This revision was merged to the branch mainline in revision 6602.
  • Revision ID: kit.randel@canonical.com-20141209224508-h4l7pyy4lo4bwtm2
added modified prop to Patch/BinaryPatch, and get_patch_names logic

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
binary_files_re = 'Binary files (.*) and (.*) differ\n'
33
33
 
34
34
def get_patch_names(iter_lines):
 
35
    modified = False
 
36
    line = iter_lines.next()
 
37
 
 
38
    if line.startswith("=== "):
 
39
        modified = True
 
40
        line = iter_lines.next()
 
41
 
35
42
    try:
36
 
        line = iter_lines.next()
 
43
        print 'line: %s' % line
37
44
        match = re.match(binary_files_re, line)
38
45
        if match is not None:
39
46
            raise BinaryFiles(match.group(1), match.group(2))
51
58
            mod_name = line[4:].rstrip("\n")
52
59
    except StopIteration:
53
60
        raise MalformedPatchHeader("No mod line", "")
54
 
    return (orig_name, mod_name)
 
61
    return (orig_name, mod_name, modified)
55
62
 
56
63
 
57
64
def parse_range(textrange):
254
261
 
255
262
 
256
263
class BinaryPatch(object):
257
 
    def __init__(self, oldname, newname):
 
264
    def __init__(self, oldname, newname, modified=False):
258
265
        self.oldname = oldname
259
266
        self.newname = newname
 
267
        self.modified = modified  # patch has file modified header
260
268
 
261
269
    def __str__(self):
262
270
        return 'Binary files %s and %s differ\n' % (self.oldname, self.newname)
264
272
 
265
273
class Patch(BinaryPatch):
266
274
 
267
 
    def __init__(self, oldname, newname):
268
 
        BinaryPatch.__init__(self, oldname, newname)
 
275
    def __init__(self, oldname, newname, modified):
 
276
        BinaryPatch.__init__(self, oldname, newname, modified)
269
277
        self.hunks = []
270
278
 
271
279
    def __str__(self):
273
281
        ret += "".join([str(h) for h in self.hunks])
274
282
        return ret
275
283
 
 
284
    def get_modified_header(self):
 
285
        if self.modified:
 
286
            return "=== modified file '%s'" % self.oldname
 
287
 
276
288
    def get_header(self):
277
289
        return "--- %s\n+++ %s\n" % (self.oldname, self.newname)
278
290
 
326
338
    '''
327
339
    iter_lines = iter_lines_handle_nl(iter_lines)
328
340
    try:
329
 
        (orig_name, mod_name) = get_patch_names(iter_lines)
 
341
        (orig_name, mod_name, modified) = get_patch_names(iter_lines)
330
342
    except BinaryFiles, e:
331
343
        return BinaryPatch(e.orig_name, e.mod_name)
332
344
    else:
333
 
        patch = Patch(orig_name, mod_name)
 
345
        patch = Patch(orig_name, mod_name, modified)
334
346
        for hunk in iter_hunks(iter_lines, allow_dirty):
335
347
            patch.hunks.append(hunk)
336
348
        return patch
356
368
    beginning = True
357
369
    for line in iter_lines:
358
370
        if line.startswith('=== ') or line.startswith('*** '):
 
371
        #if line.startswith('*** '):
359
372
            continue
360
373
        if line.startswith('#'):
361
374
            continue