[PATCH v2] help: fix search with `-k` option in non-ASCII locales

Nikolaj Sjujskij sterkrig at myopera.com
Mon Jun 4 10:56:08 CDT 2012


# HG changeset patch
# User Nikolaj Sjujskij <sterkrig at myopera.com>
# Date 1338792356 -14400
# Node ID 21a5cd6e449a638c53c56a17fbee77e8f672ce23
# Parent  0a0cf3f26938ff7a084f2dcc9e59152ac6060e1e
help: fix search with `-k` option in non-ASCII locales

Keyword search in help (introduced in 497deec204d1 and a17983680f12 by Augie
Fackler) tries to translate already translated strings, which results in
Unicode errors in gettext when non-ASCII locale is used. Also command
descriptions should be translated before searching there (thanks to FUJIWARA
Katsunori for pointing this out and actual fix), (issue3482).

diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -70,7 +70,7 @@
     """
     kw = encoding.lower(kw)
     def lowercontains(container):
-        return kw in encoding.lower(_(container))
+        return kw in encoding.lower(container)  # translated in helptable
     results = {'topics': [],
                'commands': [],
                'extensions': [],
@@ -89,9 +89,10 @@
             summary = entry[2]
         else:
             summary = ''
-        docs = getattr(entry[0], '__doc__', None) or ''
+        # translate docs *before* searching there
+        docs = _(getattr(entry[0], '__doc__', None)) or ''
         if kw in cmd or lowercontains(summary) or lowercontains(docs):
-            doclines = _(docs).splitlines()
+            doclines = docs.splitlines()
             if doclines:
                 summary = doclines[0]
             cmdname = cmd.split('|')[0].lstrip('^')
@@ -102,7 +103,8 @@
         # extensions.load ignores the UI argument
         mod = extensions.load(None, name, '')
         if lowercontains(name) or lowercontains(docs):
-            results['extensions'].append((name, _(docs).splitlines()[0]))
+            # extension docs are already translated
+            results['extensions'].append((name, docs.splitlines()[0]))
         for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
             if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])):
                 cmdname = cmd.split('|')[0].lstrip('^')


More information about the Mercurial-devel mailing list