Rev 4702: (abentley) Improve handling of binary file sections in patches. in file:///home/pqm/archives/thelove/bzr/2.0/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Nov 6 04:44:07 GMT 2009
At file:///home/pqm/archives/thelove/bzr/2.0/
------------------------------------------------------------
revno: 4702 [merge]
revision-id: pqm at pqm.ubuntu.com-20091106044405-hv2ojnz3iasu4py5
parent: pqm at pqm.ubuntu.com-20091106005605-hpz13cboo3otga4x
parent: aaron at aaronbentley.com-20091103155422-604t5mnjhyd5qm3q
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.0
timestamp: Fri 2009-11-06 04:44:05 +0000
message:
(abentley) Improve handling of binary file sections in patches.
added:
bzrlib/tests/test_patches_data/binary-after-normal.patch binaryafternormal.pa-20091103153908-9xu6wqrosgnjzk8e-1
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/patches.py patches.py-20050727183609-378c1cc5972ce908
bzrlib/tests/test_patches.py test_patches.py-20051231203844-f4974d20f6aea09c
=== modified file 'NEWS'
--- a/NEWS 2009-10-30 15:58:10 +0000
+++ b/NEWS 2009-11-03 15:54:22 +0000
@@ -19,6 +19,7 @@
Bug Fixes
*********
+* Improve "Binary files differ" hunk handling. (Aaron Bentley, #436325)
Improvements
************
=== modified file 'bzrlib/patches.py'
--- a/bzrlib/patches.py 2009-10-14 22:08:45 +0000
+++ b/bzrlib/patches.py 2009-11-03 15:45:56 +0000
@@ -17,6 +17,9 @@
import re
+binary_files_re = 'Binary files (.*) and (.*) differ\n'
+
+
class BinaryFiles(Exception):
def __init__(self, orig_name, mod_name):
@@ -66,7 +69,7 @@
def get_patch_names(iter_lines):
try:
line = iter_lines.next()
- match = re.match('Binary files (.*) and (.*) differ\n', line)
+ match = re.match(binary_files_re, line)
if match is not None:
raise BinaryFiles(match.group(1), match.group(2))
if not line.startswith("--- "):
@@ -350,6 +353,7 @@
def iter_file_patch(iter_lines):
+ regex = re.compile(binary_files_re)
saved_lines = []
orig_range = 0
for line in iter_lines:
@@ -360,7 +364,7 @@
elif orig_range > 0:
if line.startswith('-') or line.startswith(' '):
orig_range -= 1
- elif line.startswith('--- '):
+ elif line.startswith('--- ') or regex.match(line):
if len(saved_lines) > 0:
yield saved_lines
saved_lines = []
=== modified file 'bzrlib/tests/test_patches.py'
--- a/bzrlib/tests/test_patches.py 2009-10-15 15:25:20 +0000
+++ b/bzrlib/tests/test_patches.py 2009-11-03 15:45:56 +0000
@@ -156,6 +156,15 @@
self.assertContainsRe(str(patches[0]),
'Binary files bar\t.* and qux\t.* differ\n')
+ def test_parse_binary_after_normal(self):
+ patches = parse_patches(self.data_lines("binary-after-normal.patch"))
+ self.assertIs(BinaryPatch, patches[1].__class__)
+ self.assertIs(Patch, patches[0].__class__)
+ self.assertContainsRe(patches[1].oldname, '^bar\t')
+ self.assertContainsRe(patches[1].newname, '^qux\t')
+ self.assertContainsRe(str(patches[1]),
+ 'Binary files bar\t.* and qux\t.* differ\n')
+
def test_roundtrip_binary(self):
patchtext = ''.join(self.data_lines("binary.patch"))
patches = parse_patches(patchtext.splitlines(True))
=== added file 'bzrlib/tests/test_patches_data/binary-after-normal.patch'
--- a/bzrlib/tests/test_patches_data/binary-after-normal.patch 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/test_patches_data/binary-after-normal.patch 2009-11-03 15:45:56 +0000
@@ -0,0 +1,6 @@
+--- baz 2009-10-14 19:49:59 +0000
++++ quxx 2009-10-14 19:51:00 +0000
+@@ -1 +1 @@
+-hello
++goodbye
+Binary files bar 2009-10-14 19:49:59 +0000 and qux 2009-10-14 19:50:35 +0000 differ
More information about the bazaar-commits
mailing list