comparison mercurial/help.py @ 16845:4594729c61ee

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).
author Nikolaj Sjujskij <sterkrig@myopera.com>
date Mon, 04 Jun 2012 10:45:56 +0400
parents d10994f1c7a2
children af69b2b64d6e
comparison
equal deleted inserted replaced
16843:61f3ca8e4d39 16845:4594729c61ee
68 Returns {'section': [(name, summary), ...], ...} where section is 68 Returns {'section': [(name, summary), ...], ...} where section is
69 one of topics, commands, extensions, or extensioncommands. 69 one of topics, commands, extensions, or extensioncommands.
70 """ 70 """
71 kw = encoding.lower(kw) 71 kw = encoding.lower(kw)
72 def lowercontains(container): 72 def lowercontains(container):
73 return kw in encoding.lower(_(container)) 73 return kw in encoding.lower(container) # translated in helptable
74 results = {'topics': [], 74 results = {'topics': [],
75 'commands': [], 75 'commands': [],
76 'extensions': [], 76 'extensions': [],
77 'extensioncommands': [], 77 'extensioncommands': [],
78 } 78 }
87 continue 87 continue
88 if len(entry) == 3: 88 if len(entry) == 3:
89 summary = entry[2] 89 summary = entry[2]
90 else: 90 else:
91 summary = '' 91 summary = ''
92 docs = getattr(entry[0], '__doc__', None) or '' 92 # translate docs *before* searching there
93 docs = _(getattr(entry[0], '__doc__', None)) or ''
93 if kw in cmd or lowercontains(summary) or lowercontains(docs): 94 if kw in cmd or lowercontains(summary) or lowercontains(docs):
94 doclines = _(docs).splitlines() 95 doclines = docs.splitlines()
95 if doclines: 96 if doclines:
96 summary = doclines[0] 97 summary = doclines[0]
97 cmdname = cmd.split('|')[0].lstrip('^') 98 cmdname = cmd.split('|')[0].lstrip('^')
98 results['commands'].append((cmdname, summary)) 99 results['commands'].append((cmdname, summary))
99 for name, docs in itertools.chain( 100 for name, docs in itertools.chain(
100 extensions.enabled().iteritems(), 101 extensions.enabled().iteritems(),
101 extensions.disabled().iteritems()): 102 extensions.disabled().iteritems()):
102 # extensions.load ignores the UI argument 103 # extensions.load ignores the UI argument
103 mod = extensions.load(None, name, '') 104 mod = extensions.load(None, name, '')
104 if lowercontains(name) or lowercontains(docs): 105 if lowercontains(name) or lowercontains(docs):
105 results['extensions'].append((name, _(docs).splitlines()[0])) 106 # extension docs are already translated
107 results['extensions'].append((name, docs.splitlines()[0]))
106 for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems(): 108 for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
107 if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])): 109 if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])):
108 cmdname = cmd.split('|')[0].lstrip('^') 110 cmdname = cmd.split('|')[0].lstrip('^')
109 results['extensioncommands'].append( 111 results['extensioncommands'].append(
110 (cmdname, _(getattr(cmd, '__doc__', '')))) 112 (cmdname, _(getattr(cmd, '__doc__', ''))))