Patchwork [1,of,3] histedit: replace editcomment with a function

login
register
mail settings
Submitter timeless@mozdev.org
Date Jan. 5, 2016, 6:31 p.m.
Message ID <2bd72406a9bfe89e5683.1452018711@waste.org>
Download mbox | patch
Permalink /patch/12538/
State Accepted
Headers show

Comments

timeless@mozdev.org - Jan. 5, 2016, 6:31 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1450905465 0
#      Wed Dec 23 21:17:45 2015 +0000
# Node ID 2bd72406a9bfe89e56832964fc9ffab5d1d6bf80
# Parent  b8405d739149cdd6d8d9bd5e3dd2ad8487b1f09a
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
@@ -214,21 +214,32 @@ 
 # leave the attribute unspecified.
 testedwith = 'internal'
 
-# i18n: command names and abbreviations must remain untranslated
-editcomment = _("""# Edit history between %s and %s
-#
-# Commits are listed from least to most recent
-#
-# Commands:
-#  p, pick = use commit
-#  e, edit = use commit, but stop for amending
-#  f, fold = use commit, but combine it with the one above
-#  r, roll = like fold, but discard this commit's description
-#  d, drop = remove commit from history
-#  m, mess = edit commit message without changing commit content
-#
+def geteditcomment(first, last):
+    """ construct the editor comment
+    The comment includes::
+     - an intro
+     - short commands
+
+    Commands are only included once.
+    """
+    intro = _("""Edit history between %s and %s
+
+Commits are listed from least to most recent
+
+Commands:""")
+    # i18n: command names and abbreviations must remain untranslated
+    verbs = _("""
+ p, pick = use commit
+ e, edit = use commit, but stop for amending
+ f, fold = use commit, but combine it with the one above
+ r, roll = like fold, but discard this commit's description
+ d, drop = remove commit from history
+ m, mess = edit commit message without changing commit content
 """)
 
+    return ''.join(['# %s\n' % l if l else '#\n'
+                    for l in ((intro % (first, last) + verbs).split('\n'))])
+
 class histeditstate(object):
     def __init__(self, repo, parentctxnode=None, actions=None, keep=None,
             topmost=None, replacements=None, lock=None, wlock=None):
@@ -972,7 +983,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:
@@ -1055,7 +1066,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: