# HG changeset patch # User Matt Harbison # Date 2015-06-03 17:45:42 # Node ID c4a92867c048b725ada6f5f38ae88c27515297dc # Parent 21b536f01edabee51e75daa4fed882ea80c1cab9 subrepo: introduce the nullsubrepo() method This will be used in an upcoming patch. It's a one-off use, but seems better to be contained in the subrepo module, than for the next patch to overwrite the _ctx and _state fields in another module. '' is used as the default revision in subrepo.state() if it can't be found, so it seems like a safe choice. diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -340,6 +340,25 @@ def subrepo(ctx, path): raise util.Abort(_('unknown subrepo type %s') % state[2]) return types[state[2]](ctx, path, state[:2]) +def nullsubrepo(ctx, path, pctx): + """return an empty subrepo in pctx for the extant subrepo in ctx""" + # subrepo inherently violates our import layering rules + # because it wants to make repo objects from deep inside the stack + # so we manually delay the circular imports to not break + # scripts that don't use our demand-loading + global hg + import hg as h + hg = h + + pathutil.pathauditor(ctx.repo().root)(path) + state = ctx.substate[path] + if state[2] not in types: + raise util.Abort(_('unknown subrepo type %s') % state[2]) + subrev = '' + if state[2] == 'hg': + subrev = "0" * 40 + return types[state[2]](pctx, path, (state[0], subrev)) + def newcommitphase(ui, ctx): commitphase = phases.newcommitphase(ui) substate = getattr(ctx, "substate", None)