[PATCH] help: report source of aliases

timeless timeless at mozdev.org
Fri Apr 8 18:43:57 UTC 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1460140549 0
#      Fri Apr 08 18:35:49 2016 +0000
# Node ID 48aba2bdd63f1d9d2a6f807bc198b5d93215b5a3
# Parent  c5565fc8848dd084d104ca40c33d1acdfcff8bc6
help: report source of aliases

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -379,7 +379,7 @@
     return r.sub(lambda x: replacemap[x.group()], cmd)
 
 class cmdalias(object):
-    def __init__(self, name, definition, cmdtable):
+    def __init__(self, name, definition, cmdtable, source):
         self.name = self.cmd = name
         self.cmdname = ''
         self.definition = definition
@@ -389,6 +389,7 @@
         self.help = ''
         self.badalias = None
         self.unknowncmd = False
+        self.source = source
 
         try:
             aliases, entry = cmdutil.findcmd(self.name, cmdtable)
@@ -499,7 +500,8 @@
     # may use extension commands. Aliases can also use other alias definitions,
     # but only if they have been defined prior to the current definition.
     for alias, definition in ui.configitems('alias'):
-        aliasdef = cmdalias(alias, definition, cmdtable)
+        source = ui.configsource('alias', alias)
+        aliasdef = cmdalias(alias, definition, cmdtable, source)
 
         try:
             olddef = cmdtable[aliasdef.cmd][0]
diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -336,10 +336,13 @@
         if not doc:
             doc = _("(no help text available)")
         if util.safehasattr(entry[0], 'definition'):  # aliased command
+            source = entry[0].source
             if entry[0].definition.startswith('!'):  # shell alias
-                doc = _('shell alias for::\n\n    %s') % entry[0].definition[1:]
+                doc = (_('shell alias for::\n\n    %s\n\ndefined by: %s\n') %
+                       (entry[0].definition[1:], source))
             else:
-                doc = _('alias for: hg %s\n\n%s') % (entry[0].definition, doc)
+                doc = (_('alias for: hg %s\n\n%s\n\ndefined by: %s\n') %
+                       (entry[0].definition, doc, source))
         doc = doc.splitlines(True)
         if ui.quiet or not full:
             rst.append(doc[0])
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -673,10 +673,50 @@
   > def nohelp(ui, *args, **kwargs):
   >     pass
   > 
+  > def uisetup(ui):
+  >     ui.setconfig('alias', 'shellalias', '!echo hi', 'helpext')
+  >     ui.setconfig('alias', 'hgalias', 'summary', 'helpext')
+  > 
   > EOF
   $ echo '[extensions]' >> $HGRCPATH
   $ echo "helpext = `pwd`/helpext.py" >> $HGRCPATH
 
+Test for aliases
+
+  $ hg help hgalias
+  hg hgalias [--remote]
+  
+  alias for: hg summary
+  
+  summarize working directory state
+  
+      This generates a brief summary of the working directory state, including
+      parents, branch, commit status, phase and available updates.
+  
+      With the --remote option, this will check the default paths for incoming
+      and outgoing changes. This can be time-consuming.
+  
+      Returns 0 on success.
+  
+  defined by: helpext
+  
+  options:
+  
+    --remote check for push and pull
+  
+  (some details hidden, use --verbose to show complete help)
+
+  $ hg help shellalias
+  hg shellalias
+  
+  shell alias for:
+  
+    echo hi
+  
+  defined by: helpext
+  
+  (some details hidden, use --verbose to show complete help)
+
 Test command with no help text
 
   $ hg help nohelp
@@ -2064,6 +2104,13 @@
   show help for a given topic or a help overview
   </td></tr>
   <tr><td>
+  <a href="/help/hgalias">
+  hgalias
+  </a>
+  </td><td>
+  summarize working directory state
+  </td></tr>
+  <tr><td>
   <a href="/help/identify">
   identify
   </a>
@@ -2155,6 +2202,13 @@
   print the root (top) of the current working directory
   </td></tr>
   <tr><td>
+  <a href="/help/shellalias">
+  shellalias
+  </a>
+  </td><td>
+  (no help text available)
+  </td></tr>
+  <tr><td>
   <a href="/help/tag">
   tag
   </a>


More information about the Mercurial-devel mailing list