Patchwork [5,of,9,v3] bundlerevlog: 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 <3d62ff7bd297f51e2973.1470433506@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/16135/
State Accepted
Headers show

Comments

Augie Fackler - Aug. 5, 2016, 9:45 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1470416990 14400
#      Fri Aug 05 13:09:50 2016 -0400
# Node ID 3d62ff7bd297f51e29738df0de074ee9e929b6a3
# Parent  22621301ecb69d251c4481c5ebd1b05d9ad57db4
bundlerevlog: 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
@@ -56,10 +56,8 @@  class bundlerevlog(revlog.revlog):
         self.repotiprev = n - 1
         chain = None
         self.bundlerevs = set() # used by 'bundle()' revset expression
-        while True:
-            chunkdata = bundle.deltachunk(chain)
-            if not chunkdata:
-                break
+        getchunk = lambda: bundle.deltachunk(chain)
+        for chunkdata in iter(getchunk, {}):
             node = chunkdata['node']
             p1 = chunkdata['p1']
             p2 = chunkdata['p2']