Patchwork D11007: shallowutil: narrow scope of try/except block

login
register
mail settings
Submitter phabricator
Date July 7, 2021, 6:12 p.m.
Message ID <differential-rev-PHID-DREV-fk72o2xq2dc2xuho3chh-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49320/
State Superseded
Headers show

Comments

phabricator - July 7, 2021, 6:12 p.m.
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

Patch

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"