[PATCH 1 of 3] subrepo: introduce the nullsubrepo() method

Matt Harbison mharbison at attotech.com
Wed Jun 3 14:11:55 CDT 2015


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1433353542 14400
#      Wed Jun 03 13:45:42 2015 -0400
# Node ID 62e009c94b8ab987a7fb3b3fb6d328cf309067fc
# Parent  724d7982b7906775b024c04875c0c064342d186e
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)


More information about the Mercurial-devel mailing list