@@ -153,10 +153,11 @@
try:
import cPickle as pickle
pickle.dump # import now
except ImportError:
import pickle
+import itertools
import os
import sys
from mercurial import cmdutil
from mercurial import discovery
@@ -517,10 +518,13 @@
_("don't strip old nodes after edit is complete")),
('', 'abort', False, _('abort an edit in progress')),
('o', 'outgoing', False, _('changesets not found in destination')),
('f', 'force', False,
_('force outgoing even for unrelated repositories')),
+ ('x', 'exec', '',
+ _('append an exec line after each commit in the list containing CMD'),
+ _('CMD')),
('r', 'rev', [], _('first revision to be edited'))],
_("ANCESTOR | --outgoing [URL]"))
def histedit(ui, repo, *freeargs, **opts):
"""interactively edit changeset history
@@ -562,10 +566,11 @@
# basic argument incompatibility processing
outg = opts.get('outgoing')
cont = opts.get('continue')
abort = opts.get('abort')
force = opts.get('force')
+ execute_ = opts.get('exec')
rules = opts.get('commands', '')
revs = opts.get('rev', [])
goal = 'new' # This invocation goal, in new, continue, abort
if force and not outg:
raise util.Abort(_('--force only allowed with --outgoing'))
@@ -575,10 +580,12 @@
goal = 'continue'
elif abort:
if util.any((outg, revs, freeargs, rules)):
raise util.Abort(_('no arguments allowed with --abort'))
goal = 'abort'
+ elif execute_ and util.any((outg, cont, abort, force, rules)):
+ raise util.Abort(_('no arguments except --rev allowed with --exec'))
else:
if os.path.exists(os.path.join(repo.path, 'histedit-state')):
raise util.Abort(_('history edit already in progress, try '
'--continue or --abort'))
if outg:
@@ -636,11 +643,15 @@
raise util.Abort(_('%s is not an ancestor of working directory') %
node.short(root))
ctxs = [repo[r] for r in revs]
if not rules:
- rules = '\n'.join([makedesc(c) for c in ctxs])
+ nodes = [makedesc(c) for c in ctxs]
+ if execute_:
+ execline = "%s %s" % ('exec', execute_)
+ nodes = itertools.chain(*zip(nodes,[execline] * len(nodes)))
+ rules = '\n'.join(nodes)
rules += '\n\n'
rules += editcomment % (node.short(root), node.short(topmost))
rules = ui.edit(rules, ui.username())
# Save edit rules in .hg/histedit-last-edit.txt in case
# the user needs to ask for help after something
@@ -286,5 +286,46 @@
o changeset: 0:cb9a9f314b8b
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: a
+test exec flag:
+ $ HGEDITOR=cat hg histedit cb9a9f314b8b --exec "exit 0"
+ pick cb9a9f314b8b 0 a
+ exec exit 0
+ pick d2ae7f538514 1 b
+ exec exit 0
+ pick 177f92b77385 2 c
+ exec exit 0
+ pick 055a42cdd887 3 d
+ exec exit 0
+ pick e860deea161a 4 e
+ exec exit 0
+ pick caf70cdd2c86 5 g
+ exec exit 0
+ pick c009deb54b16 6 foo
+ exec exit 0
+ pick 5652d6d85ba5 7 f
+ exec exit 0
+
+ # Edit history between cb9a9f314b8b and 5652d6d85ba5
+ #
+ # Commits are listed from least to most recent
+ #
+ # Commands:
+ # p, pick = use commit
+ # e, edit = use commit, but stop for amending
+ # f, fold = use commit, but combine it with the one above
+ # d, drop = remove commit from history
+ # m, mess = edit message without changing commit content
+ # x, exec = execute the given command
+ #
+ 0 files updated, 0 files merged, 6 files removed, 0 files unresolved
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+