# HG changeset patch # User Mads Kiilerich # Date 1365555338 -7200 # Node ID 0d22458bd360a423d0f0f9470a897dee60917a14 # Parent 631e8000eae8b333390fbfd39ddfd547aec00cbc diff parser: more correct detection and reporting of binary git diffs git mode is not just used for binary diffs. diff -r 631e8000eae8 -r 0d22458bd360 rhodecode/lib/diffs.py --- a/rhodecode/lib/diffs.py Wed Apr 10 02:54:56 2013 +0200 +++ b/rhodecode/lib/diffs.py Wed Apr 10 02:55:38 2013 +0200 @@ -354,10 +354,12 @@ ##split the diff in chunks of separate --git a/file b/file chunks for raw_diff in ('\n' + self._diff).split('\ndiff --git')[1:]: - binary = False - binary_msg = 'unknown binary' head, diff = self._get_header(raw_diff) + op = None + stats = None + msg = None + if not head['a_file'] and head['b_file']: op = 'A' elif head['a_file'] and head['b_file']: @@ -365,34 +367,32 @@ elif head['a_file'] and not head['b_file']: op = 'D' else: - #probably we're dealing with a binary file 1 - binary = True if head['deleted_file_mode']: op = 'D' stats = ['b', DEL_FILENODE] - binary_msg = 'deleted binary file' + msg = 'deleted file' elif head['new_file_mode']: op = 'A' stats = ['b', NEW_FILENODE] - binary_msg = 'new binary file %s' % head['new_file_mode'] + msg = 'new file %s' % head['new_file_mode'] else: if head['new_mode'] and head['old_mode']: stats = ['b', CHMOD_FILENODE] op = 'M' - binary_msg = ('modified binary file chmod %s => %s' + msg = ('modified file chmod %s => %s' % (head['old_mode'], head['new_mode'])) elif (head['rename_from'] and head['rename_to'] and head['rename_from'] != head['rename_to']): stats = ['b', RENAMED_FILENODE] op = 'M' - binary_msg = ('file renamed from %s to %s' + msg = ('file renamed from %s to %s' % (head['rename_from'], head['rename_to'])) else: stats = ['b', MOD_FILENODE] op = 'M' - binary_msg = 'modified binary file' + msg = 'modified file' - if not binary: + if head['a_file'] or head['b_file']: # a real diff try: chunks, stats = self._parse_lines(diff) except DiffLimitExceeded: @@ -401,13 +401,17 @@ self.cur_diff_size, _diff) break - else: + else: # GIT binary patch (or empty diff) chunks = [] - chunks.append([{ + if not msg: # don't overwrite more important message + msg = 'binary diff not shown' + + if msg: + chunks.insert(0, [{ 'old_lineno': '', 'new_lineno': '', 'action': 'binary', - 'line': binary_msg, + 'line': msg, }]) _files.append({