# HG changeset patch # User Gregory Szorc # Date 1428719652 14400 # Node ID bbf1ae6b6a4405c73b79867f005e00c5018f5ff6 # Parent ab6e3729747eee3f6f1a735c6f60ce88d63557dc hgweb: expose raw line numbers to templates Surpringly, the templates didn't receive an unmodified version of the line numbers. Expose it to make implementing the JSON templates easier. In theory, we could post-process an existing template variable. But extra string manipulation seems quite wasteful, especially on items that could occur hundreds or even thousands of times in output. diff -r ab6e3729747e -r bbf1ae6b6a44 mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py Sat Apr 11 11:54:09 2015 -0400 +++ b/mercurial/hgweb/webcommands.py Fri Apr 10 22:34:12 2015 -0400 @@ -927,6 +927,7 @@ "file": f.path(), "targetline": targetline, "line": l, + "lineno": lineno + 1, "lineid": "l%d" % (lineno + 1), "linenumber": "% 6d" % (lineno + 1), "revdate": f.date()} diff -r ab6e3729747e -r bbf1ae6b6a44 mercurial/hgweb/webutil.py --- a/mercurial/hgweb/webutil.py Sat Apr 11 11:54:09 2015 -0400 +++ b/mercurial/hgweb/webutil.py Fri Apr 10 22:34:12 2015 -0400 @@ -352,7 +352,7 @@ blockcount = countgen() def prettyprintlines(diff, blockno): for lineno, l in enumerate(diff.splitlines(True)): - lineno = "%d.%d" % (blockno, lineno + 1) + difflineno = "%d.%d" % (blockno, lineno + 1) if l.startswith('+'): ltype = "difflineplus" elif l.startswith('-'): @@ -363,8 +363,9 @@ ltype = "diffline" yield tmpl(ltype, line=l, - lineid="l%s" % lineno, - linenumber="% 8s" % lineno) + lineno=lineno + 1, + lineid="l%s" % difflineno, + linenumber="% 8s" % difflineno) if files: m = match.exact(repo.root, repo.getcwd(), files) @@ -405,8 +406,10 @@ return tmpl('comparisonline', type=type, lineid=lineid, + leftlineno=leftlineno, leftlinenumber="% 6s" % (leftlineno or ''), leftline=leftline or '', + rightlineno=rightlineno, rightlinenumber="% 6s" % (rightlineno or ''), rightline=rightline or '')