# HG changeset patch
# User Bryan O'Sullivan <bos@serpentine.com>
# Date 1451973164 28800
#      Mon Jan 04 21:52:44 2016 -0800
# Node ID b3376fba4ab91c8fd6c02c3424d785b466f50836
# Parent  0bc71f45d3623b231cc3975b48feccce79d1231e
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 @@
     # 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 @@
             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 @@
             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 @@
   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 @@
 
   $ 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 @@
 
   $ 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 @@
 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 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