changeset 24712:bbf1ae6b6a44

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.
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 10 Apr 2015 22:34:12 -0400
parents ab6e3729747e
children 2f43f8cf8219
files mercurial/hgweb/webcommands.py mercurial/hgweb/webutil.py
diffstat 2 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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()}
--- 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 '')