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 11 insertions and 5 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/diffs.py
Show inline comments
 
@@ -378,19 +378,25 @@ class DiffProcessor(object):
 

	
 
            if op == 'removed' and chunks:
 
                # a way of seeing deleted content could perhaps be nice - but
 
                # not with the current UI
 
                chunks = []
 

	
 
            chunks.insert(0, [{
 
            # 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 not in [MOD_FILENODE]])
 
                }
 
                for op_, msg in stats['ops'].items()
 
                if op_ != MOD_FILENODE
 
            ]
 
            if msgs:
 
                chunks.insert(0, msgs)
 

	
 
            _files.append({
 
                'old_filename':     head['a_path'],
 
                'filename':         head['b_path'],
 
                'old_revision':     head['a_blob_id'],
 
                'new_revision':     head['b_blob_id'],
kallithea/tests/models/test_diff_parsers.py
Show inline comments
 
@@ -341,16 +341,16 @@ class TestDiffLib(base.TestController):
 
        assert expected_data == data
 

	
 
    def test_diff_markup(self):
 
        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'''
 
context         '@@ -51,8 +51,15 @@'
 
unmod    51  51 '<u>\t</u>begin();'
 
unmod    52  52 '<u>\t</u><i></i>'
0 comments (0 inline, 0 general)