changeset 26426:0486c16ce621

cmdutil: handle multiline translations of HG: messages safely Before this, if a localizer/localization included a multiline message, and didn't prefix the intermediate lines with 'HG: ', then the line would be a candidate for inclusion in the commit message -- which isn't ideal.
author timeless@mozdev.org
date Wed, 30 Sep 2015 12:36:30 -0400
parents eb21b6679dc6
children 97dc6ab42aad
files mercurial/cmdutil.py
diffstat 1 files changed, 15 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Tue Sep 29 14:42:03 2015 -0700
+++ b/mercurial/cmdutil.py	Wed Sep 30 12:36:30 2015 -0400
@@ -2735,6 +2735,9 @@
     t.show(ctx, extramsg=extramsg)
     return ui.popbuffer()
 
+def hgprefix(msg):
+    return "\n".join(["HG: %s" % a for a in msg.split("\n") if a])
+
 def buildcommittext(repo, ctx, subs, extramsg):
     edittext = []
     modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
@@ -2742,23 +2745,23 @@
         edittext.append(ctx.description())
     edittext.append("")
     edittext.append("") # Empty line between message and comments.
-    edittext.append("HG: %s" % _("Enter commit message."
-                      "  Lines beginning with 'HG:' are removed."))
-    edittext.append("HG: %s" % extramsg)
+    edittext.append(hgprefix(_("Enter commit message."
+                      "  Lines beginning with 'HG:' are removed.")))
+    edittext.append(hgprefix(extramsg))
     edittext.append("HG: --")
-    edittext.append("HG: %s" % (_("user: %s") % ctx.user()))
+    edittext.append(hgprefix(_("user: %s") % ctx.user()))
     if ctx.p2():
-        edittext.append("HG: %s" % _("branch merge"))
+        edittext.append(hgprefix(_("branch merge")))
     if ctx.branch():
-        edittext.append("HG: %s" % (_("branch '%s'") % ctx.branch()))
+        edittext.append(hgprefix(_("branch '%s'") % ctx.branch()))
     if bookmarks.isactivewdirparent(repo):
-        edittext.append("HG: %s" % (_("bookmark '%s'") % repo._activebookmark))
-    edittext.extend(["HG: %s" % (_("subrepo %s") % s) for s in subs])
-    edittext.extend(["HG: %s" % (_("added %s") % f) for f in added])
-    edittext.extend(["HG: %s" % (_("changed %s") % f) for f in modified])
-    edittext.extend(["HG: %s" % (_("removed %s") % f) for f in removed])
+        edittext.append(hgprefix(_("bookmark '%s'") % repo._activebookmark))
+    edittext.extend([hgprefix(_("subrepo %s") % s) for s in subs])
+    edittext.extend([hgprefix(_("added %s") % f) for f in added])
+    edittext.extend([hgprefix(_("changed %s") % f) for f in modified])
+    edittext.extend([hgprefix(_("removed %s") % f) for f in removed])
     if not added and not modified and not removed:
-        edittext.append("HG: %s" % _("no files changed"))
+        edittext.append(hgprefix(_("no files changed")))
     edittext.append("")
 
     return "\n".join(edittext)