largefiles: avoid redundant changectx looking up at each repetitions
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Mon, 27 Mar 2017 09:44:35 +0900
changeset 31659 1af4a1641bdb
parent 31658 32d998dc2a00
child 31660 9d075911df49
largefiles: avoid redundant changectx looking up at each repetitions These code paths look up changectx at each repetitions, even though the changectx key isn't changed while loop.
hgext/largefiles/lfcommands.py
hgext/largefiles/overrides.py
--- a/hgext/largefiles/lfcommands.py	Mon Mar 27 09:44:34 2017 +0900
+++ b/hgext/largefiles/lfcommands.py	Mon Mar 27 09:44:35 2017 +0900
@@ -403,9 +403,10 @@
         lfiles = set(lfiles) & set(filelist)
     toget = []
 
+    ctx = repo[node]
     for lfile in lfiles:
         try:
-            expectedhash = repo[node][lfutil.standin(lfile)].data().strip()
+            expectedhash = ctx[lfutil.standin(lfile)].data().strip()
         except IOError as err:
             if err.errno == errno.ENOENT:
                 continue # node must be None and standin wasn't found in wctx
@@ -457,6 +458,7 @@
         update = {}
         updated, removed = 0, 0
         wvfs = repo.wvfs
+        wctx = repo[None]
         for lfile in lfiles:
             rellfile = lfile
             rellfileorig = os.path.relpath(
@@ -474,7 +476,7 @@
                     wvfs.unlinkpath(relstandinorig)
                 expecthash = lfutil.readstandin(repo, lfile)
                 if expecthash != '':
-                    if lfile not in repo[None]: # not switched to normal file
+                    if lfile not in wctx: # not switched to normal file
                         wvfs.unlinkpath(rellfile, ignoremissing=True)
                     # use normallookup() to allocate an entry in largefiles
                     # dirstate to prevent lfilesrepo.status() from reporting
@@ -487,7 +489,7 @@
                 # largefile is converted back to a normal file: the standin
                 # disappears, but a new (normal) file appears as the lfile.
                 if (wvfs.exists(rellfile) and
-                    repo.dirstate.normalize(lfile) not in repo[None]):
+                    repo.dirstate.normalize(lfile) not in wctx):
                     wvfs.unlinkpath(rellfile)
                     removed += 1
 
--- a/hgext/largefiles/overrides.py	Mon Mar 27 09:44:34 2017 +0900
+++ b/hgext/largefiles/overrides.py	Mon Mar 27 09:44:35 2017 +0900
@@ -759,11 +759,12 @@
             lfdirstate = lfutil.openlfdirstate(mctx.repo().ui, mctx.repo(),
                                                False)
 
+            wctx = repo[None]
             def tostandin(f):
                 standin = lfutil.standin(f)
                 if standin in ctx or standin in mctx:
                     return standin
-                elif standin in repo[None] or lfdirstate[f] == 'r':
+                elif standin in wctx or lfdirstate[f] == 'r':
                     return None
                 return f
             m._files = [tostandin(f) for f in m._files]
@@ -1077,8 +1078,9 @@
         s = repo.status(match=m, clean=True)
     finally:
         repo.lfstatus = False
+    manifest = repo[None].manifest()
     forget = sorted(s.modified + s.added + s.deleted + s.clean)
-    forget = [f for f in forget if lfutil.standin(f) in repo[None].manifest()]
+    forget = [f for f in forget if lfutil.standin(f) in manifest]
 
     for f in forget:
         fstandin = lfutil.standin(f)