D4884: repo: remove the last few "pass" statements in localrepo.__getitem__

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Fri Oct 5 00:03:46 UTC 2018


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  In case of IndexError or LookupError, we used "pass" statements and
  fell through to the end of localrepo.__getitem__. I find the pass
  statements easy to miss. Consistently raising and catching exceptions
  seems easier to follow.
  
  Oh -- and I didn't plan this before I wrote the above -- that probably
  also lets us reuse the "return context.changectx(self, rev, node)" in
  a later patch.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/localrepo.py

CHANGE DETAILS

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1255,30 +1255,24 @@
                         msg = _("working directory has unknown parent '%s'!")
                         raise error.Abort(msg % short(changeid))
                     changeid = hex(changeid) # for the error message
+                    raise
 
             elif len(changeid) == 40:
-                try:
-                    node = bin(changeid)
-                    rev = self.changelog.rev(node)
-                    return context.changectx(self, rev, node)
-                except error.FilteredLookupError:
-                    raise
-                except LookupError:
-                    pass
+                node = bin(changeid)
+                rev = self.changelog.rev(node)
+                return context.changectx(self, rev, node)
             else:
                 raise error.ProgrammingError(
                         "unsupported changeid '%s' of type %s" %
                         (changeid, type(changeid)))
 
         except (error.FilteredIndexError, error.FilteredLookupError):
             raise error.FilteredRepoLookupError(_("filtered revision '%s'")
                                                 % pycompat.bytestr(changeid))
-        except IndexError:
-            pass
+        except (IndexError, LookupError):
+            raise error.RepoLookupError(_("unknown revision '%s'") % changeid)
         except error.WdirUnsupported:
             return context.workingctx(self)
-        raise error.RepoLookupError(
-            _("unknown revision '%s'") % changeid)
 
     def __contains__(self, changeid):
         """True if the given changeid exists



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


More information about the Mercurial-devel mailing list