[PATCH 6 of 6] histedit: move autoverb rule to the commit it matches
Sean Farley
sean at farley.io
Tue Jun 21 19:32:46 EDT 2016
# HG changeset patch
# User Sean Farley <sean at farley.io>
# Date 1466546329 25200
# Tue Jun 21 14:58:49 2016 -0700
# Node ID da7ee04f9d62e23cc27fe9537b0a4d47aa03da8b
# Parent 6459e0be7633c075e61017f2eab9f41a3d21f5e8
# EXP-Topic autoverb
histedit: move autoverb rule to the commit it matches
Similar to how git rebase -i works, we move the autoverb to the commit line
summary that it matches.
Tests have been updated.
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1314,19 +1314,42 @@ def ruleeditor(repo, ui, actions, editco
"""open an editor to edit rules
rules are in the format [ [act, ctx], ...] like in state.rules
"""
if repo.ui.configbool("experimental", "histedit.autoverb"):
+ newact = util.sortdict()
for act in actions:
ctx = repo[act.node]
summary = _getsummary(ctx)
fword = summary.split(' ', 1)[0].lower()
+ added = False
+
# if it doesn't end with the special character '!' just skip this
if fword.endswith('!'):
fword = fword[:-1]
if fword in primaryactions | secondaryactions | tertiaryactions:
act.verb = fword
+ # get the target summary
+ tsum = summary[len(fword) + 1:].lstrip()
+ # safe but slow: reverse iterate over the actions so we
+ # don't clash on two commits having the same summary
+ for na, l in reversed(list(newact.iteritems())):
+ actx = repo[na.node]
+ asum = _getsummary(actx)
+ if asum == tsum:
+ added = True
+ l.append(act)
+ break
+
+ if not added:
+ newact[act] = []
+
+ # copy over and flatten the new list
+ actions = []
+ for na, l in newact.iteritems():
+ actions.append(na)
+ actions += l
rules = '\n'.join([act.torule() for act in actions])
rules += '\n\n'
rules += editcomment
rules = ui.edit(rules, ui.username(), {'prefix': 'histedit'})
diff --git a/tests/test-histedit-arguments.t b/tests/test-histedit-arguments.t
--- a/tests/test-histedit-arguments.t
+++ b/tests/test-histedit-arguments.t
@@ -505,36 +505,35 @@ amend should not be blocked by the ongoi
Test autoverb feature
$ hg init autoverb
$ cd autoverb
$ echo alpha >> alpha
- $ hg addr
- adding alpha
- $ hg ci -m one
+ $ hg ci -qAm one
$ echo alpha >> alpha
- $ hg ci -m two
- $ echo alpha >> alpha
- $ hg ci -m "roll! three"
+ $ hg ci -qm two
+ $ echo beta >> beta
+ $ hg ci -qAm "roll! one"
$ hg log --style compact --graph
- @ 2[tip] 1b0b0b04c8fe 1970-01-01 00:00 +0000 test
- | roll! three
+ @ 2[tip] 4f34d0f8b5fa 1970-01-01 00:00 +0000 test
+ | roll! one
|
o 1 579e40513370 1970-01-01 00:00 +0000 test
| two
|
o 0 6058cbb6cfd7 1970-01-01 00:00 +0000 test
one
Check that 'roll' is selected by default
- $ HGEDITOR=cat hg histedit 1 --config experimental.histedit.autoverb=True
+ $ HGEDITOR=cat hg histedit 0 --config experimental.histedit.autoverb=True
+ pick 6058cbb6cfd7 0 one
+ roll 4f34d0f8b5fa 2 roll! one
pick 579e40513370 1 two
- roll 1b0b0b04c8fe 2 roll! three
- # Edit history between 579e40513370 and 1b0b0b04c8fe
+ # Edit history between 6058cbb6cfd7 and 4f34d0f8b5fa
#
# Commits are listed from least to most recent
#
# You can reorder changesets by reordering the lines
#
More information about the Mercurial-devel
mailing list