[PATCH 3 of 3] histedit: add --edit-plan option to histedit
Mateusz Kwapich
mitrandir at fb.com
Mon Feb 23 13:38:25 CST 2015
# HG changeset patch
# User Mateusz Kwapich <mitrandir at fb.com>
# Date 1421958998 28800
# Thu Jan 22 12:36:38 2015 -0800
# Node ID 2f1ebc67307aa358e205616d83c5454213440722
# Parent 9ba9c4d96b6770a53012c02beaaf8a7975060478
histedit: add --edit-plan option to histedit
--edit-plan allows user to edit remaining histedit rules in the middle of
histedit process
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -503,6 +503,7 @@ actiontable = {'p': pick,
[('', 'commands', '',
_('Read history edits from the specified file.')),
('c', 'continue', False, _('continue an edit already in progress')),
+ ('', 'edit-plan', False, _('edit remaining actions list')),
('k', 'keep', False,
_("don't strip old nodes after edit is complete")),
('', 'abort', False, _('abort an edit in progress')),
@@ -552,6 +553,7 @@ def _histedit(ui, repo, state, *freeargs
# basic argument incompatibility processing
outg = opts.get('outgoing')
cont = opts.get('continue')
+ editplan = opts.get('edit_plan')
abort = opts.get('abort')
force = opts.get('force')
rules = opts.get('commands', '')
@@ -560,13 +562,18 @@ def _histedit(ui, repo, state, *freeargs
if force and not outg:
raise util.Abort(_('--force only allowed with --outgoing'))
if cont:
- if util.any((outg, abort, revs, freeargs, rules)):
+ if util.any((outg, abort, revs, freeargs, rules, editplan)):
raise util.Abort(_('no arguments allowed with --continue'))
goal = 'continue'
elif abort:
- if util.any((outg, revs, freeargs, rules)):
+ if util.any((outg, revs, freeargs, rules, editplan)):
raise util.Abort(_('no arguments allowed with --abort'))
goal = 'abort'
+ elif editplan:
+ if util.any((outg, revs, freeargs)):
+ raise util.Abort(_('only --commands argument allowed with'
+ '--edit-plan'))
+ goal = 'edit-plan'
else:
if os.path.exists(os.path.join(repo.path, 'histedit-state')):
raise util.Abort(_('history edit already in progress, try '
@@ -596,6 +603,25 @@ def _histedit(ui, repo, state, *freeargs
state = histeditstate(repo)
state.read()
state = bootstrapcontinue(ui, state, opts)
+ elif goal == 'edit-plan':
+ state = histeditstate(repo)
+ state.read()
+ if not rules:
+ comment = editcomment % (state.parentctx, node.short(state.topmost))
+ rules = ruleeditor(repo, ui, state.rules, comment)
+ else:
+ if rules == '-':
+ f = sys.stdin
+ else:
+ f = open(rules)
+ rules = f.read()
+ f.close()
+ rules = [l for l in (r.strip() for r in rules.splitlines())
+ if l and not l.startswith('#')]
+ rules = verifyrules(rules, repo, [repo[c] for [_a, c] in state.rules])
+ state.rules = rules
+ state.write()
+ return
elif goal == 'abort':
state = histeditstate(repo)
state.read()
@@ -638,9 +664,8 @@ def _histedit(ui, repo, state, *freeargs
ctxs = [repo[r] for r in revs]
if not rules:
- rules = ruleeditor(repo, ui, [['pick', c] for c in ctxs],
- editcomment=editcomment % (node.short(root),
- node.short(topmost)))
+ comment = editcomment % (node.short(root), node.short(topmost))
+ rules = ruleeditor(repo, ui, [['pick', c] for c in ctxs], comment)
else:
if rules == '-':
f = sys.stdin
diff --git a/tests/test-histedit-edit.t b/tests/test-histedit-edit.t
--- a/tests/test-histedit-edit.t
+++ b/tests/test-histedit-edit.t
@@ -9,7 +9,7 @@
> {
> hg init r
> cd r
- > for x in a b c d e f ; do
+ > for x in a b c d e f g; do
> echo $x > $x
> hg add $x
> hg ci -m $x
@@ -20,10 +20,15 @@
log before edit
$ hg log --graph
- @ changeset: 5:652413bf663e
+ @ changeset: 6:3c6a8ed2ebe8
| tag: tip
| user: test
| date: Thu Jan 01 00:00:00 1970 +0000
+ | summary: g
+ |
+ o changeset: 5:652413bf663e
+ | user: test
+ | date: Thu Jan 01 00:00:00 1970 +0000
| summary: f
|
o changeset: 4:e860deea161a
@@ -58,11 +63,19 @@ edit the history
> pick 055a42cdd887 d
> edit e860deea161a e
> pick 652413bf663e f
+ > pick 3c6a8ed2ebe8 g
> EOF
- 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+ 0 files updated, 0 files merged, 3 files removed, 0 files unresolved
Make changes as needed, you may commit or record as needed now.
When you are finished, run hg histedit --continue to resume.
+edit the plan
+ $ hg histedit --edit-plan --commands - 2>&1 << EOF
+ > edit e860deea161a e
+ > pick 652413bf663e f
+ > drop 3c6a8ed2ebe8 g
+ > EOF
+
Go at a random point and try to continue
$ hg id -n
More information about the Mercurial-devel
mailing list