# HG changeset patch # User Laurent Charignon # Date 1453078540 28800 # Node ID d6630a6bff8688dc950275c9d1edfb15f6fcd9ce # Parent 983f2e4dbe5d4d97d6ca82f6679913d75c1f2577 touch: prompt the user for what to do with the revived changeset This patch improves our interface for reviving changesets. This patch makes touch not assume that the user wants to create divergence by default and gives a prompt instead. The prompt is skipped for changeset that have no living successor as no divergence would be created by reviving them anyway. To restore the previous behavior, one should now use the --allowdivergence flag. The prompt looks like: [10] reviving this changeset will create divergence unless you make a duplicate. (a)llow divergence or (d)uplicate the changeset? a In further patches we will want to add one more choice to that prompt, for example having a marker between the old and revived nodes but no divergence displayed on the UI. diff -r 983f2e4dbe5d -r d6630a6bff86 hgext/evolve.py --- a/hgext/evolve.py Wed Jan 27 13:57:08 2016 -0800 +++ b/hgext/evolve.py Sun Jan 17 16:55:40 2016 -0800 @@ -2824,7 +2824,10 @@ @command('^touch', [('r', 'rev', [], 'revision to update'), ('D', 'duplicate', False, - 'do not mark the new revision as successor of the old one')], + 'do not mark the new revision as successor of the old one'), + ('A', 'allowdivergence', False, + 'mark the new revision as successor of the old one potentially creating ' + 'divergence')], # allow to choose the seed ? _('[-r] revs')) def touch(ui, repo, *revs, **opts): @@ -2834,6 +2837,7 @@ This is used to "resurrect" changesets """ duplicate = opts['duplicate'] + allowdivergence = opts['allowdivergence'] revs = list(revs) revs.extend(opts['rev']) if not revs: @@ -2844,6 +2848,7 @@ return 1 if not duplicate and repo.revs('public() and %ld', revs): raise error.Abort("can't touch public revision") + displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate}) wlock = lock = tr = None try: wlock = repo.wlock() @@ -2860,11 +2865,37 @@ p2 = ctx.p2().node() p1 = newmapping.get(p1, p1) p2 = newmapping.get(p2, p2) + + if not (duplicate or allowdivergence): + # The user hasn't yet decided what to do with the revived + # cset, let's ask + sset = obsolete.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: + duplicate = False + else: + displayer.show(ctx) + index = ui.promptchoice( + _("reviving this changeset will create divergence" + " unless you make a duplicate.\n(a)llow divergence or" + " (d)uplicate the changeset? $$ &Allowdivergence $$ " + "&Duplicate"), 0) + choice = ['allowdivergence', 'duplicate'][index] + if choice == 'allowdivergence': + duplicate = False + else: + duplicate = True + new, unusedvariable = rewrite(repo, ctx, [], ctx, [p1, p2], commitopts={'extra': extra}) # store touched version to help potential children newmapping[ctx.node()] = new + if not duplicate: obsolete.createmarkers(repo, [(ctx, (repo[new],))]) phases.retractboundary(repo, tr, ctx.phase(), [new]) diff -r 983f2e4dbe5d -r d6630a6bff86 tests/test-touch.t --- a/tests/test-touch.t Wed Jan 27 13:57:08 2016 -0800 +++ b/tests/test-touch.t Sun Jan 17 16:55:40 2016 -0800 @@ -41,6 +41,9 @@ @ 1:[0-9a-f]{12} a (re) $ hg touch . + [1] a + reviving this changeset will create divergence unless you make a duplicate. + (a)llow divergence or (d)uplicate the changeset? a 2 new divergent changesets $ hg log -G @ 4:[0-9a-f]{12} a (re) @@ -110,3 +113,15 @@ A gna2 gna1 R gna1 + +check that the --duplicate option does not create divergence + + $ hg touch --duplicate 11 --hidden + 1 new unstable changesets + +check that reviving a changeset with no successor does not show the prompt + + $ hg prune 14 + 1 changesets pruned + $ hg touch 14 --hidden + 1 new unstable changesets