mercurial/hgweb/webcommands.py
changeset 7183 099b4f9be5ab
parent 7182 295af5bc1bcc
child 7280 810ca383da9c
--- a/mercurial/hgweb/webcommands.py	Mon Oct 20 12:41:09 2008 +0200
+++ b/mercurial/hgweb/webcommands.py	Mon Oct 20 14:13:37 2008 +0200
@@ -417,24 +417,40 @@
                 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