diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py +++ b/mercurial/hgweb/webcommands.py @@ -417,24 +417,40 @@ def summary(web, req, tmpl): archives=web.archivelist("tip")) def filediff(web, req, tmpl): - fctx = webutil.filectx(web.repo, req) - n = fctx.node() - path = fctx.path() - parents = fctx.parents() - p1 = parents and parents[0].node() or nullid + fctx, ctx = None, None + try: + fctx = webutil.filectx(web.repo, req) + except LookupError, inst: + ctx = webutil.changectx(web.repo, req) + path = webutil.cleanpath(web.repo, req.form['file'][0]) + if path not in ctx.files(): + raise + + if fctx is not None: + n = fctx.node() + path = fctx.path() + parents = fctx.parents() + p1 = parents and parents[0].node() or nullid + else: + n = ctx.node() + # path already defined in except clause + parents = ctx.parents() + p1 = parents and parents[0].node() or nullid diffs = web.diff(tmpl, p1, n, [path]) + rename = fctx and webutil.renamelink(fctx) or [] + ctx = fctx and fctx or ctx return tmpl("filediff", file=path, node=hex(n), - rev=fctx.rev(), - date=fctx.date(), - desc=fctx.description(), - author=fctx.user(), - rename=webutil.renamelink(fctx), - branch=webutil.nodebranchnodefault(fctx), + rev=ctx.rev(), + date=ctx.date(), + desc=ctx.description(), + author=ctx.user(), + rename=rename, + branch=webutil.nodebranchnodefault(ctx), parent=webutil.siblings(parents), - child=webutil.siblings(fctx.children()), + child=webutil.siblings(ctx.children()), diff=diffs) diff = filediff diff --git a/tests/test-hgweb-removed b/tests/test-hgweb-removed new file mode 100755 --- /dev/null +++ b/tests/test-hgweb-removed @@ -0,0 +1,17 @@ +echo % setting up repo +hg init test +cd test +echo a > a +hg ci -Ama +hg rm a +hg ci -mdel + +echo % set up hgweb +hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log +cat hg.pid >> $DAEMON_PIDS + +echo % revision +"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/rev/tip' + +echo % diff removed file +"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/diff/tip/a' diff --git a/tests/test-hgweb-removed.out b/tests/test-hgweb-removed.out new file mode 100644 --- /dev/null +++ b/tests/test-hgweb-removed.out @@ -0,0 +1,130 @@ +% setting up repo +adding a +% set up hgweb +% revision +200 Script output follows + + + + + + + + +test: changeset c78f6c5cbea9 + + + +
+changelog +shortlog +graph +tags +files +raw + +
+ +

changeset: del

+ + + + + + + + + + + + + + + + + + + + + + + + + +
changeset 1:c78f6c5cbea9
parent 0:cb9a9f314b8b
tag:tip
author:test
date:Thu Jan 01 00:00:00 1970 +0000 (38 years ago)
files:a
description:del
+ +
+
       1--- a/a	Thu Jan 01 00:00:00 1970 +0000
+       2+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
+       3@@ -1,1 +0,0 @@
+       4-a
+
+
+ + + + + + + + + +% diff removed file +200 Script output follows + + + + + + + + +test: a diff + + + +
+changelog +shortlog +graph +tags +changeset +file +revisions +annotate +raw +
+ +

a

+ + + + + + + + +
revision 1:c78f6c5cbea9
parent 0:cb9a9f314b8b
+ +
+
       1--- a/a	Thu Jan 01 00:00:00 1970 +0000
+       2+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
+       3@@ -1,1 +0,0 @@
+       4-a
+
+
+ + + + + + + + +