--- 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.
--- 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,
--- 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 = '<div style="font-family:monospace" class="parity#parity#"><pre><span class="linenr"> #linenumber#</span> #line|escape#</pre></div>'
-annotateline = '<tr style="font-family:monospace" class="parity#parity#"><td class="linenr" style="text-align: right;"><a href="#url#annotate/#node|short#/#file|urlescape#{sessionvars%urlparameter}">#author|obfuscate#@#rev#</a></td><td><pre>#line|escape#</pre></td></tr>'
-difflineplus = '<span style="color:#008800;">#line|escape#</span>'
-difflineminus = '<span style="color:#cc0000;">#line|escape#</span>'
-difflineat = '<span style="color:#990099;">#line|escape#</span>'
-diffline = '<span>#line|escape#</span>'
+fileline = '<div style="font-family:monospace" class="parity#parity#"><pre><a class="linenr" href="##lineid#" id="#lineid#">#linenumber#</a> #line|escape#</pre></div>'
+annotateline = '<tr style="font-family:monospace" class="parity#parity#"><td class="linenr" style="text-align: right;"><a href="#url#annotate/#node|short#/#file|urlescape#{sessionvars%urlparameter}">#author|obfuscate#@#rev#</a></td><td><pre><a class="linenr" href="##lineid#" id="#lineid#">#linenumber#</a></pre></td><td><pre>#line|escape#</pre></td></tr>'
+difflineplus = '<span style="color:#008800;"><a class="linenr" href="##lineid#" id="#lineid#">#linenumber#</a> #line|escape#</span>'
+difflineminus = '<span style="color:#cc0000;"><a class="linenr" href="##lineid#" id="#lineid#">#linenumber#</a> #line|escape#</span>'
+difflineat = '<span style="color:#990099;"><a class="linenr" href="##lineid#" id="#lineid#">#linenumber#</a> #line|escape#</span>'
+diffline = '<span><a class="linenr" href="##lineid#" id="#lineid#">#linenumber#</a> #line|escape#</span>'
changelogparent = '<tr><th class="parent">parent #rev#:</th><td class="parent"><a href="#url#rev/#node|short#{sessionvars%urlparameter}">#node|short#</a></td></tr>'
changesetparent = '<tr><td>parent {rev}</td><td style="font-family:monospace"><a class="list" href="{url}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a></td></tr>'
filerevparent = '<tr><td>parent {rev}</td><td style="font-family:monospace"><a class="list" href="{url}file/{node|short}/{file|urlescape}{sessionvars%urlparameter}">{rename%filerename}{node|short}</a></td></tr>'
--- 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 = '<div class="parity#parity#"><span class="lineno">#linenumber#</span>#line|escape#</div>'
+fileline = '<div class="parity#parity#"><a class="lineno" href="##lineid#" id="#lineid#">#linenumber#</a>#line|escape#</div>'
filelogentry = filelogentry.tmpl
-annotateline = '<tr class="parity#parity#"><td class="annotate"><a href="#url#annotate/#node|short#/#file|urlescape#{sessionvars%urlparameter}">#author|obfuscate#@#rev#</a></td><td><pre>#line|escape#</pre></td></tr>'
-difflineplus = '<span class="plusline">#line|escape#</span>'
-difflineminus = '<span class="minusline">#line|escape#</span>'
-difflineat = '<span class="atline">#line|escape#</span>'
-diffline = '#line|escape#'
+annotateline = '<tr class="parity#parity#"><td class="annotate"><a href="#url#annotate/#node|short#/#file|urlescape#{sessionvars%urlparameter}">#author|obfuscate#@#rev#</a></td><td><a class="lineno" href="##lineid#" id="#lineid#">#linenumber#</a></td><td><pre>#line|escape#</pre></td></tr>'
+difflineplus = '<span class="plusline"><a class="lineno" href="##lineid#" id="#lineid#">#linenumber#</a>#line|escape#</span>'
+difflineminus = '<span class="minusline"><a class="lineno" href="##lineid#" id="#lineid#">#linenumber#</a>#line|escape#</span>'
+difflineat = '<span class="atline"><a class="lineno" href="##lineid#" id="#lineid#">#linenumber#</a>#line|escape#</span>'
+diffline = '<a class="lineno" href="##lineid#" id="#lineid#">#linenumber#</a>#line|escape#'
changelogparent = '<tr><th class="parent">parent #rev#:</th><td class="parent"><a href="#url#rev/#node|short#{sessionvars%urlparameter}">#node|short#</a></td></tr>'
changesetparent = '<tr><th class="parent">parent #rev#:</th><td class="parent"><a href="#url#rev/#node|short#{sessionvars%urlparameter}">#node|short#</a></td></tr>'
filerevparent = '<tr><td class="metatag">parent:</td><td><a href="{url}file/{node|short}/{file|urlescape}{sessionvars%urlparameter}">{rename%filerename}{node|short}</a></td></tr>'