[PATCH 3 of 8] largefiles: avoid redundant changectx looking up at each repetitions

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sun Mar 26 21:53:43 EDT 2017


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1490575475 -32400
#      Mon Mar 27 09:44:35 2017 +0900
# Node ID 34114d49e2c514600ec7527d266cdef2ee22e249
# Parent  b279d4b86fd671556ada1ce24a14a39894b6aa11
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.

diff --git a/hgext/largefiles/lfcommands.py b/hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py
+++ b/hgext/largefiles/lfcommands.py
@@ -403,9 +403,10 @@ def cachelfiles(ui, repo, node, filelist
         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 @@ def updatelfiles(ui, repo, filelist=None
         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 @@ def updatelfiles(ui, repo, filelist=None
                     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 @@ def updatelfiles(ui, repo, filelist=None
                 # 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
 
diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -759,11 +759,12 @@ def overriderevert(orig, ui, repo, ctx, 
             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 @@ def cmdutilforget(orig, ui, repo, match,
         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)


More information about the Mercurial-devel mailing list