comparison hgext/extdiff.py @ 29630:67b180c0e263 stable

extdiff: escape path for docstring (issue5301) The existing code (a) assumed path would be specified in encoding.encoding and (b) assumed unicode() objects wouldn't cause other parts of Mercurial to blow up. Both are dangerous assumptions. Since we don't know the encoding of path and can't pass non-ASCII through docstrings, just escape the path and drop the early _(). Will have to suffice until we can teach docstrings to handle UTF-8b escaping. This has the side-effect that the line containing the path is now variable by the time it reaches _() and thus can't be translated.
author Matt Mackall <mpm@selenic.com>
date Mon, 18 Jul 2016 16:25:35 -0500
parents 4f86c3bed63b
children 479076db51be
comparison
equal deleted inserted replaced
29629:b33c0c38d68f 29630:67b180c0e263
74 ) 74 )
75 from mercurial import ( 75 from mercurial import (
76 archival, 76 archival,
77 cmdutil, 77 cmdutil,
78 commands, 78 commands,
79 encoding,
80 error, 79 error,
81 filemerge, 80 filemerge,
82 scmutil, 81 scmutil,
83 util, 82 util,
84 ) 83 )
363 def mydiff(ui, repo, *pats, **opts): 362 def mydiff(ui, repo, *pats, **opts):
364 options = ' '.join(map(util.shellquote, opts['option'])) 363 options = ' '.join(map(util.shellquote, opts['option']))
365 if options: 364 if options:
366 options = ' ' + options 365 options = ' ' + options
367 return dodiff(ui, repo, cmdline + options, pats, opts) 366 return dodiff(ui, repo, cmdline + options, pats, opts)
368 doc = _('''\ 367 # We can't pass non-ASCII through docstrings (and path is
368 # in an unknown encoding anyway)
369 docpath = path.encode("string-escape")
370 mydiff.__doc__ = '''\
369 use %(path)s to diff repository (or selected files) 371 use %(path)s to diff repository (or selected files)
370 372
371 Show differences between revisions for the specified files, using 373 Show differences between revisions for the specified files, using
372 the %(path)s program. 374 the %(path)s program.
373 375
374 When two revision arguments are given, then changes are shown 376 When two revision arguments are given, then changes are shown
375 between those revisions. If only one revision is specified then 377 between those revisions. If only one revision is specified then
376 that revision is compared to the working directory, and, when no 378 that revision is compared to the working directory, and, when no
377 revisions are specified, the working directory files are compared 379 revisions are specified, the working directory files are compared
378 to its parent.\ 380 to its parent.\
379 ''') % {'path': util.uirepr(path)} 381 ''' % {'path': util.uirepr(docpath)}
380
381 # We must translate the docstring right away since it is
382 # used as a format string. The string will unfortunately
383 # be translated again in commands.helpcmd and this will
384 # fail when the docstring contains non-ASCII characters.
385 # Decoding the string to a Unicode string here (using the
386 # right encoding) prevents that.
387 mydiff.__doc__ = doc.decode(encoding.encoding)
388 return mydiff 382 return mydiff
389 command(cmd, extdiffopts[:], _('hg %s [OPTION]... [FILE]...') % cmd, 383 command(cmd, extdiffopts[:], _('hg %s [OPTION]... [FILE]...') % cmd,
390 inferrepo=True)(save(cmdline)) 384 inferrepo=True)(save(cmdline))