Changeset - 32757d5e9d0b
[Not reviewed]
default
0 2 0
Mads Kiilerich (mads) - 6 years ago 2020-06-12 00:36:04
mads@kiilerich.com
Grafted from: 5f05b4d7dbd5
diff: drop internal inconsistent use of '...' as context line numbers

as_html() did in some cases not check for '...' and would thus emit unnecessary
html.
2 files changed with 8 insertions and 11 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/diffs.py
Show inline comments
 
@@ -104,18 +104,15 @@ def as_html(table_class='code-difftable'
 
                    'oldline_no': change['old_lineno']
 
                }
 
                anchor_new = "%(filename)s_n%(newline_no)s" % {
 
                    'filename': _safe_id(file_info['filename']),
 
                    'newline_no': change['new_lineno']
 
                }
 
                cond_old = (change['old_lineno'] != '...' and
 
                            change['old_lineno'])
 
                cond_new = (change['new_lineno'] != '...' and
 
                            change['new_lineno'])
 
                no_lineno = (change['old_lineno'] == '...' and
 
                             change['new_lineno'] == '...')
 
                cond_old = change['old_lineno']
 
                cond_new = change['new_lineno']
 
                no_lineno = not change['old_lineno'] and not change['new_lineno']
 
                if cond_old:
 
                    anchor_old_id = 'id="%s"' % anchor_old
 
                if cond_new:
 
                    anchor_new_id = 'id="%s"' % anchor_new
 
                ###########################################################
 
                # OLD LINE NUMBER
 
@@ -584,14 +581,14 @@ def _parse_lines(diff_lines):
 
            new_end += new_line
 

	
 
            if context:
 
                # skip context only if it's first line
 
                if int(gr[0]) > 1:
 
                    lines.append({
 
                        'old_lineno': '...',
 
                        'new_lineno': '...',
 
                        'old_lineno': '',
 
                        'new_lineno': '',
 
                        'action':     'context',
 
                        'line':       line,
 
                    })
 

	
 
            line = next(diff_lines)
 

	
 
@@ -629,14 +626,14 @@ def _parse_lines(diff_lines):
 
                line = next(diff_lines)
 

	
 
                if _newline_marker.match(line):
 
                    # we need to append to lines, since this is not
 
                    # counted in the line specs of diff
 
                    lines.append({
 
                        'old_lineno':   '...',
 
                        'new_lineno':   '...',
 
                        'old_lineno':   '',
 
                        'new_lineno':   '',
 
                        'action':       'context',
 
                        'line':         line,
 
                    })
 
                    line = next(diff_lines)
 
            if old_line > old_end:
 
                raise Exception('error parsing diff - more than %s "-" lines at -%s+%s' % (old_end, old_line, new_line))
kallithea/tests/models/test_diff_parsers.py
Show inline comments
 
@@ -292,13 +292,13 @@ class TestDiffLib(base.TestController):
 
        #from pprint import pprint; pprint(chunks[1])
 
        l = ['\n']
 
        for d in chunks[1]:
 
            l.append('%(action)-7s %(new_lineno)3s %(old_lineno)3s %(line)r\n' % d)
 
        s = ''.join(l)
 
        assert s == r'''
 
context ... ... '@@ -51,6 +51,13 @@\n'
 
context         '@@ -51,6 +51,13 @@\n'
 
unmod    51  51 '<u>\t</u>begin();\n'
 
unmod    52  52 '<u>\t</u>\n'
 
add      53     '<u>\t</u>int foo;<u class="cr"></u>\n'
 
add      54     '<u>\t</u>int bar; <u class="cr"></u>\n'
 
add      55     '<u>\t</u>int baz;<u>\t</u><u class="cr"></u>\n'
 
add      56     '<u>\t</u>int space; <i></i>'
0 comments (0 inline, 0 general)