Patchwork D9343: errors: restructure formatparse() to clarify conditions a bit

login
register
mail settings
Submitter phabricator
Date Nov. 21, 2020, 12:26 a.m.
Message ID <differential-rev-PHID-DREV-jsbde5zlru2sdip4q5s6-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47621/
State Superseded
Headers show

Comments

phabricator - Nov. 21, 2020, 12:26 a.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9343

AFFECTED FILES
  mercurial/scmutil.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -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)