From patchwork Wed Jul 7 18:12:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D11007: shallowutil: narrow scope of try/except block From: phabricator X-Patchwork-Id: 49320 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Wed, 7 Jul 2021 18:12:27 +0000 durin42 created this revision. Herald added a reviewer: hg-reviewers. Herald added a subscriber: mercurial-patches. REVISION SUMMARY This will make this code easier to understand in the future. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D11007 AFFECTED FILES hgext/remotefilelog/shallowutil.py CHANGE DETAILS To: durin42, #hg-reviewers Cc: mercurial-patches, mercurial-devel diff --git a/hgext/remotefilelog/shallowutil.py b/hgext/remotefilelog/shallowutil.py --- a/hgext/remotefilelog/shallowutil.py +++ b/hgext/remotefilelog/shallowutil.py @@ -247,6 +247,11 @@ size = None try: index = raw.index(b'\0') + except ValueError: + raise BadRemotefilelogHeader( + "unexpected remotefilelog header: illegal format" + ) + if True: header = raw[:index] if header.startswith(b'v'): # v1 and above, header starts with 'v' @@ -263,10 +268,6 @@ else: # v0, str(int(size)) is the header size = int(header) - except ValueError: - raise BadRemotefilelogHeader( - "unexpected remotefilelog header: illegal format" - ) if size is None: raise BadRemotefilelogHeader( "unexpected remotefilelog header: no size found"