Commit d798dec2 authored by Sushil Khanchi's avatar Sushil Khanchi 🐨
Browse files

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).
parent a8ac174010a5
......@@ -77,6 +77,15 @@ def precheck(repo, revs, action=b'rewrite'):
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 @@ def bookmarksupdater(repo, oldid, tr):
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 @@ def rewrite(repo, old, updates, head, newbases, commitopts):
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 @@ def contentdivrisk(repo, ctx):
# 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
......@@ -121,6 +121,9 @@ Check that --logfile works
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 @@ Check that we abort if --patch and --extract both are used at once
$ 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]
......@@ -21,6 +21,8 @@ file for more advanced cases.
> 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
......
......@@ -21,6 +21,8 @@ other cases.
> 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
......
$ . $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.
......
......@@ -24,6 +24,8 @@ Setup
> 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
......
......@@ -12,6 +12,8 @@ Setup
> glog = log -GT "{rev}:{node|short} {desc|firstline}\n {phase} {instabilities}\n\n"
> [phases]
> publish = False
> [experimental]
> evolution.allowdivergence = True
> [extensions]
> rebase =
> strip =
......
......@@ -5,6 +5,10 @@ Global setup
============
$ . $TESTDIR/testlib/obshistory_setup.sh
$ cat >> $HGRCPATH << EOF
> [experimental]
> evolution.allowdivergence = True
> EOF
Test output with content-divergence
===================================
......
......@@ -15,6 +15,8 @@ evolve --rev reordering
> 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
......
......@@ -12,6 +12,8 @@ Setup
> glog = log -GT "{rev}:{node|short} {desc|firstline}\n {phase} {instabilities}\n\n"
> [phases]
> publish = False
> [experimental]
> evolution.allowdivergence = True
> [extensions]
> rebase =
> EOF
......
......@@ -17,6 +17,8 @@ Setup
> glog = log -GT "{rev}:{node|short} {desc|firstline}\n {phase} {instabilities}\n\n"
> [phases]
> publish = False
> [experimental]
> evolution.allowdivergence = True
> [extensions]
> rebase =
> EOF
......
......@@ -15,6 +15,8 @@ Setup
> glog = log -GT "{rev}:{node|short} {desc|firstline}\n {phase} {instabilities}\n\n"
> [phases]
> publish = False
> [experimental]
> evolution.allowdivergence = True
> [extensions]
> rebase =
> EOF
......
......@@ -9,6 +9,8 @@ Global setup
> interactive = true
> [phases]
> publish=False
> [experimental]
> evolution.allowdivergence = True
> [extensions]
> evolve =
> [alias]
......
......@@ -405,8 +405,8 @@ fold aborts here because divergence is not allowed
$ 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
......
......@@ -7,6 +7,7 @@ Setup
$ cat << EOF >> $HGRCPATH
> [experimental]
> evolution = all
> evolution.allowdivergence = True
> [ui]
> interactive = True
> [extensions]
......
......@@ -6,6 +6,8 @@
> amend=-d "0 0"
> [alias]
> glog = log -GT "{rev}: {desc}"
> [experimental]
> evolution.allowdivergence = True
> [extensions]
> hgext.rebase=
> EOF
......
$ cat >> $HGRCPATH <<EOF
> [experimental]
> evolution.allowdivergence = True
> [extensions]
> EOF
$ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment