Changeset - 2d2856fd1144
[Not reviewed]
default
0 2 1
duanhongyi - 11 years ago 2015-02-09 07:42:35
duanhongyi@doopai.com
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 .
3 files changed with 17 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/diffs.py
Show inline comments
 
@@ -360,13 +360,13 @@ class DiffProcessor(object):
 
        elif self.vcs == 'hg':
 
            match = self._hg_header_re.match(diff_chunk)
 
        if match is None:
 
            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
 

	
 
    def _clean_line(self, line, command):
 
        if command in ['+', '-', ' ']:
kallithea/tests/fixtures/git_diff_modify_binary_file.diff
Show inline comments
 
new file 100644
 
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
kallithea/tests/models/test_diff_parsers.py
Show inline comments
 
@@ -212,12 +212,20 @@ DIFF_FIXTURES = {
 
        ('vcs/tests/test_repository.py', 'M',
 
         {'added': 174,
 
          'deleted': 2,
 
          '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,
 
          'deleted': 0,
 
          'binary': True,
 
          'ops': {COPIED_FILENODE: 'file copied from file1 to file2'}}),
 
@@ -258,14 +266,12 @@ DIFF_FIXTURES = {
 

	
 

	
 
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]
 
        expected_data = DIFF_FIXTURES[diff_fixture]
 
        self.assertListEqual(expected_data, data)
0 comments (0 inline, 0 general)