[PATCH 3 of 3] histedit: replace @addhisteditaction with @action
timeless
timeless at mozdev.org
Tue Jan 5 12:31:53 CST 2016
# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1450906238 0
# Wed Dec 23 21:30:38 2015 +0000
# Node ID 5b616db6e64040d138152297bff3b62245167917
# Parent 0e22d25a49546b65a4eb53ef53f555634afdbef9
histedit: replace @addhisteditaction with @action
@action supports verbs, messages, priority, and internal
messages should be translated.
internal means the action should not be listed.
geteditcomment will construct the verbs list based on
@actions (prefering priority over non priority, otherwise
favoring verbs with short forms over verbs without).
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -214,12 +214,19 @@
# leave the attribute unspecified.
testedwith = 'internal'
+actiontable = {}
+primaryactions = set()
+secondaryactions = set()
+tertiaryactions = set()
+internalactions = set()
+
def geteditcomment(first, last):
""" construct the editor comment
The comment includes::
- an intro
- sorted primary commands
- sorted short commands
+ - sorted long commands
Commands are only included once.
"""
@@ -227,19 +234,27 @@
Commits are listed from least to most recent
-Commands:""")
- # i18n: command names and abbreviations must remain untranslated
- verbs = _("""
- e, edit = use commit, but stop for amending
- m, mess = edit commit message without changing commit content
- p, pick = use commit
- d, drop = remove commit from history
- f, fold = use commit, but combine it with the one above
- r, roll = like fold, but discard this commit's description
+Commands:
""")
+ actions = []
+ def addverb(v):
+ a = actiontable[v]
+ lines = a.message.split("\n")
+ if len(a.verbs):
+ v = ', '.join(sorted(a.verbs, key=lambda v: len(v)))
+ actions.append(" %s = %s" % (v, lines[0]))
+ actions.extend([' %s' for l in lines[1:]])
+
+ for v in (
+ sorted(primaryactions) +
+ sorted(secondaryactions) +
+ sorted(tertiaryactions)
+ ):
+ addverb(v)
+ actions.append('')
return ''.join(['# %s\n' % l if l else '#\n'
- for l in ((intro % (first, last) + verbs).split('\n'))])
+ for l in ((intro % (first, last)).split('\n')) + actions])
class histeditstate(object):
def __init__(self, repo, parentctxnode=None, actions=None, keep=None,
@@ -596,21 +611,30 @@
hint=_('amend, commit, or revert them and run histedit '
'--continue, or abort with histedit --abort'))
+def action(verbs, message, priority=False, internal=False):
+ def wrap(cls):
+ assert not priority or not internal
+ verb = verbs[0]
+ if priority:
+ primaryactions.add(verb)
+ elif internal:
+ internalactions.add(verb)
+ elif len(verbs) > 1:
+ secondaryactions.add(verb)
+ else:
+ tertiaryactions.add(verb)
-actiontable = {}
-actionlist = []
-
-def addhisteditaction(verbs):
- def wrap(cls):
- cls.verb = verbs[0]
+ cls.verb = verb
+ cls.verbs = verbs
+ cls.message = message
for verb in verbs:
actiontable[verb] = cls
- actionlist.append(cls)
return cls
return wrap
-
- at addhisteditaction(['pick', 'p'])
+ at action(['pick', 'p'],
+ _('use commit'),
+ priority=True)
class pick(histeditaction):
def run(self):
rulectx = self.repo[self.node]
@@ -620,7 +644,9 @@
return super(pick, self).run()
- at addhisteditaction(['edit', 'e'])
+ at action(['edit', 'e'],
+ _('use commit, but stop for amending'),
+ priority=True)
class edit(histeditaction):
def run(self):
repo = self.repo
@@ -635,7 +661,8 @@
def commiteditor(self):
return cmdutil.getcommiteditor(edit=True, editform='histedit.edit')
- at addhisteditaction(['fold', 'f'])
+ at action(['fold', 'f'],
+ _('use commit, but combine it with the one above'))
class fold(histeditaction):
def verify(self, prev):
""" Verifies semantic correctness of the fold rule"""
@@ -761,8 +788,8 @@
basectx = self.repo['.']
return basectx, []
- at addhisteditaction(['_multifold'])
-class _multifold(fold):
+ at action(['_multifold'],
+ _(
"""fold subclass used for when multiple folds happen in a row
We only want to fire the editor for the folded message once when
@@ -770,11 +797,14 @@
similar to rollup, but we should preserve both messages so that
when the last fold operation runs we can show the user all the
commit messages in their editor.
- """
+ """),
+ internal=True)
+class _multifold(fold):
def skipprompt(self):
return True
- at addhisteditaction(["roll", "r"])
+ at action(["roll", "r"],
+ _("like fold, but discard this commit's description"))
class rollup(fold):
def mergedescs(self):
return False
@@ -782,13 +812,16 @@
def skipprompt(self):
return True
- at addhisteditaction(["drop", "d"])
+ at action(["drop", "d"],
+ _('remove commit from history'))
class drop(histeditaction):
def run(self):
parentctx = self.repo[self.state.parentctxnode]
return parentctx, [(self.node, tuple())]
- at addhisteditaction(["mess", "m"])
+ at action(["mess", "m"],
+ _('edit commit message without changing commit content'),
+ priority=True)
class message(histeditaction):
def commiteditor(self):
return cmdutil.getcommiteditor(edit=True, editform='histedit.mess')
@@ -1470,4 +1503,6 @@
['histedit-state', False, True, _('histedit in progress'),
_("use 'hg histedit --continue' or 'hg histedit --abort'")])
if ui.configbool("experimental", "histeditng"):
- globals()['base'] = addhisteditaction(['base', 'b'])(base)
+ globals()['base'] = action(['base', 'b'],
+ _('checkout changeset and apply further changesets from there')
+ )(base)
More information about the Mercurial-devel
mailing list