Patchwork [4,of,9,v2] bundlerepo: use for loop over iterator instead of while True

login
register
mail settings
Submitter Augie Fackler
Date Aug. 5, 2016, 5:23 p.m.
Message ID <882d809ec9834608cb34.1470417822@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/16123/
State Superseded
Headers show

Comments

Augie Fackler - Aug. 5, 2016, 5:23 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1470416964 14400
#      Fri Aug 05 13:09:24 2016 -0400
# Node ID 882d809ec9834608cb3472eb9dc49bbcd4b5ef7a
# Parent  c62ecf6bc1931ef717912cf143b188def7590499
bundlerepo: use for loop over iterator instead of while True

The iter() builtin has a neat pattern where you give it a callable of
no arguments and a sentinel value, and you can then loop over the
function calls like a normal iterator. This cleans up the code a
little.

Patch

diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -351,10 +351,7 @@  class bundlerepository(localrepo.localre
     def file(self, f):
         if not self.bundlefilespos:
             self.bundle.seek(self.filestart)
-            while True:
-                chunkdata = self.bundle.filelogheader()
-                if not chunkdata:
-                    break
+            for chunkdata in iter(self.bundle.filelogheader, {}):
                 fname = chunkdata['filename']
                 self.bundlefilespos[fname] = self.bundle.tell()
                 while True: