[PATCH 2 of 2] hgweb: emit the correct nav links for a file log with renames (issue1576)
Kevin Gessner
kevin at fogcreek.com
Tue Apr 5 09:23:27 CDT 2011
# HG changeset patch
# User Kevin Gessner <kevin at fogcreek.com>
# Date 1302013166 14400
# Node ID 19a11fd6c8181ce345778f7730b241a26364a5d6
# Parent 2c8959c80e96668c00f836eee93daf48d0fde463
hgweb: emit the correct nav links for a file log with renames (issue1576)
Links to older revisions must include the path that the file had in that
revision.
diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -658,7 +658,7 @@
iterfctx = fctx.filectx(i)
l.insert(0, {"filerev": i,
- "file": f,
+ "file": iterfctx.path(),
"node": hex(iterfctx.node()),
"author": iterfctx.user(),
"date": iterfctx.date(),
@@ -690,13 +690,16 @@
yield e
def nodefunc(fileid):
+ if fileid == '0':
+ return allfctx[0].filectx(0)
+ if fileid == 'tip':
+ fctx = allfctx[len(allfctx)-1]
+ return fctx.filectx(fctx.filelog().tip())
for fctx in allfctx:
- try:
- found = fctx.filectx(fileid=fileid)
- found.node()
- return found
- except IndexError:
- pass
+ c = fctx.filerev()
+ if fileid < c:
+ return fctx.filectx(fileid)
+ fileid -= c
return None
nav = webutil.revnavgen(end - 1, revcount, count, nodefunc)
return tmpl("filelog", file=f, node=hex(fctx.node()), nav=nav,
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -21,6 +21,12 @@
return up + "/"
def revnavgen(pos, pagelen, limit, nodefunc):
+ def path(ctx):
+ fn = getattr(ctx, 'path', None)
+ if fn:
+ return fn()
+ return None
+
def seq(factor, limit=None):
if limit:
yield limit
@@ -43,20 +49,24 @@
break
last = f
if pos + f < limit:
- navafter.append(("+%d" % f, hex(nodefunc(pos + f).node())))
+ ctx = nodefunc(pos + f)
+ navafter.append(("+%d" % f, hex(ctx.node()), path(ctx)))
if pos - f >= 0:
- navbefore.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node())))
+ ctx = nodefunc(pos - f)
+ navbefore.insert(0, ("-%d" % f, hex(ctx.node()), path(ctx)))
- navafter.append(("tip", "tip"))
+ ctx = nodefunc("tip")
+ navafter.append(("tip", "tip", path(ctx)))
try:
- navbefore.insert(0, ("(0)", hex(nodefunc('0').node())))
+ ctx = nodefunc("0")
+ navbefore.insert(0, ("(0)", hex(ctx.node()), path(ctx)))
except error.RepoError:
pass
def gen(l):
def f(**map):
- for label, node in l:
- yield {"label": label, "node": node}
+ for label, node, file in l:
+ yield {"label": label, "node": node, "file": file}
return f
return (dict(before=gen(navbefore), after=gen(navafter)),)
More information about the Mercurial-devel
mailing list