D6277: copies: filter out copies from non-existent source later in _chain()

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Thu Apr 18 13:58:44 EDT 2019


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  _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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6277

AFFECTED FILES
  mercurial/copies.py

CHANGE DETAILS

diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -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)



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list