[PATCH 1 of 6] restructure helptable

Martin Geisler mg at daimi.au.dk
Sat Sep 6 16:51:49 CDT 2008


"Benoit Boissinot" <bboissin at gmail.com> writes:

> On Sat, Sep 6, 2008 at 1:11 AM, Martin Geisler <mg at daimi.au.dk> wrote:
>> # HG changeset patch
>> # User Martin Geisler <mg at daimi.au.dk>
>> # Date 1220646339 -7200
>> # Node ID 6e27b148d38efe47576d0f4627da8fc2f6691fe3
>> # Parent  4e62be0208d3465cf241d8fb6fb7c9ce125a490b
>> restructure helptable
>>
> Looks good, small comment below.
>
>
>> diff --git a/mercurial/commands.py b/mercurial/commands.py
>> --- a/mercurial/commands.py
>> +++ b/mercurial/commands.py
>> @@ -1332,14 +1332,12 @@
>>             addglobalopts(True)
>>
>>     def helptopic(name):
>> -        v = None
>> -        for i, d in help.helptable:
>> -            l = i.split('|')
>> -            if name in l:
>> -                v = i
>> -                header = l[-1]
>> -                doc = d
>> -        if not v:
>> +        found = None
> No need for that
>> +        for names, header, doc in help.helptable:
>> +            if name in names:
>> +                found = True
> for that either
>> +                break
>> +        if not found:
> just use that (see http://docs.python.org/ref/for.html else clause):
>   +       else:
>>             raise cmdutil.UnknownCommand(name)

Ah, nice! I don't think I have ever used that feature before :-) Here is
an updated patch:

# HG changeset patch
# User Martin Geisler <mg at daimi.au.dk>
# Date 1220737533 -7200
# Node ID bdfbb73ab41d9b02bfbd0b3bde7843197166eff2
# Parent  83260da2f16492a9132ff5771d7f37131f2ce05b
restructure helptable

When looking up a help topic, the key is now only matched against the
short names for each topic, and not the header. So

  hg help 'Environment Variables'

must be replaced with

  hg help env

diff --git a/doc/gendoc.py b/doc/gendoc.py
--- a/doc/gendoc.py
+++ b/doc/gendoc.py
@@ -92,9 +92,7 @@
             ui.write(_("    aliases: %s\n\n") % " ".join(d['aliases']))
 
     # print topics
-    for t, doc in helptable:
-        l = t.split("|")
-        section = l[-1]
+    for names, section, doc in helptable:
         underlined(_(section).upper())
         if callable(doc):
             doc = doc()
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1332,14 +1332,10 @@
             addglobalopts(True)
 
     def helptopic(name):
-        v = None
-        for i, d in help.helptable:
-            l = i.split('|')
-            if name in l:
-                v = i
-                header = l[-1]
-                doc = d
-        if not v:
+        for names, header, doc in help.helptable:
+            if name in names:
+                break
+        else:
             raise cmdutil.UnknownCommand(name)
 
         # description
@@ -1416,9 +1412,8 @@
     if ui.verbose:
         ui.write(_("\nspecial help topics:\n"))
         topics = []
-        for i, d in help.helptable:
-            l = i.split('|')
-            topics.append((", ".join(l[:-1]), l[-1]))
+        for names, header, doc in help.helptable:
+            topics.append((", ".join(names), header))
         topics_len = max([len(s[0]) for s in topics])
         for t, desc in topics:
             ui.write(" %-*s  %s\n" % (topics_len, t, desc))
diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -6,7 +6,7 @@
 # of the GNU General Public License, incorporated herein by reference.
 
 helptable = (
-    ("dates|Date Formats",
+    (["dates"], "Date Formats",
     r'''
     Some commands allow the user to specify a date:
     backout, commit, import, tag: Specify the commit date.
@@ -45,7 +45,7 @@
     "-{days}" - within a given number of days of today
     '''),
 
-    ("patterns|File Name Patterns",
+    (["patterns"], "File Name Patterns",
     r'''
     Mercurial accepts several notations for identifying one or more
     files at a time.
@@ -91,7 +91,7 @@
 
     '''),
 
-    ('environment|env|Environment Variables',
+    (['environment', 'env'], 'Environment Variables',
     r'''
 HG::
     Path to the 'hg' executable, automatically passed when running hooks,
@@ -162,7 +162,7 @@
     appropriately if Mercurial is not installed system-wide.
     '''),
 
-    ('revs|revisions|Specifying Single Revisions',
+    (['revs', 'revisions'], 'Specifying Single Revisions',
     r'''
     Mercurial accepts several notations for identifying individual
     revisions.
@@ -195,7 +195,7 @@
     the first parent.
     '''),
 
-    ('mrevs|multirevs|Specifying Multiple Revisions',
+    (['mrevs', 'multirevs'], 'Specifying Multiple Revisions',
     r'''
     When Mercurial accepts more than one revision, they may be
     specified individually, or provided as a continuous range,




-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial-devel/attachments/20080906/5c57edc0/attachment.pgp 


More information about the Mercurial-devel mailing list