Patchwork [2,of,5,v2] histedit: replace editcomment with a function

login
register
mail settings
Submitter timeless@mozdev.org
Date Dec. 23, 2015, 10:43 p.m.
Message ID <0de3e8717757ed1d7809.1450910591@waste.org>
Download mbox | patch
Permalink /patch/12331/
State Superseded
Commit d93d340dc6ee64e621eb9c01d28e57a5feea5a2f
Delegated to: Augie Fackler
Headers show

Comments

timeless@mozdev.org - Dec. 23, 2015, 10:43 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1450905465 0
#      Wed Dec 23 21:17:45 2015 +0000
# Node ID 0de3e8717757ed1d7809dce4a03111602095674e
# Parent  84a11cb9e89d231f298ec87cad2c3e5b963aec28
histedit: replace editcomment with a function

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -218,13 +218,22 @@ 
 # leave the attribute unspecified.
 testedwith = 'internal'
 
-editcomment = _("""# Edit history between %s and %s
+def geteditcomment(first, last):
+    """ construct the editor comment
+    The comment includes::
+     - an intro
+     - short 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""") % ("%s", "%s",
-''.join(["#  %s\n" % l for l in (
+%s""")
+    verbs = (
 "p, pick = %s" % _("use commit"),
 "e, edit = %s" % _("use commit, but stop for amending"),
 "f, fold = %s" % _("use commit, but combine it with the one above"),
@@ -232,8 +241,10 @@ 
 "d, drop = %s" % _("remove commit from history"),
 "m, mess = %s" % _("edit commit message without changing commit content"),
 "",
-)])
 )
+    verbs = ''.join(["#  %s\n" % l for l in verbs])
+
+    return intro % (first, last, verbs)
 
 class histeditstate(object):
     def __init__(self, repo, parentctxnode=None, actions=None, keep=None,
@@ -964,7 +975,7 @@ 
     elif goal == 'edit-plan':
         state.read()
         if not rules:
-            comment = editcomment % (node.short(state.parentctxnode),
+            comment = geteditcomment(node.short(state.parentctxnode),
                                      node.short(state.topmost))
             rules = ruleeditor(repo, ui, state.actions, comment)
         else:
@@ -1049,7 +1060,7 @@ 
 
         ctxs = [repo[r] for r in revs]
         if not rules:
-            comment = editcomment % (node.short(root), node.short(topmost))
+            comment = geteditcomment(node.short(root), node.short(topmost))
             actions = [pick(state, r) for r in revs]
             rules = ruleeditor(repo, ui, actions, comment)
         else: