[PATCH 2 of 2] copies: drop the findlimit logic

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Oct 10 19:04:13 EDT 2019


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1570720726 -7200
#      Thu Oct 10 17:18:46 2019 +0200
# Node ID ff99cd7cca3e35023e0a51d47affa8ad51271a3b
# Parent  2477ba483c04067900d1e9f6523b03df68a4d545
# EXP-Topic patchcopies-regression
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r ff99cd7cca3e
copies: drop the findlimit logic

We don't use the limit anymore so we should stop computing that limit.

I did not bother measuring the potential performance gain. I am assuming that
not running any code will be faster that doing some computation and not using
the result.

diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -23,91 +23,6 @@ from . import (
 from .utils import stringutil
 
 
-def _findlimit(repo, ctxa, ctxb):
-    """
-    Find the last revision that needs to be checked to ensure that a full
-    transitive closure for file copies can be properly calculated.
-    Generally, this means finding the earliest revision number that's an
-    ancestor of a or b but not both, except when a or b is a direct descendent
-    of the other, in which case we can return the minimum revnum of a and b.
-    """
-
-    # basic idea:
-    # - mark a and b with different sides
-    # - if a parent's children are all on the same side, the parent is
-    #   on that side, otherwise it is on no side
-    # - walk the graph in topological order with the help of a heap;
-    #   - add unseen parents to side map
-    #   - clear side of any parent that has children on different sides
-    #   - track number of interesting revs that might still be on a side
-    #   - track the lowest interesting rev seen
-    #   - quit when interesting revs is zero
-
-    cl = repo.changelog
-    wdirparents = None
-    a = ctxa.rev()
-    b = ctxb.rev()
-    if a is None:
-        wdirparents = (ctxa.p1(), ctxa.p2())
-        a = node.wdirrev
-    if b is None:
-        assert not wdirparents
-        wdirparents = (ctxb.p1(), ctxb.p2())
-        b = node.wdirrev
-
-    side = {a: -1, b: 1}
-    visit = [-a, -b]
-    heapq.heapify(visit)
-    interesting = len(visit)
-    limit = node.wdirrev
-
-    while interesting:
-        r = -(heapq.heappop(visit))
-        if r == node.wdirrev:
-            parents = [pctx.rev() for pctx in wdirparents]
-        else:
-            parents = cl.parentrevs(r)
-        if parents[1] == node.nullrev:
-            parents = parents[:1]
-        for p in parents:
-            if p not in side:
-                # first time we see p; add it to visit
-                side[p] = side[r]
-                if side[p]:
-                    interesting += 1
-                heapq.heappush(visit, -p)
-            elif side[p] and side[p] != side[r]:
-                # p was interesting but now we know better
-                side[p] = 0
-                interesting -= 1
-        if side[r]:
-            limit = r  # lowest rev visited
-            interesting -= 1
-
-    # Consider the following flow (see test-commit-amend.t under issue4405):
-    # 1/ File 'a0' committed
-    # 2/ File renamed from 'a0' to 'a1' in a new commit (call it 'a1')
-    # 3/ Move back to first commit
-    # 4/ Create a new commit via revert to contents of 'a1' (call it 'a1-amend')
-    # 5/ Rename file from 'a1' to 'a2' and commit --amend 'a1-msg'
-    #
-    # During the amend in step five, we will be in this state:
-    #
-    # @  3 temporary amend commit for a1-amend
-    # |
-    # o  2 a1-amend
-    # |
-    # | o  1 a1
-    # |/
-    # o  0 a0
-    #
-    # When _findlimit is called, a and b are revs 3 and 0, so limit will be 2,
-    # yet the filelog has the copy information in rev 1 and we will not look
-    # back far enough unless we also look at the a and b as candidates.
-    # This only occurs when a is a descendent of b or visa-versa.
-    return min(limit, a, b)
-
-
 def _filter(src, dst, t):
     """filters out invalid copies after chaining"""
 
@@ -153,7 +68,7 @@ def _chain(a, b):
     return t
 
 
-def _tracefile(fctx, am, basemf, limit):
+def _tracefile(fctx, am, basemf):
     """return file context that is the ancestor of fctx present in ancestor
     manifest am
 
@@ -207,9 +122,6 @@ def _committedforwardcopies(a, b, base, 
     dbg = repo.ui.debug
     if debug:
         dbg(b'debug.copies:    looking into rename from %s to %s\n' % (a, b))
-    limit = _findlimit(repo, a, b)
-    if debug:
-        dbg(b'debug.copies:      search limit: %d\n' % limit)
     am = a.manifest()
     basemf = None if base is None else base.manifest()
 
@@ -243,7 +155,7 @@ def _committedforwardcopies(a, b, base, 
 
         if debug:
             start = util.timer()
-        opath = _tracefile(fctx, am, basemf, limit)
+        opath = _tracefile(fctx, am, basemf)
         if opath:
             if debug:
                 dbg(b'debug.copies:          rename of: %s\n' % opath)
diff --git a/tests/test-mv-cp-st-diff.t b/tests/test-mv-cp-st-diff.t
--- a/tests/test-mv-cp-st-diff.t
+++ b/tests/test-mv-cp-st-diff.t
@@ -1676,7 +1676,6 @@ Check debug output for copy tracing
   debug.copies: searching copies from a51f36ab1704 to 1f4aa1fd627b
   debug.copies: search mode: forward
   debug.copies:    looking into rename from a51f36ab1704 to 1f4aa1fd627b
-  debug.copies:      search limit: 3
   debug.copies:      missing files to search: 1
   debug.copies:        tracing file: renamed
   debug.copies:          rename of: f


More information about the Mercurial-devel mailing list