D5594: copies: consider nullrev a common ancestor

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Wed Jan 16 00:27:31 UTC 2019


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

REVISION SUMMARY
  I've seen many bugs in the git codebase that were caused by it not
  having a null revision and being forced to treat root commits
  differently. Mercurial has a null revision and I think it's generally
  a bug to treat it differently from other commits in graph algorithms.
  
  This effectively undoes https://phab.mercurial-scm.org/rHG83cfa1baf8ad6d3f28eff03dec4c2ab282d87b65 (copies: don't report copies with
  unrelated branch, 2010-01-01). The test cases that that commit added
  still passes. I suspect some other fix after that commit made it
  unnecessary.

REPOSITORY
  rHG Mercurial

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

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
@@ -31,7 +31,6 @@
     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.
-    None if no such revision exists.
     """
 
     # basic idea:
@@ -55,7 +54,6 @@
     visit = [-a, -b]
     heapq.heapify(visit)
     interesting = len(visit)
-    hascommonancestor = False
     limit = node.wdirrev
 
     while interesting:
@@ -65,8 +63,6 @@
         else:
             parents = cl.parentrevs(r)
         for p in parents:
-            if p < 0:
-                continue
             if p not in side:
                 # first time we see p; add it to visit
                 side[p] = side[r]
@@ -77,14 +73,10 @@
                 # p was interesting but now we know better
                 side[p] = 0
                 interesting -= 1
-                hascommonancestor = True
         if side[r]:
             limit = r # lowest rev visited
             interesting -= 1
 
-    if not hascommonancestor:
-        return None
-
     # 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')
@@ -169,8 +161,6 @@
         dbg('debug.copies:    looking into rename from %s to %s\n'
             % (a, b))
     limit = _findlimit(repo, a.rev(), b.rev())
-    if limit is None:
-        limit = node.nullrev
     if debug:
         dbg('debug.copies:      search limit: %d\n' % limit)
     am = a.manifest()
@@ -465,9 +455,6 @@
         tca = _c1.ancestor(_c2)
 
     limit = _findlimit(repo, c1.rev(), c2.rev())
-    if limit is None:
-        # no common ancestor, no copies
-        return {}, {}, {}, {}, {}
     repo.ui.debug("  searching for copies back to rev %d\n" % limit)
 
     m1 = c1.manifest()



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


More information about the Mercurial-devel mailing list