# HG changeset patch # User Sushil khanchi # Date 1573044300 -19800 # Node ID f583d9eedbce6a8dde9f2deb246207fcd491abc0 # Parent c5efcbbd0dc46d82cf019c0aa3ca47838519ad70 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()` diff -r c5efcbbd0dc4 -r f583d9eedbce hgext3rd/evolve/cmdrewrite.py --- a/hgext3rd/evolve/cmdrewrite.py Thu Dec 26 21:23:30 2019 +0100 +++ b/hgext3rd/evolve/cmdrewrite.py Wed Nov 06 18:15:00 2019 +0530 @@ -26,7 +26,6 @@ merge, node, obsolete, - obsutil, patch, phases, pycompat, @@ -56,6 +55,7 @@ commitopts2 = commands.commitopts2 mergetoolopts = commands.mergetoolopts stringio = util.stringio +contentdivrisk = rewriteutil.contentdivrisk # option added by evolve @@ -1400,27 +1400,7 @@ 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 @@ 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 = [] diff -r c5efcbbd0dc4 -r f583d9eedbce hgext3rd/evolve/rewriteutil.py --- a/hgext3rd/evolve/rewriteutil.py Thu Dec 26 21:23:30 2019 +0100 +++ b/hgext3rd/evolve/rewriteutil.py Wed Nov 06 18:15:00 2019 +0530 @@ -21,6 +21,7 @@ lock as lockmod, node, obsolete, + obsutil, phases, revset, util, @@ -254,3 +255,22 @@ 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