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

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Mon Jun 4 06:02:44 CDT 2012


Hi, Nikolaj.

At Mon, 04 Jun 2012 11:22:43 +0400,
Nikolaj Sjujskij wrote:
> 
> # HG changeset patch
> # User Nikolaj Sjujskij <sterkrig at myopera.com>
> # Date 1338792356 -14400
> # Node ID c9956d571694080dc86b7bef0b5154ff03e1dd49
> # 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. `container` item (hunk
> #1) is translated in `helptable` and `docs` (hunk #2) contains already
> translated extension description.
> 
> 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)
>      results = {'topics': [],
>                 'commands': [],
>                 'extensions': [],
> @@ -102,7 +102,7 @@
>          # extensions.load ignores the UI argument
>          mod = extensions.load(None, name, '')
>          if lowercontains(name) or lowercontains(docs):
> -            results['extensions'].append((name, _(docs).splitlines()[0]))
> +            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('^')

With just your patch, keyword looking up seems to be done on
not-translated texts only for help of commands.

I think fixing like below is also needed:

================
diff -r c9956d571694 mercurial/help.py
--- a/mercurial/help.py	Mon Jun 04 10:45:56 2012 +0400
+++ b/mercurial/help.py	Mon Jun 04 19:56:42 2012 +0900
@@ -89,9 +89,9 @@
             summary = entry[2]
         else:
             summary = ''
-        docs = getattr(entry[0], '__doc__', None) or ''
+        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('^')
================

----------------------------------------------------------------------
[FUJIWARA Katsunori]                             foozy at lares.dti.ne.jp


More information about the Mercurial-devel mailing list