subrepo: prefetch ctx.repo() for efficiency and centralization
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Fri, 10 Jul 2015 00:59:51 +0900
changeset 25768 7a9ef8608a1d
parent 25767 026105c442d7
child 25769 2538b87660be
subrepo: prefetch ctx.repo() for efficiency and centralization 'subrepo.state()' refers same 'ctx.repo()' in many places and times.
mercurial/subrepo.py
--- a/mercurial/subrepo.py	Thu Jul 02 21:39:31 2015 +0900
+++ b/mercurial/subrepo.py	Fri Jul 10 00:59:51 2015 +0900
@@ -62,6 +62,7 @@
     (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 @@
                     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 @@
                 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 @@
             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)