Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 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 | bda14660f0d7 |
children | 3ad41638b4b4 |
comparison
equal
deleted
inserted
replaced
26425:eb21b6679dc6 | 26426:0486c16ce621 |
---|---|
2733 | 2733 |
2734 ui.pushbuffer() | 2734 ui.pushbuffer() |
2735 t.show(ctx, extramsg=extramsg) | 2735 t.show(ctx, extramsg=extramsg) |
2736 return ui.popbuffer() | 2736 return ui.popbuffer() |
2737 | 2737 |
2738 def hgprefix(msg): | |
2739 return "\n".join(["HG: %s" % a for a in msg.split("\n") if a]) | |
2740 | |
2738 def buildcommittext(repo, ctx, subs, extramsg): | 2741 def buildcommittext(repo, ctx, subs, extramsg): |
2739 edittext = [] | 2742 edittext = [] |
2740 modified, added, removed = ctx.modified(), ctx.added(), ctx.removed() | 2743 modified, added, removed = ctx.modified(), ctx.added(), ctx.removed() |
2741 if ctx.description(): | 2744 if ctx.description(): |
2742 edittext.append(ctx.description()) | 2745 edittext.append(ctx.description()) |
2743 edittext.append("") | 2746 edittext.append("") |
2744 edittext.append("") # Empty line between message and comments. | 2747 edittext.append("") # Empty line between message and comments. |
2745 edittext.append("HG: %s" % _("Enter commit message." | 2748 edittext.append(hgprefix(_("Enter commit message." |
2746 " Lines beginning with 'HG:' are removed.")) | 2749 " Lines beginning with 'HG:' are removed."))) |
2747 edittext.append("HG: %s" % extramsg) | 2750 edittext.append(hgprefix(extramsg)) |
2748 edittext.append("HG: --") | 2751 edittext.append("HG: --") |
2749 edittext.append("HG: %s" % (_("user: %s") % ctx.user())) | 2752 edittext.append(hgprefix(_("user: %s") % ctx.user())) |
2750 if ctx.p2(): | 2753 if ctx.p2(): |
2751 edittext.append("HG: %s" % _("branch merge")) | 2754 edittext.append(hgprefix(_("branch merge"))) |
2752 if ctx.branch(): | 2755 if ctx.branch(): |
2753 edittext.append("HG: %s" % (_("branch '%s'") % ctx.branch())) | 2756 edittext.append(hgprefix(_("branch '%s'") % ctx.branch())) |
2754 if bookmarks.isactivewdirparent(repo): | 2757 if bookmarks.isactivewdirparent(repo): |
2755 edittext.append("HG: %s" % (_("bookmark '%s'") % repo._activebookmark)) | 2758 edittext.append(hgprefix(_("bookmark '%s'") % repo._activebookmark)) |
2756 edittext.extend(["HG: %s" % (_("subrepo %s") % s) for s in subs]) | 2759 edittext.extend([hgprefix(_("subrepo %s") % s) for s in subs]) |
2757 edittext.extend(["HG: %s" % (_("added %s") % f) for f in added]) | 2760 edittext.extend([hgprefix(_("added %s") % f) for f in added]) |
2758 edittext.extend(["HG: %s" % (_("changed %s") % f) for f in modified]) | 2761 edittext.extend([hgprefix(_("changed %s") % f) for f in modified]) |
2759 edittext.extend(["HG: %s" % (_("removed %s") % f) for f in removed]) | 2762 edittext.extend([hgprefix(_("removed %s") % f) for f in removed]) |
2760 if not added and not modified and not removed: | 2763 if not added and not modified and not removed: |
2761 edittext.append("HG: %s" % _("no files changed")) | 2764 edittext.append(hgprefix(_("no files changed"))) |
2762 edittext.append("") | 2765 edittext.append("") |
2763 | 2766 |
2764 return "\n".join(edittext) | 2767 return "\n".join(edittext) |
2765 | 2768 |
2766 def commitstatus(repo, node, branch, bheads=None, opts=None): | 2769 def commitstatus(repo, node, branch, bheads=None, opts=None): |