[PATCH 3 of 4] subrepo: add table-based dispatch for subrepo types

Augie Fackler durin42 at gmail.com
Thu Dec 31 17:54:44 CST 2009


# HG changeset patch
# User Augie Fackler <durin42 at gmail.com>
# Date 1262301003 21600
# Node ID 198667bde7d19ae5fb53ad96ad13a2a4ac529f65
# Parent  08c2b2f3b4b4aa0eb834b360cd54247542a9d997
subrepo: add table-based dispatch for subrepo types

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -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,
+    }
diff --git a/tests/test-subrepo b/tests/test-subrepo
--- a/tests/test-subrepo
+++ b/tests/test-subrepo
@@ -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
diff --git a/tests/test-subrepo.out b/tests/test-subrepo.out
--- a/tests/test-subrepo.out
+++ b/tests/test-subrepo.out
@@ -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


More information about the Mercurial-devel mailing list