diff mercurial/subrepo.py @ 11775:a8614c5a5e9a

subrepos: support remapping of .hgsub source paths Given a .hgsub file containing lib/libfoo = http://server/libfoo the 'lib/libfoo' subrepo will be cloned from 'http://server/libfoo'. This changeset introduces a remapping mechanism whereby the source paths (the right-hand sides) in the .hgsub file can be remapped. This subpaths section [subpaths] http://server = /local will result in the 'lib/libfoo' subrepo being cloned from '/local/libfoo' instead of from 'http://server/libfoo'. The patterns (left-hand sides) are really regular expressions and the replacement strings (right-hand sides) can refer to matched groups using normal backreferences. This can be used for more complicated replacements such as [subpaths] http://server/(.*)-hg/ = http://hg.server/\1/ which replaces 'http://server/foo-hg/' with 'http://hg.server/foo/'. All patterns are applied in the order by which they are listed in the config files.
author Martin Geisler <mg@lazybytes.net>
date Thu, 15 Jul 2010 18:10:05 +0200
parents 324bad1dc230
children f3075ffa6b30
line wrap: on
line diff
--- a/mercurial/subrepo.py	Tue Aug 10 16:55:38 2010 +0200
+++ b/mercurial/subrepo.py	Thu Jul 15 18:10:05 2010 +0200
@@ -12,7 +12,7 @@
 
 nullstate = ('', '', 'empty')
 
-def state(ctx):
+def state(ctx, ui):
     """return a state dict, mapping subrepo paths configured in .hgsub
     to tuple: (source from .hgsub, revision from .hgsubstate, kind
     (key in types dict))
@@ -27,6 +27,9 @@
     if '.hgsub' in ctx:
         read('.hgsub')
 
+    for path, src in ui.configitems('subpaths'):
+        p.set('subpaths', path, src, ui.configsource('subpaths', path))
+
     rev = {}
     if '.hgsubstate' in ctx:
         try:
@@ -45,6 +48,14 @@
                 raise util.Abort(_('missing ] in subrepo source'))
             kind, src = src.split(']', 1)
             kind = kind[1:]
+
+        for pattern, repl in p.items('subpaths'):
+            try:
+                src = re.sub(pattern, repl, src, 1)
+            except re.error, e:
+                raise util.Abort(_("bad subrepository pattern in %s: %s")
+                                 % (p.source('subpaths', pattern), e))
+
         state[path] = (src.strip(), rev.get(path, ''), kind)
 
     return state