Thomas R. avatar Thomas R. committed 046d76a

Map paths to somewhere else. Useful for subrepo paths...

Comments (0)

Files changed (1)

+# Copyright 2009, Alexander Solovyov <>
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+# Parts are Copyright 2005, 2006 Matt Mackall <>
+# Parts are Copyright 2010 Thomas Rachel
+r"""scheme and path mapping
+This extension allows you to map a path which might be fixed in a subrepo
+configuration to a (maybe completely) different path.
+  [mapschemes]
+  //file/share/Software proprietary/LabVIEW/library = r033s://LVlibrary
+  //file/share/(.*) = hgr03://\1
+maps a path starting with //file/share/ so that it points to somewhere else.
+import re
+from mercurial import hg, templater
+from mercurial.sshrepo import sshrepository as sshrepo
+from mercurial import error, util
+from mercurial.i18n import _
+pathmap = []
+def do_map(path):
+    for regex, sub in pathmap:
+        if regex.match(path):
+            path = regex.sub(path, sub)
+    return path
+# subclass the url class in order to do the mapping
+class url(util.url):
+    def __init__(self, path, *a, **k):
+        mappedpath = do_map(path)
+        # debug mapped path to mappedpath
+        if mappedpath != path:
+            ui.debug("mapped %r to %r\n" % (path, mappedpath))
+        else:
+            ui.debug("no mapping of %r occurs\n" % (path))
+        super(url, self).__init__(mappedpath, *a, **k)
+def extsetup(myui):
+    import re
+    global ui
+    ui = myui
+    conf = dict(ui.configitems('pathmap'))
+    ui.note("mapping is enabled")
+    for key in conf.keys():
+        # redirect key to conf[key] by replacing regex-wise.
+        # With schemes or better directly on url basis?
+        ui.debug("mapping %r to %r\n" % (key, conf[key]))
+        pathmap.append((re.compile(key), conf[key]))
+    util.url = url
+#    t = templater.engine(lambda x: x)
+#    for scheme, cmdlines in schemes.items():
+#        hg.schemes[scheme] = ProgramCaller(cmdlines, scheme, t)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.