Changeset - bf39a5c8d666
[Not reviewed]
default
0 2 0
Mads Kiilerich (mads) - 5 years ago 2021-02-22 13:08:06
mads@kiilerich.com
diffs: don't add a pointless empty first chunk
2 files changed with 15 insertions and 9 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/diffs.py
Show inline comments
 
@@ -381,13 +381,19 @@ class DiffProcessor(object):
 
                # 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'],
kallithea/tests/models/test_diff_parsers.py
Show inline comments
 
@@ -344,10 +344,10 @@ class TestDiffLib(base.TestController):
 
        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'''
0 comments (0 inline, 0 general)