~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/patches.py

  • Committer: Aaron Bentley
  • Date: 2009-11-03 15:45:56 UTC
  • mto: (4634.97.2 2.0)
  • mto: This revision was merged to the branch mainline in revision 4798.
  • Revision ID: aaron@aaronbentley.com-20091103154556-e953dmegqbinyokq
Improve patch binary section handling.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import re
18
18
 
19
19
 
 
20
binary_files_re = 'Binary files (.*) and (.*) differ\n'
 
21
 
 
22
 
20
23
class BinaryFiles(Exception):
21
24
 
22
25
    def __init__(self, orig_name, mod_name):
66
69
def get_patch_names(iter_lines):
67
70
    try:
68
71
        line = iter_lines.next()
69
 
        match = re.match('Binary files (.*) and (.*) differ\n', line)
 
72
        match = re.match(binary_files_re, line)
70
73
        if match is not None:
71
74
            raise BinaryFiles(match.group(1), match.group(2))
72
75
        if not line.startswith("--- "):
350
353
 
351
354
 
352
355
def iter_file_patch(iter_lines):
 
356
    regex = re.compile(binary_files_re)
353
357
    saved_lines = []
354
358
    orig_range = 0
355
359
    for line in iter_lines:
360
364
        elif orig_range > 0:
361
365
            if line.startswith('-') or line.startswith(' '):
362
366
                orig_range -= 1
363
 
        elif line.startswith('--- '):
 
367
        elif line.startswith('--- ') or regex.match(line):
364
368
            if len(saved_lines) > 0:
365
369
                yield saved_lines
366
370
            saved_lines = []