changeset 6929:972d98ce3552 stable

evolve: unrelated parts of splits are no longer considered content-divergent Let's backport e68fe567a780 from core that improves content-divergence computation. This way we can both provide a better experience to evolve extension users on older Mercurial versions, and don't have to fix evolve tests for hg 6.1 that we use for one of our CI jobs.
author Anton Shestakov <av6@dwimlabs.net>
date Wed, 06 Nov 2024 16:45:02 +0400
parents 85b1b169dfba
children 195941260a67
files hgext3rd/evolve/obscache.py tests/test-evolve-templates.t
diffstat 2 files changed, 45 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/obscache.py	Sat Oct 26 11:16:25 2024 +0400
+++ b/hgext3rd/evolve/obscache.py	Wed Nov 06 16:45:02 2024 +0400
@@ -14,6 +14,7 @@
 from mercurial import (
     localrepo,
     obsolete,
+    obsutil,
     phases,
     node,
     util,
@@ -462,12 +463,45 @@
         isobs = obscache.get
     return frozenset(r for r in notpublic if isobs(r))
 
+def _computecontentdivergentset(repo):
+    """the set of rev that compete to be the final successors of some revision."""
+    divergent = set()
+    obsstore = repo.obsstore
+    newermap = {}
+    tonode = repo.changelog.node
+    candidates = sorted(obsolete._mutablerevs(repo) - obsolete.getrevs(repo, b"obsolete"))
+    for rev in candidates:
+        node = tonode(rev)
+        mark = obsstore.predecessors.get(node, ())
+        toprocess = set(mark)
+        seen = set()
+        while toprocess:
+            prec = toprocess.pop()[0]
+            if prec in seen:
+                continue  # emergency cycle hanging prevention
+            seen.add(prec)
+            if prec not in newermap:
+                obsutil.successorssets(repo, prec, cache=newermap)
+            newer = [n for n in newermap[prec] if n]
+            # only this condition was changed in hg 6.9
+            # hg <= 6.8 (e68fe567a780)
+            if len(newer) > 1 and any(n for n in newer if node not in n):
+                divergent.add(rev)
+                break
+            toprocess.update(obsstore.predecessors.get(prec, ()))
+    return frozenset(divergent)
+
 @eh.uisetup
 def cachefuncs(ui):
     orig = obsolete.cachefuncs[b'obsolete']
     wrapped = lambda repo: _computeobsoleteset(orig, repo)
     obsolete.cachefuncs[b'obsolete'] = wrapped
 
+    if util.versiontuple(n=3) < (6, 8, 2):
+        # e68fe567a780 was just before the 6.8.2 release
+        # hg <= 6.8 (e68fe567a780)
+        obsolete.cachefuncs[b'contentdivergent'] = _computecontentdivergentset
+
 @eh.reposetup
 def setupcache(ui, repo):
 
--- a/tests/test-evolve-templates.t	Sat Oct 26 11:16:25 2024 +0400
+++ b/tests/test-evolve-templates.t	Wed Nov 06 16:45:02 2024 +0400
@@ -1424,7 +1424,7 @@
   working directory parent is obsolete! (4a004186e638)
   (use 'hg evolve' to update to its successor: b18bc8331526)
   $ hg commit --amend -m "Add B only"
-  4 new content-divergent changesets
+  2 new content-divergent changesets
 
   $ hg log -G
   @  changeset:   9:0b997eb7ceee
@@ -1445,7 +1445,7 @@
   | *  changeset:   7:ba2ed02b0c9a
   | |  user:        test
   | |  date:        Thu Jan 01 00:00:00 1970 +0000
-  | |  instability: orphan, content-divergent
+  | |  instability: orphan
   | |  summary:     Add A,B,C
   | |
   | x  changeset:   6:4a004186e638
@@ -1455,11 +1455,10 @@
   |    obsolete:    reworded using amend as 9:0b997eb7ceee
   |    summary:     Add A,B,C
   |
-  *  changeset:   5:dd800401bd8c
+  o  changeset:   5:dd800401bd8c
   |  parent:      3:f897c6137566
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000
-  |  instability: content-divergent
   |  summary:     Add A,B,C
   |
   o  changeset:   3:f897c6137566
@@ -1495,7 +1494,7 @@
   |      Fate: reworded using amend as 8:b18bc8331526
   |      Fate: reworded using amend as 9:0b997eb7ceee
   |
-  *  dd800401bd8c
+  o  dd800401bd8c
   |
   o  f897c6137566
   |
@@ -1513,7 +1512,7 @@
   | x  4a004186e638
   |/     Obsfate: reworded using amend as 8:b18bc8331526; reworded using amend as 9:0b997eb7ceee
   |
-  *  dd800401bd8c
+  o  dd800401bd8c
   |
   o  f897c6137566
   |
@@ -1544,7 +1543,7 @@
   |      Fate: reworded using amend as 9:0b997eb7ceee
   |      Origin: split from 4:9bd10a0775e4
   |
-  *  dd800401bd8c
+  o  dd800401bd8c
   |    Predecessors: 4:9bd10a0775e4
   |    semi-colon: 4:9bd10a0775e4
   |    Origin: split from 4:9bd10a0775e4
@@ -1592,7 +1591,7 @@
   |/     Obsfate: reworded using amend as 8:b18bc8331526; reworded using amend as 9:0b997eb7ceee
   |      Obsorigin: split from 4:9bd10a0775e4
   |
-  *  dd800401bd8c
+  o  dd800401bd8c
   |    Obsorigin: split from 4:9bd10a0775e4
   |
   | x  9bd10a0775e4
@@ -1620,7 +1619,7 @@
   $ hg rebase -r 7 -d 8 --config extensions.rebase=
   rebasing 7:ba2ed02b0c9a "Add A,B,C"
   $ hg tlog
-  *  eceed8f98ffc
+  o  eceed8f98ffc
   |    Predecessors: 4:9bd10a0775e4
   |    semi-colon: 4:9bd10a0775e4
   |    Origin: rewritten using rebase from 4:9bd10a0775e4
@@ -1635,7 +1634,7 @@
   |      semi-colon: 4:9bd10a0775e4
   |      Origin: rewritten using amend from 4:9bd10a0775e4
   |
-  *  dd800401bd8c
+  o  dd800401bd8c
   |    Predecessors: 4:9bd10a0775e4
   |    semi-colon: 4:9bd10a0775e4
   |    Origin: split from 4:9bd10a0775e4
@@ -1651,7 +1650,7 @@
   o  ea207398892e
   
   $ hg fateoriginlog
-  *  eceed8f98ffc
+  o  eceed8f98ffc
   |    Obsorigin: rewritten using rebase from 4:9bd10a0775e4
   |
   | *  0b997eb7ceee
@@ -1660,7 +1659,7 @@
   * |  b18bc8331526
   |/     Obsorigin: rewritten using amend from 4:9bd10a0775e4
   |
-  *  dd800401bd8c
+  o  dd800401bd8c
   |    Obsorigin: split from 4:9bd10a0775e4
   |
   | @  9bd10a0775e4