changeset 4823:2d2856fd1144

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 .
author duanhongyi <duanhongyi@doopai.com>
date Mon, 09 Feb 2015 14:42:35 +0800
parents 53d766fc9782
children 11422edf4bea
files kallithea/lib/diffs.py kallithea/tests/fixtures/git_diff_modify_binary_file.diff kallithea/tests/models/test_diff_parsers.py
diffstat 3 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/diffs.py	Tue Feb 03 21:39:31 2015 +0100
+++ b/kallithea/lib/diffs.py	Mon Feb 09 14:42:35 2015 +0800
@@ -363,7 +363,7 @@
             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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kallithea/tests/fixtures/git_diff_modify_binary_file.diff	Mon Feb 09 14:42:35 2015 +0800
@@ -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
--- a/kallithea/tests/models/test_diff_parsers.py	Tue Feb 03 21:39:31 2015 +0100
+++ b/kallithea/tests/models/test_diff_parsers.py	Mon Feb 09 14:42:35 2015 +0800
@@ -215,6 +215,14 @@
           '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 @@
 
     @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]