[PATCH 1 of 1] Add 'st' alias to 'status'

Thomas Arendsen Hein thomas at intevation.de
Mon Nov 7 18:03:29 UTC 2005


* Matt Mackall <mpm at selenic.com> [20051104 19:31]:
> On Fri, Nov 04, 2005 at 06:52:03PM +0100, Benoit Boissinot wrote:
> > On 11/4/05, Thomas Arendsen Hein <thomas at intevation.de> wrote:
> > > I thought about a more generic way: You can already abbreviate long
> > > options by only typing enough characters so it is unambiguous, maybe
> > > this should be added for commands, too.
> > >
> > patch attached
> 
> I've applied this patch and I've also added an explicit 'st' shortcut

Thanks.

Attached are two related patches:

- Canonicalize command when using aliases or prefix matching.
  This makes the norepo check and the help and version command work when not
  using the canonical name.

- Improved error message for ambiguous command shortcuts.

Pullable from http://hg.intevation.org/mercurial/tah

Thomas

-- 
Email: thomas at intevation.de
http://intevation.de/~thomas/
-------------- next part --------------
# HG changeset patch
# User Thomas Arendsen Hein <thomas at intevation.de>
# Node ID b582dbc161655aa19f5237f9c60516d2fc361909
# Parent  b254243b71595549519a558b1e134a6312235480
Canonicalize command when using aliases or prefix matching.
This makes the norepo check and the help and version command work when not
using the canonical name.

diff -r b254243b71595549519a558b1e134a6312235480 -r b582dbc161655aa19f5237f9c60516d2fc361909 mercurial/commands.py
--- a/mercurial/commands.py	Fri Nov  4 11:37:45 2005 -0800
+++ b/mercurial/commands.py	Mon Nov  7 18:39:25 2005 +0100
@@ -387,7 +387,7 @@
         if with_version:
             show_version(ui)
             ui.write('\n')
-        key, i = find(cmd)
+        aliases, i = find(cmd)
         # synopsis
         ui.write("%s\n\n" % i[2])
 
@@ -399,9 +399,8 @@
 
         if not ui.quiet:
             # aliases
-            aliases = ', '.join(key.split('|')[1:])
-            if aliases:
-                ui.write(_("\naliases: %s\n") % aliases)
+            if len(aliases) > 1:
+                ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:]))
 
             # options
             if i[1]:
@@ -2374,17 +2373,20 @@
           " debugindex debugindexdot paths")
 
 def find(cmd):
-    choice = []
+    """Return (aliases, command table entry) for command string."""
+    choice = None
     for e in table.keys():
         aliases = e.lstrip("^").split("|")
         if cmd in aliases:
-            return e, table[e]
+            return aliases, table[e]
         for a in aliases:
             if a.startswith(cmd):
-                choice.append(e)
-    if len(choice) == 1:
-        e = choice[0]
-        return e, table[e]
+                if choice:
+                    raise UnknownCommand(cmd)
+                else:
+                    choice = aliases, table[e]
+    if choice:
+        return choice
 
     raise UnknownCommand(cmd)
 
@@ -2422,7 +2424,8 @@
 
             cmd, args = args[0], args[1:]
 
-        i = find(cmd)[1]
+        aliases, i = find(cmd)
+        cmd = aliases[0]
         c = list(i[1])
     else:
         cmd = None
-------------- next part --------------
# HG changeset patch
# User Thomas Arendsen Hein <thomas at intevation.de>
# Node ID ac4ca6bf23836a4f9ec6ba318f6843e3404681f4
# Parent  b582dbc161655aa19f5237f9c60516d2fc361909
Improved error message for ambiguous command shortcuts.

diff -r b582dbc161655aa19f5237f9c60516d2fc361909 -r ac4ca6bf23836a4f9ec6ba318f6843e3404681f4 mercurial/commands.py
--- a/mercurial/commands.py	Mon Nov  7 18:39:25 2005 +0100
+++ b/mercurial/commands.py	Mon Nov  7 19:00:51 2005 +0100
@@ -15,6 +15,8 @@
 
 class UnknownCommand(Exception):
     """Exception raised if command is not in the command table."""
+class AmbiguousCommand(Exception):
+    """Exception raised if command shortcut matches more than one command."""
 
 def filterfiles(filters, files):
     l = [x for x in files if x in filters]
@@ -2382,7 +2384,7 @@
         for a in aliases:
             if a.startswith(cmd):
                 if choice:
-                    raise UnknownCommand(cmd)
+                    raise AmbiguousCommand(cmd)
                 else:
                     choice = aliases, table[e]
     if choice:
@@ -2505,6 +2507,9 @@
             u.warn(_("hg: %s\n") % inst.args[1])
             help_(u, 'shortlist')
         sys.exit(-1)
+    except AmbiguousCommand, inst:
+        u.warn(_("hg: command '%s' is ambiguous.\n") % inst.args[0])
+        sys.exit(1)
     except UnknownCommand, inst:
         u.warn(_("hg: unknown command '%s'\n") % inst.args[0])
         help_(u, 'shortlist')


More information about the Mercurial mailing list