largefiles: omit redundant isstandin() before splitstandin()
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Fri, 24 Mar 2017 22:24:58 +0900
changeset 31613 5c1d3f1b8f44
parent 31612 c93cdfa131a8
child 31614 d5d0e6ca62ad
largefiles: omit redundant isstandin() before splitstandin() There are many isstandin() invocations before splitstandin(). The former examines whether specified path starts with ".hglf/". The latter returns after ".hglf/" of specified path if it starts with that prefix, or returns None otherwise. Therefore, value returned by splitstandin() can be used for replacement of preceding isstandin(), and this replacement can omit redundant string comparison after isstandin().
hgext/largefiles/lfcommands.py
hgext/largefiles/lfutil.py
hgext/largefiles/overrides.py
--- a/hgext/largefiles/lfcommands.py	Fri Mar 24 22:13:23 2017 +0900
+++ b/hgext/largefiles/lfcommands.py	Fri Mar 24 22:24:58 2017 +0900
@@ -244,10 +244,10 @@
             dstfiles.append(f)
 
     def getfilectx(repo, memctx, f):
-        if lfutil.isstandin(f):
+        srcfname = lfutil.splitstandin(f)
+        if srcfname is not None:
             # if the file isn't in the manifest then it was removed
             # or renamed, return None to indicate this
-            srcfname = lfutil.splitstandin(f)
             try:
                 fctx = ctx.filectx(srcfname)
             except error.LookupError:
--- a/hgext/largefiles/lfutil.py	Fri Mar 24 22:13:23 2017 +0900
+++ b/hgext/largefiles/lfutil.py	Fri Mar 24 22:24:58 2017 +0900
@@ -261,8 +261,8 @@
 
     ctx = repo[node]
     for filename in ctx.files():
-        if isstandin(filename) and filename in ctx.manifest():
-            realfile = splitstandin(filename)
+        realfile = splitstandin(filename)
+        if realfile is not None and filename in ctx.manifest():
             copytostore(repo, ctx.node(), realfile)
 
 def copytostoreabsolute(repo, file, hash):
@@ -478,8 +478,8 @@
 
     lfdirstate = openlfdirstate(repo.ui, repo)
     for f in ctx.files():
-        if isstandin(f):
-            lfile = splitstandin(f)
+        lfile = splitstandin(f)
+        if lfile is not None:
             synclfdirstate(repo, lfdirstate, lfile, False)
     lfdirstate.write()
 
--- a/hgext/largefiles/overrides.py	Fri Mar 24 22:13:23 2017 +0900
+++ b/hgext/largefiles/overrides.py	Fri Mar 24 22:24:58 2017 +0900
@@ -649,10 +649,13 @@
             m._files = [lfutil.standin(f) for f in m._files if lfile(f)]
             m._fileroots = set(m._files)
             origmatchfn = m.matchfn
-            m.matchfn = lambda f: (lfutil.isstandin(f) and
-                                (f in manifest) and
-                                origmatchfn(lfutil.splitstandin(f)) or
-                                None)
+            def matchfn(f):
+                lfile = lfutil.splitstandin(f)
+                return (lfile is not None and
+                        (f in manifest) and
+                        origmatchfn(lfile) or
+                        None)
+            m.matchfn = matchfn
             return m
         oldmatch = installmatchfn(overridematch)
         listpats = []
@@ -767,8 +770,9 @@
             m._fileroots = set(m._files)
             origmatchfn = m.matchfn
             def matchfn(f):
-                if lfutil.isstandin(f):
-                    return (origmatchfn(lfutil.splitstandin(f)) and
+                lfile = lfutil.splitstandin(f)
+                if lfile is not None:
+                    return (origmatchfn(lfile) and
                             (f in ctx or f in mctx))
                 return origmatchfn(f)
             m.matchfn = matchfn
@@ -968,18 +972,19 @@
     for f in ctx:
         ff = ctx.flags(f)
         getdata = ctx[f].data
-        if lfutil.isstandin(f):
+        lfile = lfutil.splitstandin(f)
+        if lfile is not None:
             if node is not None:
                 path = lfutil.findfile(repo, getdata().strip())
 
                 if path is None:
                     raise error.Abort(
                        _('largefile %s not found in repo store or system cache')
-                       % lfutil.splitstandin(f))
+                       % lfile)
             else:
-                path = lfutil.splitstandin(f)
+                path = lfile
 
-            f = lfutil.splitstandin(f)
+            f = lfile
 
             getdata = lambda: util.readfile(path)
         write(f, 'x' in ff and 0o755 or 0o644, 'l' in ff, getdata)
@@ -1018,18 +1023,19 @@
     for f in ctx:
         ff = ctx.flags(f)
         getdata = ctx[f].data
-        if lfutil.isstandin(f):
+        lfile = lfutil.splitstandin(f)
+        if lfile is not None:
             if ctx.node() is not None:
                 path = lfutil.findfile(repo._repo, getdata().strip())
 
                 if path is None:
                     raise error.Abort(
                        _('largefile %s not found in repo store or system cache')
-                       % lfutil.splitstandin(f))
+                       % lfile)
             else:
-                path = lfutil.splitstandin(f)
+                path = lfile
 
-            f = lfutil.splitstandin(f)
+            f = lfile
 
             getdata = lambda: util.readfile(os.path.join(prefix, path))
 
@@ -1433,7 +1439,11 @@
 def scmutilmarktouched(orig, repo, files, *args, **kwargs):
     result = orig(repo, files, *args, **kwargs)
 
-    filelist = [lfutil.splitstandin(f) for f in files if lfutil.isstandin(f)]
+    filelist = []
+    for f in files:
+        lf = lfutil.splitstandin(f)
+        if lf is not None:
+            filelist.append(lf)
     if filelist:
         lfcommands.updatelfiles(repo.ui, repo, filelist=filelist,
                                 printmessage=False, normallookup=True)