bundlerepo: introduce method to find file starts and use it
authorAugie Fackler <augie@google.com>
Fri, 05 Aug 2016 13:07:58 -0400
changeset 29712 9e88077f972c
parent 29711 ac5f6b11aa91
child 29713 43924f3a55fa
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.
mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py	Fri Aug 05 13:09:50 2016 -0400
+++ b/mercurial/bundlerepo.py	Fri Aug 05 13:07:58 2016 -0400
@@ -234,6 +234,15 @@
         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 @@
     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 = _getfilestarts(self.bundle)
 
         if f in self.bundlefilespos:
             self.bundle.seek(self.bundlefilespos[f])