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

Augie Fackler raf at durin42.com
Fri Aug 5 17:45:05 EDT 2016


# HG changeset patch
# User Augie Fackler <augie at 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.

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:


More information about the Mercurial-devel mailing list