Comments
Patch
@@ -60,11 +60,11 @@ Binary format is as follow
Currently forced to 0 in the current state of the implementation
"""
import util
import changegroup
-
+from i18n import _
_magicstring = 'HG20'
class bundler(object):
"""represent an outgoing bundle2 container
@@ -91,14 +91,17 @@ class unbundler(object):
"""interpret a bundle2 stream
(this will eventually yield parts)"""
def __init__(self, fp):
- # assume the magic string is ok and drop it
- # to be obviously fixed soon.
self._fp = fp
- self._readexact(4)
+ header = self._readexact(4)
+ magic, version = header[0:2], header[2:4]
+ if magic != 'HG':
+ raise util.Abort(_('not a Mercurial bundle'))
+ if version != '20':
+ raise util.Abort(_('unknown bundle version %s') % version)
def _unpack(self, format):
"""unpack this struct format from the stream"""
data = self._readexact(struct.calcsize(format))
return _unpack(format, data)
@@ -36,10 +36,13 @@ Create an extension to test bundle2 API
The extension requires a repo (currently unused)
$ hg init main
$ cd main
+ $ touch a
+ $ hg add a
+ $ hg commit -m 'a'
Test simple generation of empty bundle
$ hg bundle2
HG20\x00\x00\x00\x00 (no-eol) (esc)
@@ -47,5 +50,13 @@ Test simple generation of empty bundle
Test parsing of an empty bundle
$ hg bundle2 | hg unbundle2
options count: 0
parts count: 0
+
+Test old style bundle are detected and refused
+
+ $ hg bundle --all ../bundle.hg
+ 1 changesets found
+ $ hg unbundle2 < ../bundle.hg
+ abort: unknown bundle version 10
+ [255]