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

timeless timeless at mozdev.org
Wed Dec 23 16:43:14 CST 2015


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1450906238 0
#      Wed Dec 23 21:30:38 2015 +0000
# Node ID feed536036eca034e461b48d83c0da40cd8e4d7a
# Parent  d7e9243f77436f6032d32c73692c0646602e549b
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,35 +218,61 @@
 # leave the attribute unspecified.
 testedwith = 'internal'
 
+actiontable = {}
+actionlist = []
+
 def geteditcomment(first, last):
     """ construct the editor comment
     The comment includes::
      - an intro
      - primary commands
      - sorted short commands
+     - sorted long commands
 
     Commands are only included once.
     Internal commands (those beginning with `_`) are omitted.
     """
-    intro = _("""# Edit history between %s and %s
-#
-# Commits are listed from least to most recent
-#
-# Commands:
-%s""")
-    verbs = (
-"p, pick = %s" % _("use commit"),
-"m, mess = %s" % _("edit commit message without changing commit content"),
-"e, edit = %s" % _("use commit, but stop for amending"),
+    intro = _("""Edit history between %s and %s
 
-"d, drop = %s" % _("remove commit from history"),
-"f, fold = %s" % _("use commit, but combine it with the one above"),
-"r, roll = %s" % _("like fold, but discard this commit's description"),
-"",
-)
-    verbs = ''.join(["#  %s\n" % l if l else '#\n' for l in verbs])
+Commits are listed from least to most recent
 
-    return intro % (first, last, verbs)
+Commands:""")
+    preferedkeys = (
+        'p',
+        'm',
+        'e',
+    )
+    diffkeys = set()
+    skipkeys = set()
+    samekeys = set()
+    for v, a in actiontable.iteritems():
+        if v == a.verb:
+            # skip internal actions
+            if v[0] != '_':
+                samekeys.add(v)
+        else:
+            diffkeys.add(v)
+            skipkeys.add(a.verb)
+    actions = []
+    def addverb(v):
+        a = actiontable[v]
+        lines = a.message.split("\n")
+        if v != a.verb:
+            v = '%s, %s' % (v, a.verb)
+        actions.append(" %s = %s" % (v, lines[0]))
+        actions.extend(['  %s' for l in lines[1:]])
+
+    for v in preferedkeys:
+        diffkeys.remove(v)
+        addverb(v)
+    for v in sorted(diffkeys):
+        addverb(v)
+    for v in sorted(samekeys - skipkeys):
+        addverb(v)
+    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,
@@ -599,13 +625,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