Changeset - 8df1bc51aa9c
[Not reviewed]
beta
0 1 0
Mads Kiilerich - 13 years ago 2013-04-10 03:00:20
madski@unity3d.com
diff parser: prefer git headers over old unified diff headers

Makes the diff show both rename and chmod info and the diff.
1 file changed with 28 insertions and 31 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/diffs.py
Show inline comments
 
@@ -351,59 +351,56 @@ class DiffProcessor(object):
 
    def _parse_gitdiff(self, inline_diff=True):
 
        _files = []
 
        diff_container = lambda arg: arg
 

	
 
        ##split the diff in chunks of separate --git a/file b/file chunks
 
        for raw_diff in ('\n' + self._diff).split('\ndiff --git')[1:]:
 
            head, diff = self._get_header(raw_diff)
 

	
 
            op = None
 
            stats = None
 
            msgs = []
 

	
 
            if not head['a_file'] and head['b_file']:
 
                op = 'A'
 
                stats = ['b', NEW_FILENODE]
 
                msgs.append('new file')
 
            elif head['a_file'] and head['b_file']:
 
                op = 'M'
 
                stats = ['b', MOD_FILENODE]
 
            elif head['a_file'] and not head['b_file']:
 
            if head['deleted_file_mode']:
 
                op = 'D'
 
                stats = ['b', DEL_FILENODE]
 
                msgs.append('deleted file')
 
            elif head['new_file_mode']:
 
                op = 'A'
 
                stats = ['b', NEW_FILENODE]
 
                msgs.append('new file %s' % head['new_file_mode'])
 
            else:
 
                if head['deleted_file_mode']:
 
                    op = 'D'
 
                    stats = ['b', DEL_FILENODE]
 
                    msgs.append('deleted file')
 
                elif head['new_file_mode']:
 
                    op = 'A'
 
                    stats = ['b', NEW_FILENODE]
 
                    msgs.append('new file %s' % head['new_file_mode'])
 
                else:
 
                    if head['new_mode'] and head['old_mode']:
 
                        op = 'M'
 
                        stats = ['b', CHMOD_FILENODE]
 
                        msgs.append('modified file chmod %s => %s'
 
                                      % (head['old_mode'], head['new_mode']))
 
                    if (head['rename_from'] and head['rename_to']
 
                          and head['rename_from'] != head['rename_to']):
 
                        op = 'M'
 
                        stats = ['b', RENAMED_FILENODE] # might overwrite CHMOD_FILENODE
 
                        msgs.append('file renamed from %s to %s'
 
                                      % (head['rename_from'], head['rename_to']))
 
                    if op is None:
 
                        op = 'M'
 
                        stats = ['b', MOD_FILENODE]
 
                if head['new_mode'] and head['old_mode']:
 
                    op = 'M'
 
                    stats = ['b', CHMOD_FILENODE]
 
                    msgs.append('modified file chmod %s => %s'
 
                                  % (head['old_mode'], head['new_mode']))
 
                if (head['rename_from'] and head['rename_to']
 
                      and head['rename_from'] != head['rename_to']):
 
                    op = 'M'
 
                    stats = ['b', RENAMED_FILENODE] # might overwrite CHMOD_FILENODE
 
                    msgs.append('file renamed from %s to %s'
 
                                  % (head['rename_from'], head['rename_to']))
 
                if op is None: # fall back: detect missed old style add or remove
 
                    if not head['a_file'] and head['b_file']:
 
                        op = 'A'
 
                        stats = ['b', NEW_FILENODE]
 
                        msgs.append('new file')
 
                    elif head['a_file'] and not head['b_file']:
 
                        op = 'D'
 
                        stats = ['b', DEL_FILENODE]
 
                        msgs.append('deleted file')
 
                if op is None:
 
                    op = 'M'
 
                    stats = ['b', MOD_FILENODE]
 

	
 
            if head['a_file'] or head['b_file']: # a real diff
 
                try:
 
                    chunks, stats = self._parse_lines(diff)
 
                except DiffLimitExceeded:
 
                    diff_container = lambda _diff: LimitedDiffContainer(
 
                                                self.diff_limit,
 
                                                self.cur_diff_size,
 
                                                _diff)
 
                    break
 
            else: # GIT binary patch (or empty diff)
 
                chunks = []
0 comments (0 inline, 0 general)