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

evolve: extract logic of pre-checking divergence risk to its own function

Extracting the logic (which is used to check if rewriting an obsolete
revision will create divergence) to a function. This function will be used
in upcoming patches of pre-checking.

This is how we check if rewriting an obsolete revision will create
divergence. We need to check two cases:
If there is any
1)  non-obsolete successor.
      -> easily done by `obsutil.successorssets()`
2)  precursor with non-obsolete successor.
      -> using `evolvecmd.divergentsets()`
parent c5efcbbd0dc4
Pipeline #2060 passed with stage
in 4 minutes and 17 seconds
......@@ -26,7 +26,6 @@ from mercurial import (
merge,
node,
obsolete,
obsutil,
patch,
phases,
pycompat,
......@@ -56,6 +55,7 @@ commitopts = commands.commitopts
commitopts2 = commands.commitopts2
mergetoolopts = commands.mergetoolopts
stringio = util.stringio
contentdivrisk = rewriteutil.contentdivrisk
# option added by evolve
......@@ -1400,27 +1400,7 @@ def touchnodes(ui, repo, revs, displayer, **opts):
p2 = newmapping.get(p2, p2)
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
and len(sset[0]) == 1
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:
if contentdivrisk(repo, ctx):
displayer.show(ctx)
index = ui.promptchoice(
_(b"reviving this changeset will create divergence"
......@@ -1428,9 +1408,7 @@ def touchnodes(ui, repo, revs, displayer, **opts):
b" (d)uplicate the changeset? $$ &Allowdivergence $$ "
b"&Duplicate"), 0)
choice = [b'allowdivergence', b'duplicate'][index]
if choice == b'allowdivergence':
duplicate = False
else:
if choice == b'duplicate':
duplicate = True
updates = []
......
......@@ -21,6 +21,7 @@ from mercurial import (
lock as lockmod,
node,
obsolete,
obsutil,
phases,
revset,
util,
......@@ -254,3 +255,22 @@ def rewrite(repo, old, updates, head, newbases, commitopts):
return newid, created
finally:
lockmod.release(tr, lock, wlock)
def contentdivrisk(repo, ctx):
"""logic to check if rewriting an obsolete cset 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)
sset = obsutil.successorssets(repo, ctx.node())
nodivergencerisk = (len(sset) == 0
or (len(sset) == 1
and len(sset[0]) == 1
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
return not nodivergencerisk
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