subrepo: add table-based dispatch for subrepo types
authorAugie Fackler <durin42@gmail.com>
Thu, 31 Dec 2009 17:10:03 -0600
changeset 10177 5ca0d220ae21
parent 10176 24ce8f0c0a39
child 10178 cd477be6f2fc
subrepo: add table-based dispatch for subrepo types
mercurial/subrepo.py
tests/test-subrepo
tests/test-subrepo.out
--- a/mercurial/subrepo.py	Thu Dec 31 17:19:30 2009 -0600
+++ b/mercurial/subrepo.py	Thu Dec 31 17:10:03 2009 -0600
@@ -10,7 +10,7 @@
 import config, util, node, error
 hg = None
 
-nullstate = ('', '')
+nullstate = ('', '', 'empty')
 
 def state(ctx):
     p = config.config()
@@ -35,7 +35,13 @@
 
     state = {}
     for path, src in p[''].items():
-        state[path] = (src, rev.get(path, ''))
+        kind = 'hg'
+        if src.startswith('['):
+            if ']' not in src:
+                raise util.Abort(_('missing ] in subrepo source'))
+            kind, src = src.split(']', 1)
+            kind = kind[1:]
+        state[path] = (src, rev.get(path, ''), kind)
 
     return state
 
@@ -57,7 +63,7 @@
 
     def debug(s, msg, r=""):
         if r:
-            r = "%s:%s" % r
+            r = "%s:%s:%s" % r
         repo.ui.debug("  subrepo %s: %s %s\n" % (s, msg, r))
 
     for s, l in s1.items():
@@ -146,9 +152,9 @@
 
     util.path_auditor(ctx._repo.root)(path)
     state = ctx.substate.get(path, nullstate)
-    if state[0].startswith('['): # future expansion
-        raise error.Abort('unknown subrepo source %s' % state[0])
-    return hgsubrepo(ctx, path, state)
+    if state[2] not in types:
+        raise util.Abort(_('unknown subrepo type %s') % t)
+    return types[state[2]](ctx, path, state[:2])
 
 # subrepo classes need to implement the following methods:
 # __init__(self, ctx, path, state)
@@ -205,7 +211,7 @@
         hg.clean(self._repo, node.nullid, False)
 
     def _get(self, state):
-        source, revision = state
+        source, revision, kind = state
         try:
             self._repo.lookup(revision)
         except error.RepoError:
@@ -217,7 +223,7 @@
 
     def get(self, state):
         self._get(state)
-        source, revision = state
+        source, revision, kind = state
         self._repo.ui.debug("getting subrepo %s\n" % self._path)
         hg.clean(self._repo, revision, False)
 
@@ -243,3 +249,7 @@
         dsturl = _abssource(self._repo, True)
         other = hg.repository(self._repo.ui, dsturl)
         self._repo.push(other, force)
+
+types = {
+    'hg': hgsubrepo,
+    }
--- a/tests/test-subrepo	Thu Dec 31 17:19:30 2009 -0600
+++ b/tests/test-subrepo	Thu Dec 31 17:10:03 2009 -0600
@@ -104,3 +104,9 @@
 hg pull | sed 's/ .*sub/ ...sub/g'
 hg up # should pull t
 cat t/t
+
+echo % bogus subrepo path aborts
+echo 'bogus=[boguspath' >> .hgsub
+hg ci -m 'bogus subrepo path'
+
+exit 0
--- a/tests/test-subrepo.out	Thu Dec 31 17:19:30 2009 -0600
+++ b/tests/test-subrepo.out	Thu Dec 31 17:10:03 2009 -0600
@@ -57,7 +57,7 @@
  ancestor 1f14a2e2d3ec local f0d2028bf86d+ remote 1831e14459c4
  .hgsubstate: versions differ -> m
 subrepo merge f0d2028bf86d+ 1831e14459c4 1f14a2e2d3ec
-  subrepo t: other changed, get t:6747d179aa9a688023c4b0cad32e4c92bb7f34ad
+  subrepo t: other changed, get t:6747d179aa9a688023c4b0cad32e4c92bb7f34ad:hg
 getting subrepo t
 resolving manifests
  overwrite True partial False
@@ -79,7 +79,7 @@
  ancestor 1831e14459c4 local e45c8b14af55+ remote f94576341bcf
  .hgsubstate: versions differ -> m
 subrepo merge e45c8b14af55+ f94576341bcf 1831e14459c4
-  subrepo t: both sides changed, merge with t:7af322bc1198a32402fe903e0b7ebcfc5c9bf8f4
+  subrepo t: both sides changed, merge with t:7af322bc1198a32402fe903e0b7ebcfc5c9bf8f4:hg
 merging subrepo t
   searching for copies back to rev 2
 resolving manifests
@@ -201,3 +201,5 @@
 added 1 changesets with 1 changes to 1 files
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 blah
+% bogus subrepo path aborts
+abort: missing ] in subrepo source