diff hgext/evolve.py @ 1589:d6630a6bff86

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] <description> 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.
author Laurent Charignon <lcharignon@fb.com>
date Sun, 17 Jan 2016 16:55:40 -0800
parents b915e0d54db0
children f157ef7b1741
line wrap: on
line diff
--- 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])