changeset 6935:954d7ea5cd67 stable

stack: when stack base is obsolete, pick any successor, even if at random There are situations when s0 is obsolete and we also cannot pick just one successor for it to use in stack. In such a case, let's pick the "latest" successor from the first set. We're assuming that obsutil.successorssets() returns data in the same order (it should, since it makes sure to sort data internally). Keeping that in mind, while the successor picked for s0 by this code is not based on any sort of sophisticated logic, it should nonetheless be the same every time. This patch is probably not going to completely break anything that was previously working fine, because the previous behavior was to just abort with an exception.
author Anton Shestakov <av6@dwimlabs.net>
date Sat, 16 Nov 2024 17:01:02 +0400
parents dd518437d4e0
children a239ea1dfacb
files hgext3rd/topic/stack.py tests/test-stack-split-s0.t
diffstat 2 files changed, 75 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/stack.py	Sat Nov 16 17:59:53 2024 +0400
+++ b/hgext3rd/topic/stack.py	Sat Nov 16 17:01:02 2024 +0400
@@ -181,7 +181,11 @@
             pt1 = self._repo[b'.']
 
         if pt1.obsolete():
-            pt1 = self._repo[_singlesuccessor(self._repo, pt1)]
+            try:
+                pt1 = self._repo[_singlesuccessor(self._repo, pt1)]
+            except MultipleSuccessorsError as e:
+                # here, taking a random successor is better than failing
+                pt1 = self._repo[e.successorssets[0][-1]]
         revs.insert(0, pt1.rev())
         return revs
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-stack-split-s0.t	Sat Nov 16 17:01:02 2024 +0400
@@ -0,0 +1,70 @@
+Testing the case when s0 is obsolete, and has multiple successors that are
+topological heads
+
+  $ . "$TESTDIR/testlib/common.sh"
+
+  $ cat << EOF >> "$HGRCPATH"
+  > [extensions]
+  > evolve =
+  > topic =
+  > EOF
+
+  $ hg init split-s0
+  $ cd split-s0
+
+  $ mkcommit ROOT
+  $ mkcommit A
+
+creating a small stack for the experiment
+
+  $ hg branch cool-stack
+  marked working directory as branch cool-stack
+  (branches are permanent and global, did you want a bookmark?)
+  $ mkcommit J
+  $ mkcommit K
+  $ mkcommit L
+
+right now everything is stable, including s0
+
+  $ hg stack
+  ### target: cool-stack (branch)
+  s3@ L (current)
+  s2: K
+  s1: J
+  s0^ A (base)
+
+destabilize the stack by obsoleting s0 with 2 successors
+
+  $ hg up 'desc(ROOT)' -q
+  $ mkcommit X
+  created new head
+  (consider using topic for lightweight branches. See 'hg help topic')
+  $ hg up 'desc(ROOT)' -q
+  $ mkcommit Y
+  created new head
+  (consider using topic for lightweight branches. See 'hg help topic')
+
+  $ hg --config extensions.evolve= prune --split --rev 'desc(A)' \
+  >    --successor 'desc(X)' --successor 'desc(Y)'
+  1 changesets pruned
+  3 new orphan changesets
+
+the 2 successors are 2 different heads (the revset is taken from _singlesuccessor function)
+
+  $ hg log -r 'heads((desc(X)+desc(Y))::(desc(X)+desc(Y)))' -GT '{desc}\n'
+  @  Y
+  |
+  ~
+  o  X
+  |
+  ~
+
+we choose one of the successors for s0, this is better than failing to show the stack at all
+
+  $ hg up 'desc(L)' -q
+  $ hg stack
+  ### target: cool-stack (branch)
+  s3@ L (current orphan)
+  s2$ K (orphan)
+  s1$ J (orphan)
+  s0^ Y (base)