##// END OF EJS Templates
bundle2: support bundling simple parameter...
Pierre-Yves David -
r20804:db9d3991 default
parent child Browse files
Show More
@@ -21,7 +21,7 b' The format is architectured as follow'
21 - payload parts (any number)
21 - payload parts (any number)
22 - end of stream marker.
22 - end of stream marker.
23
23
24 The current implementation is limited to empty bundle.
24 The current implementation accept some stream level option but no part.
25
25
26 Details on the Binary format
26 Details on the Binary format
27 ============================
27 ============================
@@ -37,14 +37,18 b' Binary format is as follow'
37
37
38 The total number of Bytes used by the parameters
38 The total number of Bytes used by the parameters
39
39
40 Currently force to 0.
41
42 :params value: arbitrary number of Bytes
40 :params value: arbitrary number of Bytes
43
41
44 A blob of `params size` containing the serialized version of all stream level
42 A blob of `params size` containing the serialized version of all stream level
45 parameters.
43 parameters.
46
44
47 Currently always empty.
45 The blob contains a space separated list of parameters.
46
47 Parameter value are not supported yet.
48
49 Special character in param name are not supported yet.
50
51
48
52
49
53
50 Payload part
54 Payload part
@@ -61,32 +65,57 b' Binary format is as follow'
61 """
65 """
62
66
63 import util
67 import util
68 import struct
69
64 import changegroup
70 import changegroup
65 from i18n import _
71 from i18n import _
66
72
73 _pack = struct.pack
74 _unpack = struct.unpack
75
67 _magicstring = 'HG20'
76 _magicstring = 'HG20'
68
77
78 _fstreamparamsize = '>H'
79
69 class bundle20(object):
80 class bundle20(object):
70 """represent an outgoing bundle2 container
81 """represent an outgoing bundle2 container
71
82
72 People will eventually be able to add param and parts to this object and
83 Use the `addparam` method to add stream level parameter. Then call
73 generated a stream from it."""
84 `getchunks` to retrieve all the binary chunks of datathat compose the
85 bundle2 container.
86
87 This object does not support payload part yet."""
74
88
75 def __init__(self):
89 def __init__(self):
76 self._params = []
90 self._params = []
77 self._parts = []
91 self._parts = []
78
92
93 def addparam(self, name, value=None):
94 """add a stream level parameter"""
95 self._params.append((name, value))
96
79 def getchunks(self):
97 def getchunks(self):
80 yield _magicstring
98 yield _magicstring
81 # no support for any param yet
99 param = self._paramchunk()
82 # to be obviously fixed soon.
100 yield _pack(_fstreamparamsize, len(param))
83 assert not self._params
101 if param:
84 yield '\0\0'
102 yield param
103
85 # no support for parts
104 # no support for parts
86 # to be obviously fixed soon.
105 # to be obviously fixed soon.
87 assert not self._parts
106 assert not self._parts
88 yield '\0\0'
107 yield '\0\0'
89
108
109 def _paramchunk(self):
110 """return a encoded version of all stream parameters"""
111 blocks = []
112 for key, value in self._params:
113 # XXX no support for value yet
114 assert value is None
115 # XXX no escaping yet
116 blocks.append(key)
117 return ' '.join(blocks)
118
90 class unbundle20(object):
119 class unbundle20(object):
91 """interpret a bundle2 stream
120 """interpret a bundle2 stream
92
121
@@ -14,11 +14,15 b' Create an extension to test bundle2 API'
14 > cmdtable = {}
14 > cmdtable = {}
15 > command = cmdutil.command(cmdtable)
15 > command = cmdutil.command(cmdtable)
16 >
16 >
17 > @command('bundle2', [], '')
17 > @command('bundle2',
18 > def cmdbundle2(ui, repo):
18 > [('', 'param', [], 'stream level parameter'),],
19 > '')
20 > def cmdbundle2(ui, repo, **opts):
19 > """write a bundle2 container on standard ouput"""
21 > """write a bundle2 container on standard ouput"""
20 > bundle = bundle2.bundle20()
22 > bundler = bundle2.bundle20()
21 > for chunk in bundle.getchunks():
23 > for p in opts['param']:
24 > bundler.addparam(p)
25 > for chunk in bundler.getchunks():
22 > ui.write(chunk)
26 > ui.write(chunk)
23 >
27 >
24 > @command('unbundle2', [], '')
28 > @command('unbundle2', [], '')
@@ -42,12 +46,19 b' The extension requires a repo (currently'
42 $ hg add a
46 $ hg add a
43 $ hg commit -m 'a'
47 $ hg commit -m 'a'
44
48
45 Test simple generation of empty bundle
49
50 Empty bundle
51 =================
52
53 - no option
54 - no parts
55
56 Test bundling
46
57
47 $ hg bundle2
58 $ hg bundle2
48 HG20\x00\x00\x00\x00 (no-eol) (esc)
59 HG20\x00\x00\x00\x00 (no-eol) (esc)
49
60
50 Test parsing of an empty bundle
61 Test unbundling
51
62
52 $ hg bundle2 | hg unbundle2
63 $ hg bundle2 | hg unbundle2
53 options count: 0
64 options count: 0
@@ -60,3 +71,24 b' Test old style bundle are detected and r'
60 $ hg unbundle2 < ../bundle.hg
71 $ hg unbundle2 < ../bundle.hg
61 abort: unknown bundle version 10
72 abort: unknown bundle version 10
62 [255]
73 [255]
74
75 Test parameters
76 =================
77
78 - some options
79 - no parts
80
81 advisory parameters, no value
82 -------------------------------
83
84 Simplest possible parameters form
85
86 Test generation
87
88 $ hg bundle2 --param 'caution'
89 HG20\x00\x07caution\x00\x00 (no-eol) (esc)
90
91 Test generation multiple option
92
93 $ hg bundle2 --param 'caution' --param 'meal'
94 HG20\x00\x0ccaution meal\x00\x00 (no-eol) (esc)
General Comments 0
You need to be logged in to leave comments. Login now