changeset 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 f6b3b346d80c
children 660b0c1b6196
files doc/gendoc.py mercurial/commands.py mercurial/extensions.py mercurial/help.py mercurial/subrepo.py
diffstat 5 files changed, 13 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/doc/gendoc.py	Fri May 13 11:26:29 2011 +0200
+++ b/doc/gendoc.py	Fri May 13 11:04:51 2011 -0500
@@ -157,16 +157,7 @@
 
 
 def allextensionnames():
-    extensionnames = []
-
-    extensionsdictionary = extensions.enabled()[0]
-    extensionnames.extend(extensionsdictionary.keys())
-
-    extensionsdictionary = extensions.disabled()[0]
-    extensionnames.extend(extensionsdictionary.keys())
-
-    return extensionnames
-
+    return extensions.enabled().keys() + extensions.disabled().keys()
 
 if __name__ == "__main__":
     show_doc(sys.stdout)
--- a/mercurial/commands.py	Fri May 13 11:26:29 2011 +0200
+++ b/mercurial/commands.py	Fri May 13 11:04:51 2011 -0500
@@ -2752,8 +2752,7 @@
         doc = gettext(mod.__doc__).splitlines()[0]
 
         msg = help.listexts(_("'%s' is provided by the following "
-                              "extension:") % cmd, {ext: doc}, len(ext),
-                            indent=4)
+                              "extension:") % cmd, {ext: doc}, indent=4)
         ui.write(minirst.format(msg, textwidth))
         ui.write('\n\n')
         ui.write(_('use "hg help extensions" for information on enabling '
@@ -2799,8 +2798,7 @@
 
         helplist(header)
         if name != 'shortlist':
-            exts, maxlength = extensions.enabled()
-            text = help.listexts(_('enabled extensions:'), exts, maxlength)
+            text = help.listexts(_('enabled extensions:'), extensions.enabled())
             if text:
                 ui.write("\n%s\n" % minirst.format(text, textwidth))
 
--- a/mercurial/extensions.py	Fri May 13 11:26:29 2011 +0200
+++ b/mercurial/extensions.py	Fri May 13 11:04:51 2011 -0500
@@ -230,20 +230,15 @@
 
     paths = _disabledpaths()
     if not paths:
-        return None, 0
+        return None
 
     exts = {}
-    maxlength = 0
     for name, path in paths.iteritems():
         doc = _disabledhelp(path)
-        if not doc:
-            continue
+        if doc:
+            exts[name] = doc
 
-        exts[name] = doc
-        if len(name) > maxlength:
-            maxlength = len(name)
-
-    return exts, maxlength
+    return exts
 
 def disabledext(name):
     '''find a specific disabled extension from hgext. returns desc'''
@@ -299,11 +294,9 @@
 def enabled():
     '''return a dict of {name: desc} of extensions, and the max name length'''
     exts = {}
-    maxlength = 0
     for ename, ext in extensions():
         doc = (gettext(ext.__doc__) or _('(no help text available)'))
         ename = ename.split('.')[-1]
-        maxlength = max(len(ename), maxlength)
         exts[ename] = doc.splitlines()[0].strip()
 
-    return exts, maxlength
+    return exts
--- a/mercurial/help.py	Fri May 13 11:26:29 2011 +0200
+++ b/mercurial/help.py	Fri May 13 11:04:51 2011 -0500
@@ -43,10 +43,11 @@
 
     return ''.join(result)
 
-def listexts(header, exts, maxlength, indent=1):
+def listexts(header, exts, indent=1):
     '''return a text listing of the given extensions'''
     if not exts:
         return ''
+    maxlength = max(len(e) for e in exts)
     result = '\n%s\n\n' % header
     for name, desc in sorted(exts.iteritems()):
         result += '%s%-*s %s\n' % (' ' * indent, maxlength + 2,
@@ -55,13 +56,8 @@
 
 def extshelp():
     doc = loaddoc('extensions')()
-
-    exts, maxlength = extensions.enabled()
-    doc += listexts(_('enabled extensions:'), exts, maxlength)
-
-    exts, maxlength = extensions.disabled()
-    doc += listexts(_('disabled extensions:'), exts, maxlength)
-
+    doc += listexts(_('enabled extensions:'), extensions.enabled())
+    doc += listexts(_('disabled extensions:'), extensions.disabled())
     return doc
 
 def loaddoc(topic):
--- a/mercurial/subrepo.py	Fri May 13 11:26:29 2011 +0200
+++ b/mercurial/subrepo.py	Fri May 13 11:04:51 2011 -0500
@@ -408,7 +408,7 @@
         if r == '' and not ignoreupdate: # no state recorded
             return True
         w = self._repo[None]
-        if r != w.p1().node() and not ignoreupdate:
+        if r != w.p1().hex() and not ignoreupdate:
             # different version checked out
             return True
         return w.dirty() # working directory changed