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

durin42 at gmail.com durin42 at gmail.com
Thu Dec 31 14:36:21 CST 2009


# HG changeset patch
# User Augie Fackler <durin42 at gmail.com>
# Date 1262291380 21600
# Node ID 4a6db2e12639bf1374a009a9ffaee015befc056c
# Parent  68d80c9814d720f2b7d8b2f39008ae6547a5b128
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,11 @@
 
     state = {}
     for path, src in p[''].items():
-        state[path] = (src, rev.get(path, ''))
+        kind = 'hg'
+        if src.startswith('['):
+            kind, src = src.split(']', 1)
+            kind = kind[1:]
+        state[path] = (src, rev.get(path, ''), kind)
 
     return state
 
@@ -45,6 +49,7 @@
                          for s in sorted(state)]), '')
 
 def submerge(repo, wctx, mctx, actx):
+    # working context, merging context, ancestor context
     if mctx == actx: # backwards?
         actx = wctx.p1()
     s1 = wctx.substate
@@ -56,7 +61,7 @@
 
     def debug(s, msg, r=""):
         if r:
-            r = "%s:%s" % r
+            r = "%s:%s" % r[:-1]
         repo.ui.debug("  subrepo %s: %s %s\n" % (s, msg, r))
 
     for s, l in s1.items():
@@ -105,7 +110,7 @@
             continue
         elif s not in sa:
             debug(s, "remote added, get", r)
-            wctx.sub(s).get(r)
+            mctx.sub(s).get(r)
             sm[s] = r
         elif r != sa[s]:
             if repo.ui.promptchoice(
@@ -145,9 +150,7 @@
 
     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)
+    return getrepoclass(state[2])(ctx, path, state[:2])
 
 # subrepo classes need to implement the following methods:
 # __init__(self, ctx, path, state)
@@ -204,7 +207,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:
@@ -216,7 +219,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)
 
@@ -242,3 +245,13 @@
         dsturl = _abssource(self._repo, True)
         other = hg.repository(self._repo.ui, dsturl)
         self._repo.push(other, force)
+
+def getrepoclass(t):
+    try:
+        return types[t]
+    except KeyError:
+        raise util.Abort(_('unknown subrepo type %s') % t)
+
+types = {
+    'hg': hgsubrepo,
+    }


More information about the Mercurial-devel mailing list