# HG changeset patch # User Anton Shestakov # Date 1731762062 -14400 # Node ID 954d7ea5cd674c43c935135a2cc6e738d016199c # Parent dd518437d4e0ef5febf45c9168df50b4e2d2168a 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. diff -r dd518437d4e0 -r 954d7ea5cd67 hgext3rd/topic/stack.py --- 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 diff -r dd518437d4e0 -r 954d7ea5cd67 tests/test-stack-split-s0.t --- /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)