Mercurial > kallithea
changeset 8866:e6034764387e
diffs: let DiffProcessor inject context_lineno in chunk changes
Make it possible to use these numbers reliably, also outside as_html.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Mon, 22 Feb 2021 11:44:23 +0100 |
parents | bf39a5c8d666 |
children | 3119d680a8d5 |
files | kallithea/lib/diffs.py |
diffstat | 1 files changed, 10 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/diffs.py Mon Feb 22 13:08:06 2021 +0100 +++ b/kallithea/lib/diffs.py Mon Feb 22 11:44:23 2021 +0100 @@ -77,7 +77,6 @@ }) for file_info in parsed_lines: - count_no_lineno = 0 # counter to allow comments on lines without new/old line numbers for chunk in file_info['chunks']: _html_empty = False for change in chunk: @@ -128,11 +127,10 @@ ########################################################### # NO LINE NUMBER ########################################################### - anchor = "%(filename)s_%(count_no_lineno)s" % { + anchor = "%(filename)s_%(context_lineno)s" % { 'filename': _safe_id(file_info['filename']), - 'count_no_lineno': count_no_lineno, + 'context_lineno': change['context_lineno'], } - count_no_lineno += 1 _html.append('''\t<td id="%(anchor)s" class="%(olc)s" colspan="2">''' % { 'anchor': anchor, 'olc': no_lineno_class, @@ -395,6 +393,14 @@ if msgs: chunks.insert(0, msgs) + # enumerate 'context' lines that don't have new/old line numbers so they can be commented on + context_lineno = 0 + for chunk in chunks: + for change in chunk: + if not change['old_lineno'] and not change['new_lineno']: + change['context_lineno'] = context_lineno + context_lineno += 1 + _files.append({ 'old_filename': head['a_path'], 'filename': head['b_path'],