Mercurial > hg-stable
comparison mercurial/extensions.py @ 14316:d5b525697ddb
extensions: drop maxlength from enabled and disabled
This is a bad/silly API. Instead calculate maxlength in one place in help
it's used and simplify all the callers.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 13 May 2011 11:04:51 -0500 |
parents | 08fde203a600 |
children | 660b0c1b6196 |
comparison
equal
deleted
inserted
replaced
14315:f6b3b346d80c | 14316:d5b525697ddb |
---|---|
228 '''find disabled extensions from hgext | 228 '''find disabled extensions from hgext |
229 returns a dict of {name: desc}, and the max name length''' | 229 returns a dict of {name: desc}, and the max name length''' |
230 | 230 |
231 paths = _disabledpaths() | 231 paths = _disabledpaths() |
232 if not paths: | 232 if not paths: |
233 return None, 0 | 233 return None |
234 | 234 |
235 exts = {} | 235 exts = {} |
236 maxlength = 0 | |
237 for name, path in paths.iteritems(): | 236 for name, path in paths.iteritems(): |
238 doc = _disabledhelp(path) | 237 doc = _disabledhelp(path) |
239 if not doc: | 238 if doc: |
240 continue | 239 exts[name] = doc |
241 | 240 |
242 exts[name] = doc | 241 return exts |
243 if len(name) > maxlength: | |
244 maxlength = len(name) | |
245 | |
246 return exts, maxlength | |
247 | 242 |
248 def disabledext(name): | 243 def disabledext(name): |
249 '''find a specific disabled extension from hgext. returns desc''' | 244 '''find a specific disabled extension from hgext. returns desc''' |
250 paths = _disabledpaths() | 245 paths = _disabledpaths() |
251 if name in paths: | 246 if name in paths: |
297 raise error.UnknownCommand(cmd) | 292 raise error.UnknownCommand(cmd) |
298 | 293 |
299 def enabled(): | 294 def enabled(): |
300 '''return a dict of {name: desc} of extensions, and the max name length''' | 295 '''return a dict of {name: desc} of extensions, and the max name length''' |
301 exts = {} | 296 exts = {} |
302 maxlength = 0 | |
303 for ename, ext in extensions(): | 297 for ename, ext in extensions(): |
304 doc = (gettext(ext.__doc__) or _('(no help text available)')) | 298 doc = (gettext(ext.__doc__) or _('(no help text available)')) |
305 ename = ename.split('.')[-1] | 299 ename = ename.split('.')[-1] |
306 maxlength = max(len(ename), maxlength) | |
307 exts[ename] = doc.splitlines()[0].strip() | 300 exts[ename] = doc.splitlines()[0].strip() |
308 | 301 |
309 return exts, maxlength | 302 return exts |