D9344: errors: morph reportsimilar() into similarity_hint()
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Sat Nov 21 00:26:39 UTC 2020
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
The next step is to eagerly create the hint in `UnknownIdentifier`'s
constructor.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D9344
AFFECTED FILES
mercurial/dispatch.py
mercurial/scmutil.py
CHANGE DETAILS
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -150,12 +150,14 @@
return [s for s in symbols if sim(s) > 0.6]
-def reportsimilar(write, similar):
+def similarity_hint(similar):
if len(similar) == 1:
- write(_(b"(did you mean %s?)\n") % similar[0])
+ return _(b"did you mean %s?") % similar[0]
elif similar:
ss = b", ".join(sorted(similar))
- write(_(b"(did you mean one of %s?)\n") % ss)
+ return _(b"did you mean one of %s?") % ss
+ else:
+ return None
def formatparse(write, inst):
@@ -169,7 +171,9 @@
if isinstance(inst, error.UnknownIdentifier):
# make sure to check fileset first, as revset can invoke fileset
similar = getsimilar(inst.symbols, inst.function)
- reportsimilar(write, similar)
+ hint = similarity_hint(similar)
+ if hint:
+ write(b"(%s)\n" % hint)
elif inst.hint:
write(_(b"(%s)\n") % inst.hint)
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -487,7 +487,7 @@
sim = scmutil.getsimilar(inst.all_commands, inst.command)
if sim:
ui.warn(nocmdmsg)
- scmutil.reportsimilar(ui.warn, sim)
+ ui.warn(b"(%s)\n" % scmutil.similarity_hint(sim))
suggested = True
if not suggested:
ui.warn(nocmdmsg)
To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list