changeset 4728:ef8907df73fc stable

touch: fix the inconsistent behavior of divergence catching logic (issue6107) When touching a node, the way we check if it can lead to divergence is we look at the successors sets of the rev being touched. And if there is successor revs exists (excluding the case when that successor set is (A,) for rev A) that means there will be divergence and we warn the user. This works fine but there is still a case (which is not covered by looking at successor sets) which can lead to divergence. That case is: when there is already a revision exists which is divergent to the revision being touched. And performing the touch would revive that "dead" divergence. (Dead because one of the revision is obsolete which is the one we are touching) And to see if there is any rev which is divergent to a particular rev we already have a function which we can use here i.e. `evolvecmd.divergentsets(repo, ctx_being_touched)` Changes in test file demonstrate the fixed behaviour.
author Sushil khanchi <sushilkhanchi97@gmail.com>
date Wed, 17 Jul 2019 17:58:44 +0200
parents 355b8e17e14c
children 076b6813a7ea d0965c5c5335
files CHANGELOG hgext3rd/evolve/cmdrewrite.py tests/test-touch.t
diffstat 3 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGELOG	Sat Jun 29 14:28:35 2019 +0530
+++ b/CHANGELOG	Wed Jul 17 17:58:44 2019 +0200
@@ -8,6 +8,7 @@
   * pick: properly report and cleanup "unfinished state"
   * prune: don't update wcp if pruned revision are unrelated (issue6137)
   * evolve: properly prune changeset with no change in case of conflict (issue5967)
+  * touch: detect resulting divergence in more cases (issue6107)
 
 9.0.0 -- 2019-06-06
 -------------------
--- a/hgext3rd/evolve/cmdrewrite.py	Sat Jun 29 14:28:35 2019 +0530
+++ b/hgext3rd/evolve/cmdrewrite.py	Wed Jul 17 17:58:44 2019 +0200
@@ -1378,6 +1378,10 @@
         if not (duplicate or allowdivergence):
             # If reviving this cset creates divergence, let's ask user
             # what to do: create divergence or duplicate
+
+            # We need to check two cases that can cause divergence:
+            # case 1: the rev being revived has a non-obsolete successor (easily
+            #     detected by successorssets)
             sset = obsutil.successorssets(repo, ctx.node())
             nodivergencerisk = (len(sset) == 0
                                 or (len(sset) == 1
@@ -1385,6 +1389,12 @@
                                     and repo[sset[0][0]].rev() == ctx.rev()
                                 ))
             if nodivergencerisk:
+                # case 2: one of the precursors of the rev being revived has a
+                #     non-obsolete successor (we need divergentsets for this)
+                from . import evolvecmd
+                if evolvecmd.divergentsets(repo, ctx):
+                    nodivergencerisk = False
+            if nodivergencerisk:
                 duplicate = False
             else:
                 displayer.show(ctx)
--- a/tests/test-touch.t	Sat Jun 29 14:28:35 2019 +0530
+++ b/tests/test-touch.t	Wed Jul 17 17:58:44 2019 +0200
@@ -186,7 +186,9 @@
 
   $ hg touch -r "desc('added c')" --hidden
   $ hg touch -r "desc('modified c')" --hidden
+  [1] modified c
+  reviving this changeset will create divergence unless you make a duplicate.
+  (a)llow divergence or (d)uplicate the changeset?  a
   2 new content-divergent changesets
-XXX: it should warn for divergence here
 
   $ cd ..