[PATCH 6 of 9 v2] bundlerepo: introduce method to discard file chunks and use it

Martin von Zweigbergk martinvonz at google.com
Fri Aug 5 16:36:27 EDT 2016


On Fri, Aug 5, 2016 at 10:23 AM, Augie Fackler <raf at durin42.com> wrote:
> # HG changeset patch
> # User Augie Fackler <augie at google.com>
> # Date 1470416878 14400
> #      Fri Aug 05 13:07:58 2016 -0400
> # Node ID 7e585d431acf066bf97ac7ccf8d16044206d5931
> # Parent  8f8a9c204d704878faabbeca4c6c011ebc0a088e
> bundlerepo: introduce method to discard file chunks and use it
>
> This moves us to the modern iter() technique instead of the `while
> True` pattern since it's easy. Factored out as a function because I'm
> about to need this in a second place.
>
> diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
> --- a/mercurial/bundlerepo.py
> +++ b/mercurial/bundlerepo.py
> @@ -233,6 +233,10 @@ class bundlephasecache(phases.phasecache
>          self.invalidate()
>          self.dirty = True
>
> +def _discarddeltachunks(bundle):
> +    for chunk in iter(lambda: bundle.deltachunk(None), {}):
> +        pass
> +
>  class bundlerepository(localrepo.localrepository):
>      def __init__(self, ui, path, bundlename):
>          def _writetempbundle(read, suffix, header=''):
> @@ -351,10 +355,7 @@ class bundlerepository(localrepo.localre
>              for chunkdata in iter(self.bundle.filelogheader, {}):
>                  fname = chunkdata['filename']
>                  self.bundlefilespos[fname] = self.bundle.tell()

I haven't tested it myself, but it looks like these three lines could
also be extracted into a helper for the last patch in this series.
Something like a findfilepositions() returning a dict.
_discarddeltachunks() would then be called from a single place and can
be inlined again.

> -                while True:
> -                    c = self.bundle.deltachunk(None)
> -                    if not c:
> -                        break
> +                _discarddeltachunks(self.bundle)
>
>          if f in self.bundlefilespos:
>              self.bundle.seek(self.bundlefilespos[f])
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list