comparison mercurial/localrepo.py @ 40063:f84d7ed3bb35

repo: remove the last few "pass" statements in localrepo.__getitem__ 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. Differential Revision: https://phab.mercurial-scm.org/D4884
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 04 Oct 2018 16:06:36 -0700
parents 324b4b10351e
children 5c3585a58845
comparison
equal deleted inserted replaced
40062:b6c2543e1dd8 40063:f84d7ed3bb35
1253 if (self.local() 1253 if (self.local()
1254 and changeid in self.unfiltered().dirstate.parents()): 1254 and changeid in self.unfiltered().dirstate.parents()):
1255 msg = _("working directory has unknown parent '%s'!") 1255 msg = _("working directory has unknown parent '%s'!")
1256 raise error.Abort(msg % short(changeid)) 1256 raise error.Abort(msg % short(changeid))
1257 changeid = hex(changeid) # for the error message 1257 changeid = hex(changeid) # for the error message
1258 raise
1258 1259
1259 elif len(changeid) == 40: 1260 elif len(changeid) == 40:
1260 try: 1261 node = bin(changeid)
1261 node = bin(changeid) 1262 rev = self.changelog.rev(node)
1262 rev = self.changelog.rev(node) 1263 return context.changectx(self, rev, node)
1263 return context.changectx(self, rev, node)
1264 except error.FilteredLookupError:
1265 raise
1266 except LookupError:
1267 pass
1268 else: 1264 else:
1269 raise error.ProgrammingError( 1265 raise error.ProgrammingError(
1270 "unsupported changeid '%s' of type %s" % 1266 "unsupported changeid '%s' of type %s" %
1271 (changeid, type(changeid))) 1267 (changeid, type(changeid)))
1272 1268
1273 except (error.FilteredIndexError, error.FilteredLookupError): 1269 except (error.FilteredIndexError, error.FilteredLookupError):
1274 raise error.FilteredRepoLookupError(_("filtered revision '%s'") 1270 raise error.FilteredRepoLookupError(_("filtered revision '%s'")
1275 % pycompat.bytestr(changeid)) 1271 % pycompat.bytestr(changeid))
1276 except IndexError: 1272 except (IndexError, LookupError):
1277 pass 1273 raise error.RepoLookupError(_("unknown revision '%s'") % changeid)
1278 except error.WdirUnsupported: 1274 except error.WdirUnsupported:
1279 return context.workingctx(self) 1275 return context.workingctx(self)
1280 raise error.RepoLookupError(
1281 _("unknown revision '%s'") % changeid)
1282 1276
1283 def __contains__(self, changeid): 1277 def __contains__(self, changeid):
1284 """True if the given changeid exists 1278 """True if the given changeid exists
1285 1279
1286 error.AmbiguousPrefixLookupError is raised if an ambiguous node 1280 error.AmbiguousPrefixLookupError is raised if an ambiguous node