Changeset - 6b723a49a9a1
[Not reviewed]
default
0 3 0
Mads Kiilerich - 9 years ago 2016-08-12 03:13:59
madski@unity3d.com
diff: only highlight of difference between del and add line for one-liners

Comparing a single del line with the first of several add lines would often be
quite arbitrary and misleading.

Note: the non-gitdiff code paths in diffs.py are incomplete and unused and
unusable.
3 files changed with 35 insertions and 18 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/diffs.py
Show inline comments
 
@@ -283,15 +283,13 @@ class DiffProcessor(object):
 
            self.removes += 1
 
        return safe_unicode(l)
 

	
 
    def _highlight_line_difflib(self, line, next_):
 
    def _highlight_line_difflib(self, old, new):
 
        """
 
        Highlight inline changes in both lines.
 
        """
 

	
 
        if line['action'] == 'del':
 
            old, new = line, next_
 
        else:
 
            old, new = next_, line
 
        assert old['action'] == 'del'
 
        assert new['action'] == 'add'
 

	
 
        oldwords = self._token_re.split(old['line'])
 
        newwords = self._token_re.split(new['line'])
 
@@ -484,19 +482,34 @@ class DiffProcessor(object):
 
        if not inline_diff:
 
            return diff_container(_files)
 

	
 
        # highlight inline changes
 
        # highlight inline changes when one del is followed by one add
 
        for diff_data in _files:
 
            for chunk in diff_data['chunks']:
 
                lineiter = iter(chunk)
 
                try:
 
                    while 1:
 
                        line = lineiter.next()
 
                        if line['action'] not in ['unmod', 'context']:
 
                            nextline = lineiter.next()
 
                            if nextline['action'] in ['unmod', 'context'] or \
 
                               nextline['action'] == line['action']:
 
                                continue
 
                            self.differ(line, nextline)
 
                    peekline = lineiter.next()
 
                    while True:
 
                        # find a first del line
 
                        while peekline['action'] != 'del':
 
                            peekline = lineiter.next()
 
                        delline = peekline
 
                        peekline = lineiter.next()
 
                        # if not followed by add, eat all following del lines
 
                        if peekline['action'] != 'add':
 
                            while peekline['action'] == 'del':
 
                                peekline = lineiter.next()
 
                            continue
 
                        # found an add - make sure it is the only one
 
                        addline = peekline
 
                        try:
 
                            peekline = lineiter.next()
 
                        except StopIteration:
 
                            # add was last line - ok
 
                            self.differ(delline, addline)
 
                            raise
 
                        if peekline['action'] != 'add':
 
                            # there was only one add line - ok
 
                            self.differ(delline, addline)
 
                except StopIteration:
 
                    pass
 

	
kallithea/tests/fixtures/markuptest.diff
Show inline comments
 
diff --git a/f b/f
 
--- a/f	
 
+++ b/f	
 
@@ -51,5 +51,12 @@
 
@@ -51,6 +51,13 @@
 
 	begin();
 
 	
 
+	int foo;
 
@@ -15,3 +15,5 @@ diff --git a/f b/f
 
+	
 
+	#define MAX_STEPS (64)
 
 
 
-	#define MIN_STEPS (48)
 
+	#define MIN_STEPS (42)
kallithea/tests/models/test_diff_parsers.py
Show inline comments
 
@@ -298,7 +298,7 @@ class TestDiffLib(TestController):
 
        s = ''.join(l)
 
        print s
 
        assert s == r'''
 
context ... ... u'@@ -51,5 +51,12 @@\n'
 
context ... ... u'@@ -51,6 +51,13 @@\n'
 
unmod    51  51 u'<u>\t</u>begin();\n'
 
unmod    52  52 u'<u>\t</u>\n'
 
add      53     u'<u>\t</u>int foo;<u class="cr"></u>\n'
 
@@ -308,8 +308,10 @@ add      56     u'<u>\t</u>int space; <i
 
add      57     u'<u>\t</u>int tab;<u>\t</u>\n'
 
add      58     u'<u>\t</u>\n'
 
unmod    59  53 u' <i></i>'
 
del          54 u'<u>\t</u><del>#define MAX_STEPS (48)</del>\n'
 
add      60     u'<u>\t</u><ins><u class="cr"></u></ins>\n'
 
del          54 u'<u>\t</u>#define MAX_STEPS (48)\n'
 
add      60     u'<u>\t</u><u class="cr"></u>\n'
 
add      61     u'<u>\t</u>#define MAX_STEPS (64)<u class="cr"></u>\n'
 
unmod    62  55 u'\n'
 
del          56 u'<u>\t</u>#define MIN_STEPS (<del>48</del>)\n'
 
add      63     u'<u>\t</u>#define MIN_STEPS (<ins>42</ins>)\n'
 
'''
0 comments (0 inline, 0 general)