evolve: add pre-check logic for content-divergence in rewriteutil.precheck()
For now, pre-check will abort if rewriting a rev create divergence (and
config experimental.evolution.allowdivergence is not set to True).
But this behaviour can be improved where instead of abort maybe we
can confirm the user to either proceed with divergence or some other
options depends on what command user is running.
Changes in test file are used to overrides the pre-check for testing
purpose (using experimental.evolution.allowdivergence=yes).
--- a/hgext3rd/evolve/rewriteutil.py Fri Dec 20 14:08:37 2019 +0700
+++ b/hgext3rd/evolve/rewriteutil.py Mon Nov 04 01:30:50 2019 +0530
@@ -77,6 +77,15 @@
msg %= (action, len(newunstable))
hint = _(b"see 'hg help evolution.instability'")
raise error.Abort(msg, hint=hint)
+ divrisk = revs_hascontentdivrisk(repo, revs)
+ allowdivergence = repo.ui.configbool(b'experimental',
+ b'evolution.allowdivergence')
+ if divrisk and not allowdivergence:
+ msg = _(b"revision being rewritten or one of its precursor was "
+ b"rewritten as %s, performing '%s' will create "
+ b"content-divergence") % (repo[divrisk[0]], action)
+ hint = _(b"For more, see 'hg help evolution.instability'")
+ raise error.Abort(msg, hint=hint)
def bookmarksupdater(repo, oldid, tr):
"""Return a callable update(newid) updating the current bookmark
@@ -89,6 +98,14 @@
repo._bookmarks.applychanges(repo, tr, bmchanges)
return updatebookmarks
+def revs_hascontentdivrisk(repo, revs):
+ obsrevs = repo.revs(b'%ld and obsolete()', revs)
+ for r in obsrevs:
+ div = contentdivrisk(repo, repo[r])
+ if div:
+ return div
+ return []
+
def disallowednewunstable(repo, revs):
"""Check that editing <revs> will not create disallowed unstable
@@ -257,10 +274,12 @@
lockmod.release(tr, lock, wlock)
def contentdivrisk(repo, ctx):
- """logic to check if rewriting an obsolete cset will create divergence"""
+ """return divergent revision if rewriting an obsolete cset (ctx) will
+ create divergence"""
# We need to check two cases that can cause divergence:
# case 1: the rev being rewritten has a non-obsolete successor (easily
# detected by successorssets)
+ divergent = []
sset = obsutil.successorssets(repo, ctx.node())
nodivergencerisk = (len(sset) == 0
or (len(sset) == 1
@@ -271,6 +290,10 @@
# 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
- return not nodivergencerisk
+ divsets = evolvecmd.divergentsets(repo, ctx)
+ if divsets:
+ nsuccset = divsets[0][b'divergentnodes']
+ divergent.append(nsuccset[0][0])
+ else:
+ divergent.append(sset[0][0])
+ return divergent
--- a/tests/test-amend.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-amend.t Mon Nov 04 01:30:50 2019 +0530
@@ -121,6 +121,9 @@
update: (current)
phases: 3 draft
+setting the user after we have performed the test with no username
+ $ HGUSER=test
+
Check the help
$ hg amend -h
hg amend [OPTION]... [FILE]...
@@ -170,3 +173,22 @@
$ hg amend --patch --extract
abort: cannot use both --patch and --extract
[255]
+
+ $ cd ..
+
+Check the pre-check logic
+ $ hg init precheckrepo
+ $ cd precheckrepo
+ $ echo a > a
+ $ hg ci -Am "added a"
+ adding a
+ $ echo newchanges > a
+ $ hg amend
+ $ hg up 0 --hidden -q
+ updated to hidden changeset 9092f1db7931
+ (hidden revision '9092f1db7931' was rewritten as: aafaf407b00d)
+ working directory parent is obsolete! (9092f1db7931)
+ $ hg amend -m "i am gonna create divergence"
+ abort: revision being rewritten or one of its precursor was rewritten as aafaf407b00d, performing 'amend' will create content-divergence
+ (For more, see 'hg help evolution.instability')
+ [255]
--- a/tests/test-evolve-content-divergent-basic.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-evolve-content-divergent-basic.t Mon Nov 04 01:30:50 2019 +0530
@@ -21,6 +21,8 @@
> unified = 0
> [ui]
> logtemplate = {rev}:{node|short}@{branch}({phase}) {desc|firstline} [{instabilities}]\n
+ > [experimental]
+ > evolution.allowdivergence = True
> [extensions]
> EOF
$ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH
--- a/tests/test-evolve-content-divergent-corner-cases.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-evolve-content-divergent-corner-cases.t Mon Nov 04 01:30:50 2019 +0530
@@ -21,6 +21,8 @@
> unified = 0
> [ui]
> logtemplate = {rev}:{node|short}@{branch}({phase}) {desc|firstline} [{instabilities}]\n
+ > [experimental]
+ > evolution.allowdivergence = True
> [extensions]
> EOF
$ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH
--- a/tests/test-evolve-content-divergent-first-changeset.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-evolve-content-divergent-first-changeset.t Mon Nov 04 01:30:50 2019 +0530
@@ -1,6 +1,11 @@
$ . $TESTDIR/testlib/pythonpath.sh
- $ echo "[extensions]" >> $HGRCPATH
- $ echo "evolve=" >> $HGRCPATH
+ $ cat >> $HGRCPATH << EOF
+ > [extensions]
+ > evolve=
+ > [experimental]
+ > evolution.allowdivergence = True
+ > EOF
+
This test file tests the case of content-divergence resolution of changesets
that have the null revision as the parent.
--- a/tests/test-evolve-content-divergent-interrupted.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-evolve-content-divergent-interrupted.t Mon Nov 04 01:30:50 2019 +0530
@@ -24,6 +24,8 @@
> publish = False
> [alias]
> glog = log -GT "{rev}:{node|short} {desc}\n ({bookmarks}) {phase}"
+ > [experimental]
+ > evolution.allowdivergence = True
> [extensions]
> EOF
$ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH
--- a/tests/test-evolve-content-divergent-meta.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-evolve-content-divergent-meta.t Mon Nov 04 01:30:50 2019 +0530
@@ -12,6 +12,8 @@
> glog = log -GT "{rev}:{node|short} {desc|firstline}\n {phase} {instabilities}\n\n"
> [phases]
> publish = False
+ > [experimental]
+ > evolution.allowdivergence = True
> [extensions]
> rebase =
> strip =
--- a/tests/test-evolve-obshistory-content-divergent.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-evolve-obshistory-content-divergent.t Mon Nov 04 01:30:50 2019 +0530
@@ -5,6 +5,10 @@
============
$ . $TESTDIR/testlib/obshistory_setup.sh
+ $ cat >> $HGRCPATH << EOF
+ > [experimental]
+ > evolution.allowdivergence = True
+ > EOF
Test output with content-divergence
===================================
--- a/tests/test-evolve-order.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-evolve-order.t Mon Nov 04 01:30:50 2019 +0530
@@ -15,6 +15,8 @@
> unified = 0
> [ui]
> logtemplate = {rev}:{node|short}@{branch}({phase}) {desc|firstline}\n
+ > [experimental]
+ > evolution.allowdivergence = True
> [extensions]
> EOF
$ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH
--- a/tests/test-evolve-public-content-divergent-corner-cases.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-evolve-public-content-divergent-corner-cases.t Mon Nov 04 01:30:50 2019 +0530
@@ -12,6 +12,8 @@
> glog = log -GT "{rev}:{node|short} {desc|firstline}\n {phase} {instabilities}\n\n"
> [phases]
> publish = False
+ > [experimental]
+ > evolution.allowdivergence = True
> [extensions]
> rebase =
> EOF
--- a/tests/test-evolve-public-content-divergent-discard.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-evolve-public-content-divergent-discard.t Mon Nov 04 01:30:50 2019 +0530
@@ -17,6 +17,8 @@
> glog = log -GT "{rev}:{node|short} {desc|firstline}\n {phase} {instabilities}\n\n"
> [phases]
> publish = False
+ > [experimental]
+ > evolution.allowdivergence = True
> [extensions]
> rebase =
> EOF
--- a/tests/test-evolve-public-content-divergent-main.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-evolve-public-content-divergent-main.t Mon Nov 04 01:30:50 2019 +0530
@@ -15,6 +15,8 @@
> glog = log -GT "{rev}:{node|short} {desc|firstline}\n {phase} {instabilities}\n\n"
> [phases]
> publish = False
+ > [experimental]
+ > evolution.allowdivergence = True
> [extensions]
> rebase =
> EOF
--- a/tests/test-evolve-templates.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-evolve-templates.t Mon Nov 04 01:30:50 2019 +0530
@@ -9,6 +9,8 @@
> interactive = true
> [phases]
> publish=False
+ > [experimental]
+ > evolution.allowdivergence = True
> [extensions]
> evolve =
> [alias]
--- a/tests/test-fold.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-fold.t Mon Nov 04 01:30:50 2019 +0530
@@ -405,8 +405,8 @@
$ hg fold --exact -r 'desc("A")::desc("B")' -m 'second fold' \
> --config experimental.evolution.allowdivergence=no
- abort: folding obsolete revisions may cause divergence
- (set experimental.evolution.allowdivergence=yes to allow folding them)
+ abort: revision being rewritten or one of its precursor was rewritten as fcfd42a7fa46, performing 'fold' will create content-divergence
+ (For more, see 'hg help evolution.instability')
[255]
but if we allow divergence, this should work and should create new content-divergent changesets
--- a/tests/test-topic-stack-complex.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-topic-stack-complex.t Mon Nov 04 01:30:50 2019 +0530
@@ -7,6 +7,7 @@
$ cat << EOF >> $HGRCPATH
> [experimental]
> evolution = all
+ > evolution.allowdivergence = True
> [ui]
> interactive = True
> [extensions]
--- a/tests/test-touch.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-touch.t Mon Nov 04 01:30:50 2019 +0530
@@ -6,6 +6,8 @@
> amend=-d "0 0"
> [alias]
> glog = log -GT "{rev}: {desc}"
+ > [experimental]
+ > evolution.allowdivergence = True
> [extensions]
> hgext.rebase=
> EOF
--- a/tests/test-uncommit.t Fri Dec 20 14:08:37 2019 +0700
+++ b/tests/test-uncommit.t Mon Nov 04 01:30:50 2019 +0530
@@ -1,4 +1,6 @@
$ cat >> $HGRCPATH <<EOF
+ > [experimental]
+ > evolution.allowdivergence = True
> [extensions]
> EOF
$ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH