Patchwork [3,of,3] help: use cmdutil.parsealiases() to resolve command name

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 15, 2018, 1:42 p.m.
Message ID <74f1b48042c6595ae49a.1518702158@mimosa>
Download mbox | patch
Permalink /patch/27976/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 15, 2018, 1:42 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1515380983 -32400
#      Mon Jan 08 12:09:43 2018 +0900
# Node ID 74f1b48042c6595ae49aaee050d1eac3b672fe6d
# Parent  d5c440f7e2840eae190246159ec31d74b4df655f
help: use cmdutil.parsealiases() to resolve command name

This seems slightly better than parsing '^command|name' string by using an
ad-hoc pattern.
Augie Fackler - Feb. 16, 2018, 10:14 p.m.
On Thu, Feb 15, 2018 at 10:42:38PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1515380983 -32400
> #      Mon Jan 08 12:09:43 2018 +0900
> # Node ID 74f1b48042c6595ae49aaee050d1eac3b672fe6d
> # Parent  d5c440f7e2840eae190246159ec31d74b4df655f
> help: use cmdutil.parsealiases() to resolve command name

queued, thanks

Patch

diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -150,7 +150,7 @@  def topicmatch(ui, commands, kw):
             doclines = docs.splitlines()
             if doclines:
                 summary = doclines[0]
-            cmdname = cmd.partition('|')[0].lstrip('^')
+            cmdname = cmdutil.parsealiases(cmd)[0]
             if filtercmd(ui, cmdname, kw, docs):
                 continue
             results['commands'].append((cmdname, summary))
@@ -170,7 +170,7 @@  def topicmatch(ui, commands, kw):
             continue
         for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
             if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])):
-                cmdname = cmd.partition('|')[0].lstrip('^')
+                cmdname = cmdutil.parsealiases(cmd)[0]
                 cmddoc = pycompat.getdoc(entry[0])
                 if cmddoc:
                     cmddoc = gettext(cmddoc).splitlines()[0]
@@ -328,7 +328,7 @@  def help_(ui, commands, name, unknowncmd
             # py3k fix: except vars can't be used outside the scope of the
             # except block, nor can be used inside a lambda. python issue4617
             prefix = inst.args[0]
-            select = lambda c: c.lstrip('^').startswith(prefix)
+            select = lambda c: cmdutil.parsealiases(c)[0].startswith(prefix)
             rst = helplist(select)
             return rst
 
@@ -419,15 +419,18 @@  def help_(ui, commands, name, unknowncmd
         h = {}
         cmds = {}
         for c, e in commands.table.iteritems():
-            f = c.partition("|")[0]
-            if select and not select(f):
+            fs = cmdutil.parsealiases(c)
+            f = fs[0]
+            p = ''
+            if c.startswith("^"):
+                p = '^'
+            if select and not select(p + f):
                 continue
             if (not select and name != 'shortlist' and
                 e[0].__module__ != commands.__name__):
                 continue
-            if name == "shortlist" and not f.startswith("^"):
+            if name == "shortlist" and not p:
                 continue
-            f = f.lstrip("^")
             doc = pycompat.getdoc(e[0])
             if filtercmd(ui, f, name, doc):
                 continue
@@ -435,7 +438,7 @@  def help_(ui, commands, name, unknowncmd
             if not doc:
                 doc = _("(no help text available)")
             h[f] = doc.splitlines()[0].rstrip()
-            cmds[f] = c.lstrip("^")
+            cmds[f] = '|'.join(fs)
 
         rst = []
         if not h: