# HG changeset patch # User duanhongyi # Date 2015-02-09 07:42:35 # Node ID 2d2856fd114414a570d07376be86a87ee821dd71 # Parent 53d766fc9782d53bc8521996d69da272629eecc4 diff: handle GIT delta binary patches It seems like they only occur rarely; recent git versions do apparently not create them. Using a test case from https://secure.phabricator.com/T6157 . diff --git a/kallithea/lib/diffs.py b/kallithea/lib/diffs.py --- a/kallithea/lib/diffs.py +++ b/kallithea/lib/diffs.py @@ -363,7 +363,7 @@ class DiffProcessor(object): raise Exception('diff not recognized as valid %s diff' % self.vcs) groups = match.groupdict() rest = diff_chunk[match.end():] - if rest and not rest.startswith('@') and not rest.startswith('literal '): + if rest and not rest.startswith('@') and not rest.startswith('literal ') and not rest.startswith('delta '): raise Exception('cannot parse diff header: %r followed by %r' % (diff_chunk[:match.end()], rest[:1000])) difflines = imap(self._escaper, re.findall(r'.*\n|.+$', rest)) # don't split on \r as str.splitlines do return groups, difflines diff --git a/kallithea/tests/fixtures/git_diff_modify_binary_file.diff b/kallithea/tests/fixtures/git_diff_modify_binary_file.diff new file mode 100644 --- /dev/null +++ b/kallithea/tests/fixtures/git_diff_modify_binary_file.diff @@ -0,0 +1,8 @@ +diff --git a/file.name b/file.name +index 033c3ac88947362c4227a3ae44d556d5d2665ef0..0dd4757a6bbe6cd99b57f092f3a5e69a4158fce3 100644 +GIT binary patch +delta 21 +ccmey(*vd4agxfi>Bsn87DJNASZDMH~09UpM8~^|S + +delta 11 +ScmZo=`pr0@gwbtceH#E7tpsHN diff --git a/kallithea/tests/models/test_diff_parsers.py b/kallithea/tests/models/test_diff_parsers.py --- a/kallithea/tests/models/test_diff_parsers.py +++ b/kallithea/tests/models/test_diff_parsers.py @@ -215,6 +215,14 @@ DIFF_FIXTURES = { 'binary': False, 'ops': {MOD_FILENODE: 'modified file'}}), ], + 'git_diff_modify_binary_file.diff': [ + ('file.name', 'M', + {'added': 0, + 'deleted': 0, + 'binary': True, + 'ops': {MOD_FILENODE: 'modified file', + BIN_FILENODE: 'binary diff not shown'}}) + ], 'hg_diff_copy_file.diff': [ ('file2', 'M', {'added': 0, @@ -261,9 +269,7 @@ class DiffLibTest(BaseTestCase): @parameterized.expand([(x,) for x in DIFF_FIXTURES]) def test_diff(self, diff_fixture): - diff = fixture.load_resource(diff_fixture, strip=False) - diff_proc = DiffProcessor(diff) diff_proc_d = diff_proc.prepare() data = [(x['filename'], x['operation'], x['stats']) for x in diff_proc_d]