Show More
@@ -60,6 +60,10 b' Binary format is as follow' | |||||
60 | Currently forced to 0 in the current state of the implementation |
|
60 | Currently forced to 0 in the current state of the implementation | |
61 | """ |
|
61 | """ | |
62 |
|
62 | |||
|
63 | import util | |||
|
64 | import changegroup | |||
|
65 | ||||
|
66 | ||||
63 | _magicstring = 'HG20' |
|
67 | _magicstring = 'HG20' | |
64 |
|
68 | |||
65 | class bundle20(object): |
|
69 | class bundle20(object): | |
@@ -82,3 +86,48 b' class bundle20(object):' | |||||
82 | # to be obviously fixed soon. |
|
86 | # to be obviously fixed soon. | |
83 | assert not self._parts |
|
87 | assert not self._parts | |
84 | yield '\0\0' |
|
88 | yield '\0\0' | |
|
89 | ||||
|
90 | class unbundle20(object): | |||
|
91 | """interpret a bundle2 stream | |||
|
92 | ||||
|
93 | (this will eventually yield parts)""" | |||
|
94 | ||||
|
95 | def __init__(self, fp): | |||
|
96 | # assume the magic string is ok and drop it | |||
|
97 | # to be obviously fixed soon. | |||
|
98 | self._fp = fp | |||
|
99 | self._readexact(4) | |||
|
100 | ||||
|
101 | def _unpack(self, format): | |||
|
102 | """unpack this struct format from the stream""" | |||
|
103 | data = self._readexact(struct.calcsize(format)) | |||
|
104 | return _unpack(format, data) | |||
|
105 | ||||
|
106 | def _readexact(self, size): | |||
|
107 | """read exactly <size> bytes from the stream""" | |||
|
108 | return changegroup.readexactly(self._fp, size) | |||
|
109 | ||||
|
110 | @util.propertycache | |||
|
111 | def params(self): | |||
|
112 | """dictionnary of stream level parameters""" | |||
|
113 | paramsize = self._readexact(2) | |||
|
114 | assert paramsize == '\0\0' | |||
|
115 | return {} | |||
|
116 | ||||
|
117 | def __iter__(self): | |||
|
118 | """yield all parts contained in the stream""" | |||
|
119 | # make sure param have been loaded | |||
|
120 | self.params | |||
|
121 | part = self._readpart() | |||
|
122 | while part is not None: | |||
|
123 | yield part | |||
|
124 | part = self._readpart() | |||
|
125 | ||||
|
126 | def _readpart(self): | |||
|
127 | """return None when an end of stream markers is reach""" | |||
|
128 | headersize = self._readexact(2) | |||
|
129 | assert headersize == '\0\0' | |||
|
130 | return None | |||
|
131 | ||||
|
132 | ||||
|
133 |
@@ -8,6 +8,7 b' Create an extension to test bundle2 API' | |||||
8 | > code. We still need to be able to test it while it grow up. |
|
8 | > code. We still need to be able to test it while it grow up. | |
9 | > """ |
|
9 | > """ | |
10 | > |
|
10 | > | |
|
11 | > import sys | |||
11 | > from mercurial import cmdutil |
|
12 | > from mercurial import cmdutil | |
12 | > from mercurial import bundle2 |
|
13 | > from mercurial import bundle2 | |
13 | > cmdtable = {} |
|
14 | > cmdtable = {} | |
@@ -19,6 +20,14 b' Create an extension to test bundle2 API' | |||||
19 | > bundle = bundle2.bundle20() |
|
20 | > bundle = bundle2.bundle20() | |
20 | > for chunk in bundle.getchunks(): |
|
21 | > for chunk in bundle.getchunks(): | |
21 | > ui.write(chunk) |
|
22 | > ui.write(chunk) | |
|
23 | > | |||
|
24 | > @command('unbundle2', [], '') | |||
|
25 | > def cmdunbundle2(ui, repo): | |||
|
26 | > """read a bundle2 container from standard input""" | |||
|
27 | > unbundler = bundle2.unbundle20(sys.stdin) | |||
|
28 | > ui.write('options count: %i\n' % len(unbundler.params)) | |||
|
29 | > parts = list(unbundler) | |||
|
30 | > ui.write('parts count: %i\n' % len(parts)) | |||
22 | > EOF |
|
31 | > EOF | |
23 | $ cat >> $HGRCPATH << EOF |
|
32 | $ cat >> $HGRCPATH << EOF | |
24 | > [extensions] |
|
33 | > [extensions] | |
@@ -34,3 +43,9 b' Test simple generation of empty bundle' | |||||
34 |
|
43 | |||
35 | $ hg bundle2 |
|
44 | $ hg bundle2 | |
36 | HG20\x00\x00\x00\x00 (no-eol) (esc) |
|
45 | HG20\x00\x00\x00\x00 (no-eol) (esc) | |
|
46 | ||||
|
47 | Test parsing of an empty bundle | |||
|
48 | ||||
|
49 | $ hg bundle2 | hg unbundle2 | |||
|
50 | options count: 0 | |||
|
51 | parts count: 0 |
General Comments 0
You need to be logged in to leave comments.
Login now