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

login
register
mail settings
Submitter Augie Fackler
Date Aug. 5, 2016, 9:45 p.m.
Message ID <22621301ecb69d251c44.1470433505@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/16134/
State Accepted
Headers show

Comments

Augie Fackler - Aug. 5, 2016, 9:45 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1470416964 14400
#      Fri Aug 05 13:09:24 2016 -0400
# Node ID 22621301ecb69d251c4481c5ebd1b05d9ad57db4
# Parent  e131d83f89725b400741c083920c3e3fae944ceb
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: