Mercurial > hg
changeset 9941:11d7ee94b56a stable
extdiff: prevent exception on double-translation
The docstring is translated twice: once when used as a format string,
and once on display. The second translation fails when the first
translation introduces non-ASCII characters in the string.
The problem is that the gettext module calls unicode(message) on the
string, i.e., it decodes it to a Unicode string using the ASCII
encoding (the default encoding). By translating it into a Unicode
string here, the unicode() call becomes a noop.
author | Martin Geisler <mg@lazybytes.net> |
---|---|
date | Thu, 26 Nov 2009 20:06:45 +0100 |
parents | 251812d34c08 |
children | b6d484168350 |
files | hgext/extdiff.py |
diffstat | 1 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/extdiff.py Wed Nov 25 21:54:18 2009 -0600 +++ b/hgext/extdiff.py Thu Nov 26 20:06:45 2009 +0100 @@ -43,7 +43,7 @@ from mercurial.i18n import _ from mercurial.node import short, nullid -from mercurial import cmdutil, util, commands +from mercurial import cmdutil, util, commands, encoding import os, shlex, shutil, tempfile, re def snapshot(ui, repo, files, node, tmproot): @@ -254,7 +254,7 @@ '''use closure to save diff command to use''' def mydiff(ui, repo, *pats, **opts): return dodiff(ui, repo, path, diffopts, pats, opts) - mydiff.__doc__ = _('''\ + doc = _('''\ use %(path)s to diff repository (or selected files) Show differences between revisions for the specified files, using the @@ -265,6 +265,14 @@ compared to the working directory, and, when no revisions are specified, the working directory files are compared to its parent.\ ''') % dict(path=util.uirepr(path)) + + # We must translate the docstring right away since it is + # used as a format string. The string will unfortunately + # be translated again in commands.helpcmd and this will + # fail when the docstring contains non-ASCII characters. + # Decoding the string to a Unicode string here (using the + # right encoding) prevents that. + mydiff.__doc__ = doc.decode(encoding.encoding) return mydiff cmdtable[cmd] = (save(cmd, path, diffopts), cmdtable['extdiff'][1][1:],