changeset 8865:bf39a5c8d666

diffs: don't add a pointless empty first chunk
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 22 Feb 2021 13:08:06 +0100
parents 3ab8744d20c9
children e6034764387e
files kallithea/lib/diffs.py kallithea/tests/models/test_diff_parsers.py
diffstat 2 files changed, 15 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/diffs.py	Mon Feb 22 10:56:04 2021 +0100
+++ b/kallithea/lib/diffs.py	Mon Feb 22 13:08:06 2021 +0100
@@ -381,13 +381,19 @@
                 # not with the current UI
                 chunks = []
 
-            chunks.insert(0, [{
-                'old_lineno': '',
-                'new_lineno': '',
-                'action':     'context',
-                'line':       msg,
-                } for _op, msg in stats['ops'].items()
-                  if _op not in [MOD_FILENODE]])
+            # show helpful additional texts for mode change and renaming, but not for plain 'modified file'
+            msgs = [
+                {
+                    'old_lineno': '',
+                    'new_lineno': '',
+                    'action': 'context',
+                    'line': msg,
+                }
+                for op_, msg in stats['ops'].items()
+                if op_ != MOD_FILENODE
+            ]
+            if msgs:
+                chunks.insert(0, msgs)
 
             _files.append({
                 'old_filename':     head['a_path'],
--- a/kallithea/tests/models/test_diff_parsers.py	Mon Feb 22 10:56:04 2021 +0100
+++ b/kallithea/tests/models/test_diff_parsers.py	Mon Feb 22 13:08:06 2021 +0100
@@ -344,10 +344,10 @@
         raw_diff = fixture.load_resource('markuptest.diff', strip=False)
         diff_processor = DiffProcessor(raw_diff)
         chunks = diff_processor.parsed[0]['chunks']
-        assert not chunks[0]
+        assert len(chunks) == 1, chunks
         #from pprint import pprint; pprint(chunks[1])
         l = ['\n']
-        for d in chunks[1]:
+        for d in chunks[0]:
             l.append('%(action)-7s %(new_lineno)3s %(old_lineno)3s %(line)r\n' % d)
         s = ''.join(l)
         assert s == r'''