Patchwork [6,of,9,v3] bundlerepo: introduce method to find file starts and use it

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

Comments

Augie Fackler - Aug. 5, 2016, 9:45 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1470416878 14400
#      Fri Aug 05 13:07:58 2016 -0400
# Node ID bb22ee33a9f98e3e017288c13993e1cef6dbd4ed
# Parent  3d62ff7bd297f51e29738df0de074ee9e929b6a3
bundlerepo: introduce method to find file starts 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.
via Mercurial-devel - Aug. 5, 2016, 10:05 p.m.
On Fri, Aug 5, 2016 at 2:45 PM, Augie Fackler <raf@durin42.com> wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1470416878 14400
> #      Fri Aug 05 13:07:58 2016 -0400
> # Node ID bb22ee33a9f98e3e017288c13993e1cef6dbd4ed
> # Parent  3d62ff7bd297f51e29738df0de074ee9e929b6a3
> bundlerepo: introduce method to find file starts 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
> @@ -234,6 +234,15 @@ class bundlephasecache(phases.phasecache
>          self.invalidate()
>          self.dirty = True
>
> +def _getfilestarts(bundle):
> +    bundlefilespos = {}
> +    for chunkdata in iter(bundle.filelogheader, {}):
> +        fname = chunkdata['filename']
> +        bundlefilespos[fname] = bundle.tell()
> +        for chunk in iter(lambda: bundle.deltachunk(None), {}):
> +            pass
> +    return bundlefilespos
> +
>  class bundlerepository(localrepo.localrepository):
>      def __init__(self, ui, path, bundlename):
>          def _writetempbundle(read, suffix, header=''):
> @@ -349,13 +358,7 @@ class bundlerepository(localrepo.localre
>      def file(self, f):
>          if not self.bundlefilespos:
>              self.bundle.seek(self.filestart)
> -            for chunkdata in iter(self.bundle.filelogheader, {}):
> -                fname = chunkdata['filename']
> -                self.bundlefilespos[fname] = self.bundle.tell()
> -                while True:
> -                    c = self.bundle.deltachunk(None)
> -                    if not c:
> -                        break
> +            self.bundlefilespos.update(_getfilestarts(self.bundle))

We know it's empty, so I'll change this to a reassignment in flight if
you don't mind. Not that it will be noticeably faster, but I think
it's simpler.

>
>          if f in self.bundlefilespos:
>              self.bundle.seek(self.bundlefilespos[f])
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Augie Fackler - Aug. 5, 2016, 10:08 p.m.
On Fri, Aug 5, 2016 at 6:05 PM, Martin von Zweigbergk
<martinvonz@google.com> wrote:
>> +            self.bundlefilespos.update(_getfilestarts(self.bundle))
>
> We know it's empty, so I'll change this to a reassignment in flight if
> you don't mind. Not that it will be noticeably faster, but I think
> it's simpler.


Please do!

Patch

diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -234,6 +234,15 @@  class bundlephasecache(phases.phasecache
         self.invalidate()
         self.dirty = True
 
+def _getfilestarts(bundle):
+    bundlefilespos = {}
+    for chunkdata in iter(bundle.filelogheader, {}):
+        fname = chunkdata['filename']
+        bundlefilespos[fname] = bundle.tell()
+        for chunk in iter(lambda: bundle.deltachunk(None), {}):
+            pass
+    return bundlefilespos
+
 class bundlerepository(localrepo.localrepository):
     def __init__(self, ui, path, bundlename):
         def _writetempbundle(read, suffix, header=''):
@@ -349,13 +358,7 @@  class bundlerepository(localrepo.localre
     def file(self, f):
         if not self.bundlefilespos:
             self.bundle.seek(self.filestart)
-            for chunkdata in iter(self.bundle.filelogheader, {}):
-                fname = chunkdata['filename']
-                self.bundlefilespos[fname] = self.bundle.tell()
-                while True:
-                    c = self.bundle.deltachunk(None)
-                    if not c:
-                        break
+            self.bundlefilespos.update(_getfilestarts(self.bundle))
 
         if f in self.bundlefilespos:
             self.bundle.seek(self.bundlefilespos[f])