[PATCH] dispatch: report similar names consistently

Bryan O'Sullivan bos at serpentine.com
Tue Jan 5 05:53:55 UTC 2016


# HG changeset patch
# User Bryan O'Sullivan <bos at serpentine.com>
# Date 1451973164 28800
#      Mon Jan 04 21:52:44 2016 -0800
# Node ID f9a7e04fb6e1d31887c9a866fef852e52db7ca21
# Parent  b8405d739149cdd6d8d9bd5e3dd2ad8487b1f09a
dispatch: report similar names consistently

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -59,6 +59,13 @@ def _getsimilar(symbols, value):
     # probably be investigated and tweaked.
     return [s for s in symbols if sim(s) > 0.6]
 
+def _reportsimilar(write, similar):
+    if len(similar) == 1:
+        write(_("(did you mean %s?)\n") % similar[0])
+    elif similar:
+        ss = ", ".join(sorted(similar))
+        write(_("(did you mean one of %s?)\n") % ss)
+
 def _formatparse(write, inst):
     similar = []
     if isinstance(inst, error.UnknownIdentifier):
@@ -71,12 +78,7 @@ def _formatparse(write, inst):
             write(_("unexpected leading whitespace\n"))
     else:
         write(_("hg: parse error: %s\n") % inst.args[0])
-        if similar:
-            if len(similar) == 1:
-                write(_("(did you mean %r?)\n") % similar[0])
-            else:
-                ss = ", ".join(sorted(similar))
-                write(_("(did you mean one of %s?)\n") % ss)
+        _reportsimilar(write, similar)
 
 def dispatch(req):
     "run the command specified in req.args"
@@ -262,8 +264,7 @@ def _runcatch(req):
             if len(inst.args) == 2:
                 sim = _getsimilar(inst.args[1], inst.args[0])
                 if sim:
-                    ui.warn(_('(did you mean one of %s?)\n') %
-                            ', '.join(sorted(sim)))
+                    _reportsimilar(ui.warn, sim)
                     suggested = True
             if not suggested:
                 commands.help_(ui, 'shortlist')
diff --git a/tests/test-alias.t b/tests/test-alias.t
--- a/tests/test-alias.t
+++ b/tests/test-alias.t
@@ -360,11 +360,11 @@ shell alias defined in current repo
   sub
   $ hg --cwd .. subalias > /dev/null
   hg: unknown command 'subalias'
-  (did you mean one of idalias?)
+  (did you mean idalias?)
   [255]
   $ hg -R .. subalias > /dev/null
   hg: unknown command 'subalias'
-  (did you mean one of idalias?)
+  (did you mean idalias?)
   [255]
 
 
@@ -372,7 +372,7 @@ shell alias defined in other repo
 
   $ hg mainalias > /dev/null
   hg: unknown command 'mainalias'
-  (did you mean one of idalias?)
+  (did you mean idalias?)
   [255]
   $ hg -R .. mainalias
   main
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -645,12 +645,12 @@ this is a section and erroring out weird
 
   $ hg .log
   hg: unknown command '.log'
-  (did you mean one of log?)
+  (did you mean log?)
   [255]
 
   $ hg log.
   hg: unknown command 'log.'
-  (did you mean one of log?)
+  (did you mean log?)
   [255]
   $ hg pu.lh
   hg: unknown command 'pu.lh'
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1482,11 +1482,11 @@ parentrevspec
 Bogus function gets suggestions
   $ log 'add()'
   hg: parse error: unknown identifier: add
-  (did you mean 'adds'?)
+  (did you mean adds?)
   [255]
   $ log 'added()'
   hg: parse error: unknown identifier: added
-  (did you mean 'adds'?)
+  (did you mean adds?)
   [255]
   $ log 'remo()'
   hg: parse error: unknown identifier: remo
@@ -1499,7 +1499,7 @@ Bogus function gets suggestions
 Bogus function with a similar internal name doesn't suggest the internal name
   $ log 'matches()'
   hg: parse error: unknown identifier: matches
-  (did you mean 'matching'?)
+  (did you mean matching?)
   [255]
 
 Undocumented functions aren't suggested as similar either


More information about the Mercurial-devel mailing list