Mercurial > public > mercurial-scm > hg-stable
diff hgext/histedit.py @ 22152:d2a5986cb89d
histedit: add "roll" command to fold commit data and drop message (issue4256)
This new histedit command (short for "rollup") is a variant of "fold" akin to
"hg amend" for working copy: it accumulates changes without interrupting
the user and asking for an updated commit message.
author | Mike Edgar <adgar@google.com> |
---|---|
date | Wed, 06 Aug 2014 16:51:41 -0400 |
parents | d5cef58d8ec8 |
children | 3ddfb9b3fdc6 |
line wrap: on
line diff
--- a/hgext/histedit.py Tue Aug 12 09:39:14 2014 -0700 +++ b/hgext/histedit.py Wed Aug 06 16:51:41 2014 -0400 @@ -36,6 +36,7 @@ # p, pick = use commit # e, edit = use commit, but stop for amending # f, fold = use commit, but combine it with the one above + # r, roll = like fold, but discard this commit's description # d, drop = remove commit from history # m, mess = edit message without changing commit content # @@ -57,6 +58,7 @@ # p, pick = use commit # e, edit = use commit, but stop for amending # f, fold = use commit, but combine it with the one above + # r, roll = like fold, but discard this commit's description # d, drop = remove commit from history # m, mess = edit message without changing commit content # @@ -179,6 +181,7 @@ # p, pick = use commit # e, edit = use commit, but stop for amending # f, fold = use commit, but combine it with the one above +# r, roll = like fold, but discard this commit's description # d, drop = remove commit from history # m, mess = edit message without changing commit content # @@ -291,7 +294,9 @@ extra = commitopts.get('extra') parents = (first.p1().node(), first.p2().node()) - editor = cmdutil.getcommiteditor(edit=True, editform='histedit.fold') + editor = None + if not commitopts.get('rollup'): + editor = cmdutil.getcommiteditor(edit=True, editform='histedit.fold') new = context.memctx(repo, parents=parents, text=message, @@ -333,6 +338,11 @@ _('Make changes as needed, you may commit or record as needed now.\n' 'When you are finished, run hg histedit --continue to resume.')) +def rollup(ui, repo, ctx, ha, opts): + rollupopts = opts.copy() + rollupopts['rollup'] = True + return fold(ui, repo, ctx, ha, rollupopts) + def fold(ui, repo, ctx, ha, opts): oldctx = repo[ha] hg.update(repo, ctx.node()) @@ -360,10 +370,13 @@ username = ui.username() commitopts['user'] = username # commit message - newmessage = '\n***\n'.join( - [ctx.description()] + - [repo[r].description() for r in internalchanges] + - [oldctx.description()]) + '\n' + if opts.get('rollup'): + newmessage = ctx.description() + else: + newmessage = '\n***\n'.join( + [ctx.description()] + + [repo[r].description() for r in internalchanges] + + [oldctx.description()]) + '\n' commitopts['message'] = newmessage # date commitopts['date'] = max(ctx.date(), oldctx.date()) @@ -444,6 +457,8 @@ 'edit': edit, 'f': fold, 'fold': fold, + 'r': rollup, + 'roll': rollup, 'd': drop, 'drop': drop, 'm': message, @@ -679,7 +694,7 @@ m, a, r, d = repo.status()[:4] if m or a or r or d: # prepare the message for the commit to comes - if action in ('f', 'fold'): + if action in ('f', 'fold', 'r', 'roll'): message = 'fold-temp-revision %s' % currentnode else: message = ctx.description() @@ -702,15 +717,19 @@ # to parent. replacements.append((ctx.node(), tuple(newchildren))) - if action in ('f', 'fold'): + if action in ('f', 'fold', 'r', 'roll'): if newchildren: # finalize fold operation if applicable if new is None: new = newchildren[-1] else: newchildren.pop() # remove new from internal changes - parentctx, repl = finishfold(ui, repo, parentctx, ctx, new, opts, - newchildren) + foldopts = opts + if action in ('r', 'roll'): + foldopts = foldopts.copy() + foldopts['rollup'] = True + parentctx, repl = finishfold(ui, repo, parentctx, ctx, new, + foldopts, newchildren) replacements.extend(repl) else: # newchildren is empty if the fold did not result in any commit