copies: filter out copies from non-existent source later in _chain()
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 17 Apr 2019 23:10:29 -0700
changeset 42230 fdbeacb9d456
parent 42229 5a3979529740
child 42231 d345627d104b
copies: filter out copies from non-existent source later in _chain() _changesetforwardcopies() repeatedly calls _chain(). That is very expensive because _chain() does lookups in the manifest. I hope to split up the function in two parts: 1) simple chaining, not considering end points, and 2) filter out files that don't exist in the end points (and ping-pong copies/renames). This patches gets us closer to that by moving the check for non-existent source later in the function. Now there are no more checks for "src" and "dst" in the first loop; all the filtering of invalid copies is done in the second loop. The code also looks much more consistent now. No measureable impact on `hg debugpathcopies 4.0 4.8`. That shouldn't be surprising since the only case we're doing more checks now is in case of chained copies/renames, which are quire rare in practice. Differential Revision: https://phab.mercurial-scm.org/D6277
mercurial/copies.py
--- a/mercurial/copies.py	Thu Apr 18 00:12:56 2019 -0700
+++ b/mercurial/copies.py	Wed Apr 17 23:10:29 2019 -0700
@@ -134,13 +134,16 @@
             if t[v] != k:
                 # file wasn't renamed back to itself (i.e. case 4, not 3)
                 t[k] = t[v]
-        elif v in src:
-            # file is a copy of an existing file, i.e. case 6.
+        else:
+            # Renamed only in 'b', i.e. cases 5 & 6. We'll remove case 5 later.
             t[k] = v
 
     for k, v in list(t.items()):
+        # remove copies from files that didn't exist, i.e. case 5
+        if v not in src:
+            del t[k]
         # remove criss-crossed copies, i.e. case 3
-        if k in src and v in dst:
+        elif k in src and v in dst:
             del t[k]
         # remove copies to files that were then removed, i.e. case 1
         # and file 'y' in cases 3 & 4 (in case of rename)