diff --git a/kallithea/lib/diffs.py b/kallithea/lib/diffs.py
--- a/kallithea/lib/diffs.py
+++ b/kallithea/lib/diffs.py
@@ -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
diff --git a/kallithea/tests/fixtures/markuptest.diff b/kallithea/tests/fixtures/markuptest.diff
--- a/kallithea/tests/fixtures/markuptest.diff
+++ b/kallithea/tests/fixtures/markuptest.diff
@@ -1,7 +1,7 @@
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)
diff --git a/kallithea/tests/models/test_diff_parsers.py b/kallithea/tests/models/test_diff_parsers.py
--- a/kallithea/tests/models/test_diff_parsers.py
+++ b/kallithea/tests/models/test_diff_parsers.py
@@ -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'\tbegin();\n'
unmod 52 52 u'\t\n'
add 53 u'\tint foo;\n'
@@ -308,8 +308,10 @@ add 56 u'\tint space; \tint tab;\t\n'
add 58 u'\t\n'
unmod 59 53 u' '
-del 54 u'\t#define MAX_STEPS (48)\n'
-add 60 u'\t\n'
+del 54 u'\t#define MAX_STEPS (48)\n'
+add 60 u'\t\n'
add 61 u'\t#define MAX_STEPS (64)\n'
unmod 62 55 u'\n'
+del 56 u'\t#define MIN_STEPS (48)\n'
+add 63 u'\t#define MIN_STEPS (42)\n'
'''