changeset 25416:c4a92867c048

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.
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 03 Jun 2015 13:45:42 -0400
parents 21b536f01eda
children 95c271356a66
files mercurial/subrepo.py
diffstat 1 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/subrepo.py	Thu May 07 17:15:24 2015 +0900
+++ b/mercurial/subrepo.py	Wed Jun 03 13:45:42 2015 -0400
@@ -340,6 +340,25 @@
         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)