Patchwork D1392: bundle2: inline changegroup.readexactly()

login
register
mail settings
Submitter phabricator
Date Nov. 20, 2017, 11:50 p.m.
Message ID <384e6b40e413d184fd7ab058fe42e99b@localhost.localdomain>
Download mbox | patch
Permalink /patch/25693/
State Not Applicable
Headers show

Comments

phabricator - Nov. 20, 2017, 11:50 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG1fb0846ad792: bundle2: inline changegroup.readexactly() (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1392?vs=3470&id=3696

REVISION DETAIL
  https://phab.mercurial-scm.org/D1392

AFFECTED FILES
  mercurial/bundle2.py

CHANGE DETAILS




To: indygreg, #hg-reviewers, durin42
Cc: mercurial-devel

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -1198,22 +1198,36 @@ 
 
     headersize = struct.calcsize(_fpayloadsize)
     readexactly = changegroup.readexactly
+    read = fh.read
 
     chunksize = _unpack(_fpayloadsize, readexactly(fh, headersize))[0]
     indebug(ui, 'payload chunk size: %i' % chunksize)
 
+    # changegroup.readexactly() is inlined below for performance.
     while chunksize:
         if chunksize >= 0:
-            yield readexactly(fh, chunksize)
+            s = read(chunksize)
+            if len(s) < chunksize:
+                raise error.Abort(_('stream ended unexpectedly '
+                                    ' (got %d bytes, expected %d)') %
+                                  (len(s), chunksize))
+
+            yield s
         elif chunksize == flaginterrupt:
             # Interrupt "signal" detected. The regular stream is interrupted
             # and a bundle2 part follows. Consume it.
             interrupthandler(ui, fh)()
         else:
             raise error.BundleValueError(
                 'negative payload chunk size: %s' % chunksize)
 
-        chunksize = _unpack(_fpayloadsize, readexactly(fh, headersize))[0]
+        s = read(headersize)
+        if len(s) < headersize:
+            raise error.Abort(_('stream ended unexpectedly '
+                                ' (got %d bytes, expected %d)') %
+                              (len(s), chunksize))
+
+        chunksize = _unpack(_fpayloadsize, s)[0]
 
         # indebug() inlined for performance.
         if dolog: