changeset 27882:319b0bf6ecc9

streamclone: extract code for reading header fields So it can be called from another consumer in a future patch.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 14 Jan 2016 22:48:54 -0800
parents ffa599f3f503
children 4f4b80b3f2bf
files mercurial/streamclone.py
diffstat 1 files changed, 15 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/streamclone.py	Sat Jan 16 18:30:01 2016 +0900
+++ b/mercurial/streamclone.py	Thu Jan 14 22:48:54 2016 -0800
@@ -329,16 +329,7 @@
                        (util.bytecount(bytecount), elapsed,
                         util.bytecount(bytecount / elapsed)))
 
-def applybundlev1(repo, fp):
-    """Apply the content from a stream clone bundle version 1.
-
-    We assume the 4 byte header has been read and validated and the file handle
-    is at the 2 byte compression identifier.
-    """
-    if len(repo):
-        raise error.Abort(_('cannot apply stream clone bundle on non-empty '
-                            'repo'))
-
+def readbundle1header(fp):
     compression = fp.read(2)
     if compression != 'UN':
         raise error.Abort(_('only uncompressed stream clone bundles are '
@@ -353,6 +344,20 @@
                             'requirements not properly encoded'))
 
     requirements = set(requires.rstrip('\0').split(','))
+
+    return filecount, bytecount, requirements
+
+def applybundlev1(repo, fp):
+    """Apply the content from a stream clone bundle version 1.
+
+    We assume the 4 byte header has been read and validated and the file handle
+    is at the 2 byte compression identifier.
+    """
+    if len(repo):
+        raise error.Abort(_('cannot apply stream clone bundle on non-empty '
+                            'repo'))
+
+    filecount, bytecount, requirements = readbundle1header(fp)
     missingreqs = requirements - repo.supportedformats
     if missingreqs:
         raise error.Abort(_('unable to apply stream clone: '