[PATCH 5 of 5] histedit: switch editcomment to use actionlist

timeless timeless at mozdev.org
Wed Dec 23 03:10:03 CST 2015


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1450855004 0
#      Wed Dec 23 07:16:44 2015 +0000
# Node ID 4bcfcb7278b50896e5386701dca8871b2a45ab55
# Parent  eb5f4e0a1fe3638a73475d1383ec8f67a3f55152
histedit: switch editcomment to use actionlist

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -218,25 +218,39 @@
 # leave the attribute unspecified.
 testedwith = 'internal'
 
+actiontable = {}
+actionlist = []
+
 def editcomment(first, last):
-    preamble = _("""# Edit history between %s and %s
-#
-# Commits are listed from least to most recent
-#
-# Commands:
-%s""")
-    verbs = (
-"d, drop = %s" % _("remove commit from history"),
-"e, edit = %s" % _("use commit, but stop for amending"),
-"f, fold = %s" % _("use commit, but combine it with the one above"),
-"m, mess = %s" % _("edit commit message without changing commit content"),
-"p, pick = %s" % _("use commit"),
-"r, roll = %s" % _("like fold, but discard this commit's description"),
-"",
-)
-    verbs = ''.join(["#  %s\n" % l if l else '#\n' for l in verbs])
+    intro = _("""Edit history between %s and %s
 
-    return preamble % (first, last, verbs)
+Commits are listed from least to most recent
+
+Commands:""")
+    diffkeys = set()
+    skipkeys = set()
+    samekeys = set()
+    for l, a in actiontable.iteritems():
+        if l == a.verb:
+            # skip internal actions
+            if l[0] != '_':
+                samekeys.add(l)
+        else:
+            diffkeys.add(l)
+            skipkeys.add(a.verb)
+    actions = []
+    for l in sorted(diffkeys):
+        lines = actiontable[l].message.split("\n")
+        actions.append(" %s, %s = %s" % (l, actiontable[l].verb, lines[0]))
+        actions.extend(['  %s' for l in lines[1:]])
+    for l in sorted(samekeys - skipkeys):
+        lines = actiontable[l].message.split("\n")
+        actions.append(" %s = %s" % (l, lines[0]))
+        actions.extend(['  %s' for l in lines[1:]])
+    actions.append('')
+
+    return ''.join(['# %s\n' % l if l else '#\n'
+                    for l in ((intro % (first, last)).split('\n')) + actions])
 
 class histeditstate(object):
     def __init__(self, repo, parentctxnode=None, actions=None, keep=None,
@@ -589,13 +603,10 @@
         hint=_('amend, commit, or revert them and run histedit '
             '--continue, or abort with histedit --abort'))
 
-
-actiontable = {}
-actionlist = []
-
 def addhisteditaction(verbs):
     def wrap(cls):
         cls.verb = verbs[0]
+        cls.message = _(cls.__doc__) or _('(unknown action)')
         for verb in verbs:
             actiontable[verb] = cls
         actionlist.append(cls)


More information about the Mercurial-devel mailing list