diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -10,7 +10,7 @@ from i18n import _ import config, util, node, error hg = None -nullstate = ('', '') +nullstate = ('', '', 'empty') def state(ctx): p = config.config() @@ -35,7 +35,13 @@ def state(ctx): 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 submerge(repo, wctx, mctx, actx): 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 @@ def subrepo(ctx, path): 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 @@ class hgsubrepo(object): 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 @@ class hgsubrepo(object): 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 @@ class hgsubrepo(object): 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 @@ cd ../tc 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 @@ resolving manifests 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 @@ resolving manifests 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 @@ adding file changes 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