Mercurial > public > mercurial-scm > hg
comparison hgext/extdiff.py @ 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 | d932dc655881 |
children | 5e4ef56b4d42 6045a8c4dbbc |
comparison
equal
deleted
inserted
replaced
9939:251812d34c08 | 9941:11d7ee94b56a |
---|---|
41 fast (at least faster than having to compare the entire tree). | 41 fast (at least faster than having to compare the entire tree). |
42 ''' | 42 ''' |
43 | 43 |
44 from mercurial.i18n import _ | 44 from mercurial.i18n import _ |
45 from mercurial.node import short, nullid | 45 from mercurial.node import short, nullid |
46 from mercurial import cmdutil, util, commands | 46 from mercurial import cmdutil, util, commands, encoding |
47 import os, shlex, shutil, tempfile, re | 47 import os, shlex, shutil, tempfile, re |
48 | 48 |
49 def snapshot(ui, repo, files, node, tmproot): | 49 def snapshot(ui, repo, files, node, tmproot): |
50 '''snapshot files as of some revision | 50 '''snapshot files as of some revision |
51 if not using snapshot, -I/-X does not work and recursive diff | 51 if not using snapshot, -I/-X does not work and recursive diff |
252 path, diffopts = cmd, [] | 252 path, diffopts = cmd, [] |
253 def save(cmd, path, diffopts): | 253 def save(cmd, path, diffopts): |
254 '''use closure to save diff command to use''' | 254 '''use closure to save diff command to use''' |
255 def mydiff(ui, repo, *pats, **opts): | 255 def mydiff(ui, repo, *pats, **opts): |
256 return dodiff(ui, repo, path, diffopts, pats, opts) | 256 return dodiff(ui, repo, path, diffopts, pats, opts) |
257 mydiff.__doc__ = _('''\ | 257 doc = _('''\ |
258 use %(path)s to diff repository (or selected files) | 258 use %(path)s to diff repository (or selected files) |
259 | 259 |
260 Show differences between revisions for the specified files, using the | 260 Show differences between revisions for the specified files, using the |
261 %(path)s program. | 261 %(path)s program. |
262 | 262 |
263 When two revision arguments are given, then changes are shown between | 263 When two revision arguments are given, then changes are shown between |
264 those revisions. If only one revision is specified then that revision is | 264 those revisions. If only one revision is specified then that revision is |
265 compared to the working directory, and, when no revisions are specified, | 265 compared to the working directory, and, when no revisions are specified, |
266 the working directory files are compared to its parent.\ | 266 the working directory files are compared to its parent.\ |
267 ''') % dict(path=util.uirepr(path)) | 267 ''') % dict(path=util.uirepr(path)) |
268 | |
269 # We must translate the docstring right away since it is | |
270 # used as a format string. The string will unfortunately | |
271 # be translated again in commands.helpcmd and this will | |
272 # fail when the docstring contains non-ASCII characters. | |
273 # Decoding the string to a Unicode string here (using the | |
274 # right encoding) prevents that. | |
275 mydiff.__doc__ = doc.decode(encoding.encoding) | |
268 return mydiff | 276 return mydiff |
269 cmdtable[cmd] = (save(cmd, path, diffopts), | 277 cmdtable[cmd] = (save(cmd, path, diffopts), |
270 cmdtable['extdiff'][1][1:], | 278 cmdtable['extdiff'][1][1:], |
271 _('hg %s [OPTION]... [FILE]...') % cmd) | 279 _('hg %s [OPTION]... [FILE]...') % cmd) |