changeset 4696:fbb992c719aa

diff: don't split lines on bare CR as python splitlines do The line count from the @@ lines and the actual count would get out of sync and an incomplete diff would be shown. This is slower than native splitlines ... but that is what it takes to handle it correctly. (Except that we perhaps could use .split('\n') and patch the result ...)
author Mads Kiilerich <madski@unity3d.com>
date Mon, 15 Dec 2014 13:47:36 +0100
parents 97ed7d05d3d2
children 5225ed43bbb3
files kallithea/lib/diffs.py kallithea/tests/fixtures/hg_diff_rename_space_cr.diff kallithea/tests/models/test_diff_parsers.py
diffstat 3 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/diffs.py	Mon Dec 15 13:47:36 2014 +0100
+++ b/kallithea/lib/diffs.py	Mon Dec 15 13:47:36 2014 +0100
@@ -363,7 +363,7 @@
         rest = diff_chunk[match.end():]
         if rest and not rest.startswith('@') and not rest.startswith('literal '):
             raise Exception('cannot parse diff header: %r followed by %r' % (diff_chunk[:match.end()], rest[:1000]))
-        difflines = imap(self._escaper, rest.splitlines(True))
+        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):
--- a/kallithea/tests/fixtures/hg_diff_rename_space_cr.diff	Mon Dec 15 13:47:36 2014 +0100
+++ b/kallithea/tests/fixtures/hg_diff_rename_space_cr.diff	Mon Dec 15 13:47:36 2014 +0100
@@ -3,7 +3,7 @@
 rename to oh yes
 --- a/oh no	
 +++ b/oh yes	
-@@ -1,5 +1,6 @@
+@@ -1,4 +1,4 @@
  1
 -2
+ 2
 -3
 
--- a/kallithea/tests/models/test_diff_parsers.py	Mon Dec 15 13:47:36 2014 +0100
+++ b/kallithea/tests/models/test_diff_parsers.py	Mon Dec 15 13:47:36 2014 +0100
@@ -249,7 +249,7 @@
     ],
     'hg_diff_rename_space_cr.diff': [
         ('oh yes', 'R',
-         {'added': 4,
+         {'added': 3,
           'deleted': 2,
           'binary': False,
           'ops': {RENAMED_FILENODE: 'file renamed from oh no to oh yes'}}),