[PATCH 1 of 6] subrepo: prefetch ctx.repo() for efficiency and centralization

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Thu Jul 9 11:02:58 CDT 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1436457591 -32400
#      Fri Jul 10 00:59:51 2015 +0900
# Node ID 86048cf48d5c86497dfde9a2ccce9dfb0794d920
# Parent  648323f41a89619d9eeeb7287213378c340866c8
subrepo: prefetch ctx.repo() for efficiency and centralization

'subrepo.state()' refers same 'ctx.repo()' in many places and times.

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -62,6 +62,7 @@ def state(ctx, ui):
     (key in types dict))
     """
     p = config.config()
+    repo = ctx.repo()
     def read(f, sections=None, remap=None):
         if f in ctx:
             try:
@@ -71,11 +72,10 @@ def state(ctx, ui):
                     raise
                 # handle missing subrepo spec files as removed
                 ui.warn(_("warning: subrepo spec file \'%s\' not found\n") %
-                        util.pathto(ctx.repo().root, ctx.repo().getcwd(), f))
+                        util.pathto(repo.root, repo.getcwd(), f))
                 return
             p.parse(f, data, sections, remap, read)
         else:
-            repo = ctx.repo()
             raise util.Abort(_("subrepo spec file \'%s\' not found") %
                              util.pathto(repo.root, repo.getcwd(), f))
 
@@ -95,7 +95,6 @@ def state(ctx, ui):
                 try:
                     revision, path = l.split(" ", 1)
                 except ValueError:
-                    repo = ctx.repo()
                     raise util.Abort(_("invalid subrepository revision "
                                        "specifier in \'%s\' line %d")
                                      % (util.pathto(repo.root, repo.getcwd(),
@@ -132,7 +131,7 @@ def state(ctx, ui):
             src = src.lstrip() # strip any extra whitespace after ']'
 
         if not util.url(src).isabs():
-            parent = _abssource(ctx.repo(), abort=False)
+            parent = _abssource(repo, abort=False)
             if parent:
                 parent = util.url(parent)
                 parent.path = posixpath.join(parent.path or '', src)


More information about the Mercurial-devel mailing list