[PATCH 1 of 5] streamclone: extract code for reading header fields
Gregory Szorc
gregory.szorc at gmail.com
Fri Jan 15 07:01:49 UTC 2016
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1452840534 28800
# Thu Jan 14 22:48:54 2016 -0800
# Node ID 2292827fab6b8c367617c14b4a509b79654a75f0
# Parent 63116d47cc3fd179c90b117397cc26341a381edb
streamclone: extract code for reading header fields
So it can be called from another consumer in a future patch.
diff --git a/mercurial/streamclone.py b/mercurial/streamclone.py
--- a/mercurial/streamclone.py
+++ b/mercurial/streamclone.py
@@ -337,40 +337,45 @@ def consumev1(repo, fp, filecount, bytec
elapsed = 0.001
repo.ui.progress(_('clone'), None)
repo.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') %
(util.bytecount(bytecount), elapsed,
util.bytecount(bytecount / elapsed)))
finally:
lock.release()
-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 '
'supported; got %s') % compression)
filecount, bytecount = struct.unpack('>QQ', fp.read(16))
requireslen = struct.unpack('>H', fp.read(2))[0]
requires = fp.read(requireslen)
if not requires.endswith('\0'):
raise error.Abort(_('malformed stream clone bundle: '
'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: '
'unsupported format: %s') %
', '.join(sorted(missingreqs)))
consumev1(repo, fp, filecount, bytecount)
More information about the Mercurial-devel
mailing list