[PATCH] hgweb: accept /path/to/file as a shortcut to /file/somehead/path/to/file

Alexander Solovyov alexander at solovyov.net
Sat Apr 30 05:49:03 CDT 2011


# HG changeset patch
# User Alexander Solovyov <alexander at solovyov.net>
# Date 1304160491 -7200
# Node ID 14352d74764bdae41066670c0347822eb9ace88c
# Parent  3c616f512a5b55dfc269b7da5818df66b286c680
hgweb: accept /path/to/file as a shortcut to /file/somehead/path/to/file

If you open http://host/filename (which is not a valid command from
hgweb.webcommands), now hgweb will go through heads and seek for a 'filename' in
them.

diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -150,7 +150,11 @@ class hgweb(object):
             if hasattr(webcommands, cmd):
                 req.form['cmd'] = [cmd]
             else:
-                cmd = ''
+                cmd, args = self.havefile(cmd, args)
+                if cmd:
+                    req.form['cmd'] = [cmd]
+                    req.form['node'] = args[0]
+                    req.form['file'] = args[1]
 
             if cmd == 'static':
                 req.form['file'] = ['/'.join(args)]
@@ -300,3 +304,13 @@ class hgweb(object):
     def check_perm(self, req, op):
         for hook in permhooks:
             hook(self, req, op)
+
+    def havefile(self, cmd, args):
+        """Go through heads and check if we've got a path to file
+        """
+        path = os.path.join(cmd, *args)
+        for head in self.repo.heads():
+            ctx = self.repo[head]
+            if path in ctx:
+                return 'file', [str(ctx), path]
+        return '', args


More information about the Mercurial-devel mailing list