errors: restructure formatparse() to clarify conditions a bit
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 19 Nov 2020 10:29:06 -0800
changeset 45880 7a273336d3d3
parent 45879 5d73d3053d92
child 45881 bb1b7a5bc96b
errors: restructure formatparse() to clarify conditions a bit The `similar` list will be calculated only for `error.UnknownIdentifier`. It was then printed only if `inst.location is None`, which is true for that exception type, but it's an indirect condition to rely on. Also, it looked from the code like it could both report similarities and print a hint. That would be a little awkward because the similarity report looks similar to the hint (both are printed within parentheses). I also added a `elif` to clarify that. I plan to refactor this more coming patches so the similarity report actually is a hint. Differential Revision: https://phab.mercurial-scm.org/D9343
mercurial/scmutil.py
--- a/mercurial/scmutil.py	Thu Nov 19 14:55:55 2020 -0500
+++ b/mercurial/scmutil.py	Thu Nov 19 10:29:06 2020 -0800
@@ -159,10 +159,6 @@
 
 
 def formatparse(write, inst):
-    similar = []
-    if isinstance(inst, error.UnknownIdentifier):
-        # make sure to check fileset first, as revset can invoke fileset
-        similar = getsimilar(inst.symbols, inst.function)
     if inst.location is not None:
         write(
             _(b"hg: parse error at %s: %s\n")
@@ -170,8 +166,11 @@
         )
     else:
         write(_(b"hg: parse error: %s\n") % inst.message)
+    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)
-    if inst.hint:
+    elif inst.hint:
         write(_(b"(%s)\n") % inst.hint)