[PATCH 3 of 4] extensions: various improvements related to the help topic

Cédric Duval cedricduval at free.fr
Sun Jun 21 09:40:10 CDT 2009


# HG changeset patch
# User Cédric Duval <cedricduval at free.fr>
# Date 1245595140 -7200
# Node ID 88aacc0e18fc11bcc91b1fe89673e754143532ab
# Parent  3760529b6e07abccabb6900f9fa93d18ff3ae324
extensions: various improvements related to the help topic

 - rename help.extensionslisting() to help.listexts()
 - merge pydoc mention with moduledoc()'s documentation
 - return early from functions to save on indentation
 - rename help.topicextensions() to help.extshelp()

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1485,8 +1485,7 @@
 
         if name != 'shortlist':
             exts, maxlength = extensions.enabled()
-            ui.write(help.extensionslisting(_('enabled extensions:'),
-                                            exts, maxlength))
+            ui.write(help.listexts(_('enabled extensions:'), exts, maxlength))
 
         if not ui.quiet:
             addglobalopts(True)
diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -9,11 +9,13 @@
 import extensions
 
 
-# loosely inspired by pydoc.source_synopsis()
-# rewritten to handle ''' as well as """
-# and to return the whole text instead of just the synopsis
 def moduledoc(file):
-    '''Return the top python documentation for the given file'''
+    '''Return the top python documentation for the given file
+
+    loosely inspired by pydoc.source_synopsis()
+    rewritten to handle both kinds of docstring delimiters, and to return
+    the whole text instead of just the synopsis (required for gettext)
+    '''
     result = []
 
     line = file.readline()
@@ -39,18 +41,18 @@
 
     return ''.join(result)
 
-def extensionslisting(header, exts, maxlength):
+def listexts(header, exts, maxlength):
     '''Return a text listing of the given extensions'''
-    result = ''
+    if not exts:
+        return ''
 
-    if exts:
-        result += '\n%s\n\n' % header
-        for name, desc in sorted(exts.iteritems()):
-            result += ' %s   %s\n' % (name.ljust(maxlength), desc)
+    result = '\n%s\n\n' % header
+    for name, desc in sorted(exts.iteritems()):
+        result += ' %s   %s\n' % (name.ljust(maxlength), desc)
 
     return result
 
-def topicextensions():
+def extshelp():
     doc = _(r'''
     Mercurial has a mechanism for adding new features through the
     use of extensions. Extensions may bring new commands, or new
@@ -86,10 +88,10 @@
     ''')
 
     exts, maxlength = extensions.enabled()
-    doc += extensionslisting(_('enabled extensions:'), exts, maxlength)
+    doc += listexts(_('enabled extensions:'), exts, maxlength)
 
     exts, maxlength = extensions.disabled()
-    doc += extensionslisting(_('non-enabled extensions:'), exts, maxlength)
+    doc += listexts(_('non-enabled extensions:'), exts, maxlength)
 
     return doc
 
@@ -504,5 +506,5 @@
       The push command will look for a path named 'default-push', and
       prefer it over 'default' if both are defined.
     ''')),
-    (["extensions"], _("Using additional features"), topicextensions),
+    (["extensions"], _("Using additional features"), extshelp),
 )



More information about the Mercurial-devel mailing list