Show More
@@ -0,0 +1,84 b'' | |||||
|
1 | # bundle2.py - generic container format to transmit arbitrary data. | |||
|
2 | # | |||
|
3 | # Copyright 2013 Facebook, Inc. | |||
|
4 | # | |||
|
5 | # This software may be used and distributed according to the terms of the | |||
|
6 | # GNU General Public License version 2 or any later version. | |||
|
7 | """Handling of the new bundle2 format | |||
|
8 | ||||
|
9 | The goal of bundle2 is to act as an atomically packet to transmit a set of | |||
|
10 | payloads in an application agnostic way. It consist in a sequence of "parts" | |||
|
11 | that will be handed to and processed by the application layer. | |||
|
12 | ||||
|
13 | ||||
|
14 | General format architecture | |||
|
15 | =========================== | |||
|
16 | ||||
|
17 | The format is architectured as follow | |||
|
18 | ||||
|
19 | - magic string | |||
|
20 | - stream level parameters | |||
|
21 | - payload parts (any number) | |||
|
22 | - end of stream marker. | |||
|
23 | ||||
|
24 | The current implementation is limited to empty bundle. | |||
|
25 | ||||
|
26 | Details on the Binary format | |||
|
27 | ============================ | |||
|
28 | ||||
|
29 | All numbers are unsigned and big endian. | |||
|
30 | ||||
|
31 | stream level parameters | |||
|
32 | ------------------------ | |||
|
33 | ||||
|
34 | Binary format is as follow | |||
|
35 | ||||
|
36 | :params size: (16 bits integer) | |||
|
37 | ||||
|
38 | The total number of Bytes used by the parameters | |||
|
39 | ||||
|
40 | Currently force to 0. | |||
|
41 | ||||
|
42 | :params value: arbitrary number of Bytes | |||
|
43 | ||||
|
44 | A blob of `params size` containing the serialized version of all stream level | |||
|
45 | parameters. | |||
|
46 | ||||
|
47 | Currently always empty. | |||
|
48 | ||||
|
49 | ||||
|
50 | Payload part | |||
|
51 | ------------------------ | |||
|
52 | ||||
|
53 | Binary format is as follow | |||
|
54 | ||||
|
55 | :header size: (16 bits inter) | |||
|
56 | ||||
|
57 | The total number of Bytes used by the part headers. When the header is empty | |||
|
58 | (size = 0) this is interpreted as the end of stream marker. | |||
|
59 | ||||
|
60 | Currently forced to 0 in the current state of the implementation | |||
|
61 | """ | |||
|
62 | ||||
|
63 | _magicstring = 'HG20' | |||
|
64 | ||||
|
65 | class bundle20(object): | |||
|
66 | """represent an outgoing bundle2 container | |||
|
67 | ||||
|
68 | People will eventually be able to add param and parts to this object and | |||
|
69 | generated a stream from it.""" | |||
|
70 | ||||
|
71 | def __init__(self): | |||
|
72 | self._params = [] | |||
|
73 | self._parts = [] | |||
|
74 | ||||
|
75 | def getchunks(self): | |||
|
76 | yield _magicstring | |||
|
77 | # no support for any param yet | |||
|
78 | # to be obviously fixed soon. | |||
|
79 | assert not self._params | |||
|
80 | yield '\0\0' | |||
|
81 | # no support for parts | |||
|
82 | # to be obviously fixed soon. | |||
|
83 | assert not self._parts | |||
|
84 | yield '\0\0' |
@@ -0,0 +1,36 b'' | |||||
|
1 | ||||
|
2 | Create an extension to test bundle2 API | |||
|
3 | ||||
|
4 | $ cat > bundle2.py << EOF | |||
|
5 | > """A small extension to test bundle2 implementation | |||
|
6 | > | |||
|
7 | > Current bundle2 implementation is far too limited to be used in any core | |||
|
8 | > code. We still need to be able to test it while it grow up. | |||
|
9 | > """ | |||
|
10 | > | |||
|
11 | > from mercurial import cmdutil | |||
|
12 | > from mercurial import bundle2 | |||
|
13 | > cmdtable = {} | |||
|
14 | > command = cmdutil.command(cmdtable) | |||
|
15 | > | |||
|
16 | > @command('bundle2', [], '') | |||
|
17 | > def cmdbundle2(ui, repo): | |||
|
18 | > """write a bundle2 container on standard ouput""" | |||
|
19 | > bundle = bundle2.bundle20() | |||
|
20 | > for chunk in bundle.getchunks(): | |||
|
21 | > ui.write(chunk) | |||
|
22 | > EOF | |||
|
23 | $ cat >> $HGRCPATH << EOF | |||
|
24 | > [extensions] | |||
|
25 | > bundle2=$TESTTMP/bundle2.py | |||
|
26 | > EOF | |||
|
27 | ||||
|
28 | The extension requires a repo (currently unused) | |||
|
29 | ||||
|
30 | $ hg init main | |||
|
31 | $ cd main | |||
|
32 | ||||
|
33 | Test simple generation of empty bundle | |||
|
34 | ||||
|
35 | $ hg bundle2 | |||
|
36 | HG20\x00\x00\x00\x00 (no-eol) (esc) |
General Comments 0
You need to be logged in to leave comments.
Login now