[PATCH 5 of 8] largefiles: avoid redundant loop to eliminate None from list

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sun Mar 26 21:53:45 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 77257838e7eb6abf1796e30539c996b4bdfc57a5
# Parent  d1347341abb3e026ef6aa751b1048ceef44b3991
largefiles: avoid redundant loop to eliminate None from list

Before this patch, this code path contains two loops for m._files: one
for replacement with standin, and another for elimination of None,
which comes from previous replacement ("standin in wctx or
lfdirstate[f] == 'r'" case in tostandin()).

These two loops can be unified into simple one "for" loop.

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -759,15 +759,16 @@ def overriderevert(orig, ui, repo, ctx, 
                                                False)
 
             wctx = repo[None]
-            def tostandin(f):
+            matchfiles = []
+            for f in m._files:
                 standin = lfutil.standin(f)
                 if standin in ctx or standin in mctx:
-                    return standin
+                    matchfiles.append(standin)
                 elif standin in wctx or lfdirstate[f] == 'r':
-                    return None
-                return f
-            m._files = [tostandin(f) for f in m._files]
-            m._files = [f for f in m._files if f is not None]
+                    continue
+                else:
+                    matchfiles.append(f)
+            m._files = matchfiles
             m._fileroots = set(m._files)
             origmatchfn = m.matchfn
             def matchfn(f):


More information about the Mercurial-devel mailing list