Mercurial > hg-stable
comparison mercurial/bundle2.py @ 20804:db9d3991d2c6
bundle2: support bundling simple parameter
This changeset add bundling capacity for simple parameters, not value or any
special case are handled.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Wed, 19 Mar 2014 14:52:03 -0700 |
parents | 88db3e615319 |
children | c5aaeca0cfbf |
comparison
equal
deleted
inserted
replaced
20803:88db3e615319 | 20804:db9d3991d2c6 |
---|---|
19 - magic string | 19 - magic string |
20 - stream level parameters | 20 - stream level parameters |
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 ============================ |
28 | 28 |
29 All numbers are unsigned and big endian. | 29 All numbers are unsigned and big endian. |
35 | 35 |
36 :params size: (16 bits integer) | 36 :params size: (16 bits integer) |
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 |
51 ------------------------ | 55 ------------------------ |
52 | 56 |
59 | 63 |
60 Currently forced to 0 in the current state of the implementation | 64 Currently forced to 0 in the current state of the implementation |
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' |
77 | |
78 _fstreamparamsize = '>H' | |
68 | 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' |
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) | |
89 | 118 |
90 class unbundle20(object): | 119 class unbundle20(object): |
91 """interpret a bundle2 stream | 120 """interpret a bundle2 stream |
92 | 121 |
93 (this will eventually yield parts)""" | 122 (this will eventually yield parts)""" |