comparison 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
comparison
equal deleted inserted replaced
1588:983f2e4dbe5d 1589:d6630a6bff86
2822 return cmdprune(ui, repo, *revs, **kwargs) 2822 return cmdprune(ui, repo, *revs, **kwargs)
2823 2823
2824 @command('^touch', 2824 @command('^touch',
2825 [('r', 'rev', [], 'revision to update'), 2825 [('r', 'rev', [], 'revision to update'),
2826 ('D', 'duplicate', False, 2826 ('D', 'duplicate', False,
2827 'do not mark the new revision as successor of the old one')], 2827 'do not mark the new revision as successor of the old one'),
2828 ('A', 'allowdivergence', False,
2829 'mark the new revision as successor of the old one potentially creating '
2830 'divergence')],
2828 # allow to choose the seed ? 2831 # allow to choose the seed ?
2829 _('[-r] revs')) 2832 _('[-r] revs'))
2830 def touch(ui, repo, *revs, **opts): 2833 def touch(ui, repo, *revs, **opts):
2831 """create successors that are identical to their predecessors except 2834 """create successors that are identical to their predecessors except
2832 for the changeset ID 2835 for the changeset ID
2833 2836
2834 This is used to "resurrect" changesets 2837 This is used to "resurrect" changesets
2835 """ 2838 """
2836 duplicate = opts['duplicate'] 2839 duplicate = opts['duplicate']
2840 allowdivergence = opts['allowdivergence']
2837 revs = list(revs) 2841 revs = list(revs)
2838 revs.extend(opts['rev']) 2842 revs.extend(opts['rev'])
2839 if not revs: 2843 if not revs:
2840 revs = ['.'] 2844 revs = ['.']
2841 revs = scmutil.revrange(repo, revs) 2845 revs = scmutil.revrange(repo, revs)
2842 if not revs: 2846 if not revs:
2843 ui.write_err('no revision to touch\n') 2847 ui.write_err('no revision to touch\n')
2844 return 1 2848 return 1
2845 if not duplicate and repo.revs('public() and %ld', revs): 2849 if not duplicate and repo.revs('public() and %ld', revs):
2846 raise error.Abort("can't touch public revision") 2850 raise error.Abort("can't touch public revision")
2851 displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
2847 wlock = lock = tr = None 2852 wlock = lock = tr = None
2848 try: 2853 try:
2849 wlock = repo.wlock() 2854 wlock = repo.wlock()
2850 lock = repo.lock() 2855 lock = repo.lock()
2851 tr = repo.transaction('touch') 2856 tr = repo.transaction('touch')
2858 # search for touched parent 2863 # search for touched parent
2859 p1 = ctx.p1().node() 2864 p1 = ctx.p1().node()
2860 p2 = ctx.p2().node() 2865 p2 = ctx.p2().node()
2861 p1 = newmapping.get(p1, p1) 2866 p1 = newmapping.get(p1, p1)
2862 p2 = newmapping.get(p2, p2) 2867 p2 = newmapping.get(p2, p2)
2868
2869 if not (duplicate or allowdivergence):
2870 # The user hasn't yet decided what to do with the revived
2871 # cset, let's ask
2872 sset = obsolete.successorssets(repo, ctx.node())
2873 nodivergencerisk = len(sset) == 0 or (
2874 len(sset) == 1 and
2875 len(sset[0]) == 1 and
2876 repo[sset[0][0]].rev() == ctx.rev()
2877 )
2878 if nodivergencerisk:
2879 duplicate = False
2880 else:
2881 displayer.show(ctx)
2882 index = ui.promptchoice(
2883 _("reviving this changeset will create divergence"
2884 " unless you make a duplicate.\n(a)llow divergence or"
2885 " (d)uplicate the changeset? $$ &Allowdivergence $$ "
2886 "&Duplicate"), 0)
2887 choice = ['allowdivergence', 'duplicate'][index]
2888 if choice == 'allowdivergence':
2889 duplicate = False
2890 else:
2891 duplicate = True
2892
2863 new, unusedvariable = rewrite(repo, ctx, [], ctx, 2893 new, unusedvariable = rewrite(repo, ctx, [], ctx,
2864 [p1, p2], 2894 [p1, p2],
2865 commitopts={'extra': extra}) 2895 commitopts={'extra': extra})
2866 # store touched version to help potential children 2896 # store touched version to help potential children
2867 newmapping[ctx.node()] = new 2897 newmapping[ctx.node()] = new
2898
2868 if not duplicate: 2899 if not duplicate:
2869 obsolete.createmarkers(repo, [(ctx, (repo[new],))]) 2900 obsolete.createmarkers(repo, [(ctx, (repo[new],))])
2870 phases.retractboundary(repo, tr, ctx.phase(), [new]) 2901 phases.retractboundary(repo, tr, ctx.phase(), [new])
2871 if ctx in repo[None].parents(): 2902 if ctx in repo[None].parents():
2872 repo.dirstate.beginparentchange() 2903 repo.dirstate.beginparentchange()