changeset 35136:2b72bc88043f

bundle2: only seek to beginning of part in bundlerepo For reasons still not yet fully understood by me, bundlerepo requires its changegroup bundle2 part to be seeked to beginning after part iteration. As far as I can tell, it is the only bundle2 part consumer that relies on this behavior. This seeking was performed in the generic iterparts() API. Again, I don't fully understand why it was here and not in bundlerepo. Probably historical reasons. What I do know is that all other bundle2 part consumers don't need this special behavior (assuming the tests are comprehensive). So, we move the code from bundle2's iterparts() to bundlerepo's consumption of iterparts(). Differential Revision: https://phab.mercurial-scm.org/D1389
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 13 Nov 2017 20:12:00 -0800
parents db5038525718
children da91e7309daf
files mercurial/bundle2.py mercurial/bundlerepo.py
diffstat 2 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundle2.py	Mon Nov 13 20:03:02 2017 -0800
+++ b/mercurial/bundle2.py	Mon Nov 13 20:12:00 2017 -0800
@@ -859,9 +859,7 @@
             # Ensure part is fully consumed so we can start reading the next
             # part.
             part.consume()
-            # But then seek back to the beginning so the code consuming this
-            # generator has a part that starts at 0.
-            part.seek(0, os.SEEK_SET)
+
             headerblock = self._readpartheader()
         indebug(self.ui, 'end of bundle2 stream')
 
--- a/mercurial/bundlerepo.py	Mon Nov 13 20:03:02 2017 -0800
+++ b/mercurial/bundlerepo.py	Mon Nov 13 20:12:00 2017 -0800
@@ -288,18 +288,26 @@
             self._bundlefile = bundle
             self._cgunpacker = None
 
-            hadchangegroup = False
+            cgpart = None
             for part in bundle.iterparts():
                 if part.type == 'changegroup':
-                    if hadchangegroup:
+                    if cgpart:
                         raise NotImplementedError("can't process "
                                                   "multiple changegroups")
-                    hadchangegroup = True
+                    cgpart = part
 
                 self._handlebundle2part(bundle, part)
 
-            if not hadchangegroup:
+            if not cgpart:
                 raise error.Abort(_("No changegroups found"))
+
+            # This is required to placate a later consumer, which expects
+            # the payload offset to be at the beginning of the changegroup.
+            # We need to do this after the iterparts() generator advances
+            # because iterparts() will seek to end of payload after the
+            # generator returns control to iterparts().
+            cgpart.seek(0, os.SEEK_SET)
+
         elif isinstance(bundle, changegroup.cg1unpacker):
             if bundle.compressed():
                 f = self._writetempbundle(bundle.read, '.hg10un',