[PATCH 5 of 9 v2] bundlerevlog: use for loop over iterator instead of while True

Kevin Bullock kbullock+mercurial at ringworld.org
Fri Aug 5 16:58:02 EDT 2016


> On Aug 5, 2016, at 12:23, Augie Fackler <raf at durin42.com> wrote:
> 
> # HG changeset patch
> # User Augie Fackler <augie at google.com>
> # Date 1470416990 14400
> #      Fri Aug 05 13:09:50 2016 -0400
> # Node ID 8f8a9c204d704878faabbeca4c6c011ebc0a088e
> # Parent  882d809ec9834608cb3472eb9dc49bbcd4b5ef7a
> 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.
> 
> diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
> --- a/mercurial/bundlerepo.py
> +++ b/mercurial/bundlerepo.py
> @@ -56,10 +56,7 @@ 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
> +        for chunkdata in iter(lambda: bundle.deltachunk(chain), {}):

Nit: seems to be this would be clearer if we give the callable a name:

    getchunk = lambda: bundle.deltachunk(chain)
    for chunkdata in iter(getchunk, {}):
        # ...

pacem in terris / мир / शान्ति / ‎‫سَلاَم‬ / 平和
Kevin R. Bullock



More information about the Mercurial-devel mailing list