[PATCH 1 of 2] hgweb: add hook for remapping repository path into virtual paths

Martin Geisler mg at lazybytes.net
Sun Apr 15 09:06:28 CDT 2012


# HG changeset patch
# User Martin Geisler <mg at lazybytes.net>
# Date 1334498753 -7200
# Node ID 7eaa67554bb5c19a6ca00afb2556243fc548baf7
# Parent  6883c2363f44ea7b0dcb83f3c507c71b0f1b4a34
hgweb: add hook for remapping repository path into virtual paths

Extensions such as largefiles can use this to remap files so they
appear in the same location as they do in the user's working copy.

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -303,6 +303,14 @@
 
 rev = changeset
 
+def decodepath(path):
+    """Hook for mapping a path in the repository to a path in the
+    working copy.
+
+    Extensions (e.g., largefiles) can override this to remap files in
+    the virtual file system presented by the manifest command below."""
+    return path
+
 def manifest(web, req, tmpl):
     ctx = webutil.changectx(web.repo, req)
     path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0])
@@ -318,13 +326,17 @@
     l = len(path)
     abspath = "/" + path
 
-    for f, n in mf.iteritems():
+    for full, n in mf.iteritems():
+        # the virtual path (working copy path) used for the full
+        # (repository) path
+        f = decodepath(full)
+
         if f[:l] != path:
             continue
         remain = f[l:]
         elements = remain.split('/')
         if len(elements) == 1:
-            files[remain] = f
+            files[remain] = full
         else:
             h = dirs # need to retain ref to dirs (root)
             for elem in elements[0:-1]:


More information about the Mercurial-devel mailing list