# HG changeset patch # User Thomas Arendsen Hein # Date 1203101094 -3600 # Node ID f7f25f58693ab8ddf4009dc7c6cfc76ba4f513b5 # Parent c74f1d9092f873a889b003f7edfc93931f55f9f1# Parent 800e2756c9abbc2b48ea5b3ec90e466eabd801a5 merged Edward Lee's line anchors patch diff -r c74f1d9092f8 -r f7f25f58693a mercurial/hgweb/common.py --- a/mercurial/hgweb/common.py Fri Feb 15 18:37:00 2008 +0100 +++ b/mercurial/hgweb/common.py Fri Feb 15 19:44:54 2008 +0100 @@ -101,6 +101,12 @@ parity = 1 - parity count = 0 +def countgen(start=0, step=1): + """count forever -- useful for line numbers""" + while True: + yield start + start += step + def get_contact(config): """Return repo contact information or empty string. diff -r c74f1d9092f8 -r f7f25f58693a mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py Fri Feb 15 18:37:00 2008 +0100 +++ b/mercurial/hgweb/hgweb_mod.py Fri Feb 15 19:44:54 2008 +0100 @@ -10,7 +10,8 @@ from mercurial.node import * from mercurial import mdiff, ui, hg, util, archival, patch, hook from mercurial import revlog, templater, templatefilters -from common import ErrorResponse, get_mtime, style_map, paritygen, get_contact +from common import get_mtime, style_map, paritygen, countgen, get_contact +from common import ErrorResponse from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR from request import wsgirequest import webcommands, protocol @@ -372,16 +373,26 @@ file=f, filenode=hex(fn or nullid)) + blockcount = countgen() def prettyprintlines(diff): - for l in diff.splitlines(1): + blockno = blockcount.next() + for lineno, l in enumerate(diff.splitlines(1)): + if blockno == 0: + lineno = lineno + 1 + else: + lineno = "%d.%d" % (blockno, lineno + 1) if l.startswith('+'): - yield tmpl("difflineplus", line=l) + ltype = "difflineplus" elif l.startswith('-'): - yield tmpl("difflineminus", line=l) + ltype = "difflineminus" elif l.startswith('@'): - yield tmpl("difflineat", line=l) + ltype = "difflineat" else: - yield tmpl("diffline", line=l) + ltype = "diffline" + yield tmpl(ltype, + line=l, + lineid="l%s" % lineno, + linenumber="% 8s" % lineno) r = self.repo c1 = r.changectx(node1) @@ -597,9 +608,10 @@ text = '(binary:%s)' % mt def lines(): - for l, t in enumerate(text.splitlines(1)): + for lineno, t in enumerate(text.splitlines(1)): yield {"line": t, - "linenumber": "% 6d" % (l + 1), + "lineid": "l%d" % (lineno + 1), + "linenumber": "% 6d" % (lineno + 1), "parity": parity.next()} return tmpl("filerevision", @@ -624,7 +636,7 @@ def annotate(**map): last = None - for f, l in fctx.annotate(follow=True): + for lineno, (f, l) in enumerate(fctx.annotate(follow=True)): fnode = f.filenode() name = self.repo.ui.shortuser(f.user()) @@ -636,7 +648,9 @@ "rev": f.rev(), "author": name, "file": f.path(), - "line": l} + "line": l, + "lineid": "l%d" % (lineno + 1), + "linenumber": "% 6d" % (lineno + 1)} return tmpl("fileannotate", file=f, diff -r c74f1d9092f8 -r f7f25f58693a templates/gitweb/map --- a/templates/gitweb/map Fri Feb 15 18:37:00 2008 +0100 +++ b/templates/gitweb/map Fri Feb 15 19:44:54 2008 +0100 @@ -23,12 +23,12 @@ fileannotate = fileannotate.tmpl filediff = filediff.tmpl filelog = filelog.tmpl -fileline = '
   #linenumber# #line|escape#
' -annotateline = '#author|obfuscate#@#rev#
#line|escape#
' -difflineplus = '#line|escape#' -difflineminus = '#line|escape#' -difflineat = '#line|escape#' -diffline = '#line|escape#' +fileline = '
#linenumber# #line|escape#
' +annotateline = '#author|obfuscate#@#rev#
#linenumber#
#line|escape#
' +difflineplus = '#linenumber# #line|escape#' +difflineminus = '#linenumber# #line|escape#' +difflineat = '#linenumber# #line|escape#' +diffline = '#linenumber# #line|escape#' changelogparent = 'parent #rev#:#node|short#' changesetparent = 'parent {rev}{node|short}' filerevparent = 'parent {rev}{rename%filerename}{node|short}' diff -r c74f1d9092f8 -r f7f25f58693a templates/map --- a/templates/map Fri Feb 15 18:37:00 2008 +0100 +++ b/templates/map Fri Feb 15 19:44:54 2008 +0100 @@ -22,13 +22,13 @@ fileannotate = fileannotate.tmpl filediff = filediff.tmpl filelog = filelog.tmpl -fileline = '
#linenumber##line|escape#
' +fileline = '
#linenumber##line|escape#
' filelogentry = filelogentry.tmpl -annotateline = '#author|obfuscate#@#rev#
#line|escape#
' -difflineplus = '#line|escape#' -difflineminus = '#line|escape#' -difflineat = '#line|escape#' -diffline = '#line|escape#' +annotateline = '#author|obfuscate#@#rev##linenumber#
#line|escape#
' +difflineplus = '#linenumber##line|escape#' +difflineminus = '#linenumber##line|escape#' +difflineat = '#linenumber##line|escape#' +diffline = '#linenumber##line|escape#' changelogparent = 'parent #rev#:#node|short#' changesetparent = 'parent #rev#:#node|short#' filerevparent = 'parent:{rename%filerename}{node|short}'