Patchwork [3,of,4,V2] crecord: break out the help message for editing hunks

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date March 21, 2016, 1:09 a.m.
Message ID <bf07fd7c4934b85b2d0e.1458522580@Iris>
Download mbox | patch
Permalink /patch/14003/
State Accepted
Headers show

Comments

Jordi Gutiérrez Hermoso - March 21, 2016, 1:09 a.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1458512699 14400
#      Sun Mar 20 18:24:59 2016 -0400
# Node ID bf07fd7c4934b85b2d0e671ba02b6104431e0dda
# Parent  caefdf7d3b1a02476ed7c669857d9acb3b9c91fb
crecord: break out the help message for editing hunks

This help message can be useful for other situations, such as for the
review extension. It's also easier to write it at the top-level
indentation with triple-quoted strings instead of inserting comment
characters and newlines programmatically.

Patch

diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -31,6 +31,19 @@  from . import (
 # locale encoding correctly.  --immerrr
 locale.setlocale(locale.LC_ALL, '')
 
+# patch comments based on the git one
+diffhelptext = _("""# To remove '-' lines, make them ' ' lines (context).
+# To remove '+' lines, delete them.
+# Lines starting with # will be removed from the patch.
+""")
+
+hunkhelptext = _("""#
+# If the patch applies cleanly, the edited hunk will immediately be
+# added to the record list. If it does not apply cleanly, a rejects file
+# will be generated. You can use that when you try again. If all lines
+# of the hunk are removed, then the edit is aborted and the hunk is left
+# unchanged.
+""")
 try:
     import curses
     import fcntl
@@ -1502,22 +1515,10 @@  are you sure you want to review/edit and
                 self.ui.write(_('cannot edit patch for binary file'))
                 self.ui.write("\n")
                 return None
-            # patch comment based on the git one (based on comment at end of
-            # https://mercurial-scm.org/wiki/recordextension)
-            phelp = '---' + _("""
-    to remove '-' lines, make them ' ' lines (context).
-    to remove '+' lines, delete them.
-    lines starting with # will be removed from the patch.
 
-    if the patch applies cleanly, the edited hunk will immediately be
-    added to the record list. if it does not apply cleanly, a rejects
-    file will be generated: you can use that when you try again. if
-    all lines of the hunk are removed, then the edit is aborted and
-    the hunk is left unchanged.
-    """)
             # write the initial patch
             patch = cStringIO.StringIO()
-            patch.write(''.join(['# %s\n' % i for i in phelp.splitlines()]))
+            patch.write(diffhelptext + hunkhelptext)
             chunk.header.write(patch)
             chunk.write(patch)