Show More
@@ -63,25 +63,8 b' The file starts with a version header:' | |||
|
63 | 63 | |
|
64 | 64 | - 1 unsigned byte: version number, starting at zero. |
|
65 | 65 | |
|
66 | ||
|
67 | The header is followed by the markers. Each marker is made of: | |
|
68 | ||
|
69 | - 1 unsigned byte: number of new changesets "N", can be zero. | |
|
70 | ||
|
71 | - 1 unsigned 32-bits integer: metadata size "M" in bytes. | |
|
72 | ||
|
73 | - 1 byte: a bit field. It is reserved for flags used in common | |
|
74 | obsolete marker operations, to avoid repeated decoding of metadata | |
|
75 | entries. | |
|
76 | ||
|
77 | - 20 bytes: obsoleted changeset identifier. | |
|
78 | ||
|
79 | - N*20 bytes: new changesets identifiers. | |
|
80 | ||
|
81 | - M bytes: metadata as a sequence of nul-terminated strings. Each | |
|
82 | string contains a key and a value, separated by a colon ':', without | |
|
83 | additional encoding. Keys cannot contain '\0' or ':' and values | |
|
84 | cannot contain '\0'. | |
|
66 | The header is followed by the markers. Marker format depend of the version. See | |
|
67 | comment associated with each format for details. | |
|
85 | 68 | |
|
86 | 69 | """ |
|
87 | 70 | import struct |
@@ -98,13 +81,6 b' from i18n import _' | |||
|
98 | 81 | # you have to rely on third party extension extension to enable this. |
|
99 | 82 | _enabled = False |
|
100 | 83 | |
|
101 | # data used for parsing and writing | |
|
102 | _fm0version = 0 | |
|
103 | _fm0fixed = '>BIB20s' | |
|
104 | _fm0node = '20s' | |
|
105 | _fm0fsize = struct.calcsize(_fm0fixed) | |
|
106 | _fm0fnodesize = struct.calcsize(_fm0node) | |
|
107 | ||
|
108 | 84 | ### obsolescence marker flag |
|
109 | 85 | |
|
110 | 86 | ## bumpedfix flag |
@@ -137,24 +113,31 b' from i18n import _' | |||
|
137 | 113 | # "bumped" here. |
|
138 | 114 | bumpedfix = 1 |
|
139 | 115 | |
|
140 | def _readmarkers(data): | |
|
141 | """Read and enumerate markers from raw data""" | |
|
142 | off = 0 | |
|
143 | diskversion = _unpack('>B', data[off:off + 1])[0] | |
|
144 | off += 1 | |
|
145 | if diskversion not in formats: | |
|
146 | raise util.Abort(_('parsing obsolete marker: unknown version %r') | |
|
147 | % diskversion) | |
|
148 | return diskversion, formats[diskversion][0](data, off) | |
|
149 | ||
|
150 | def encodemarkers(markers, addheader=False, version=_fm0version): | |
|
151 | # Kept separate from flushmarkers(), it will be reused for | |
|
152 | # markers exchange. | |
|
153 | encodeone = formats[version][1] | |
|
154 | if addheader: | |
|
155 | yield _pack('>B', _fm0version) | |
|
156 | for marker in markers: | |
|
157 | yield encodeone(marker) | |
|
116 | ## Parsing and writing of version "0" | |
|
117 | # | |
|
118 | # The header is followed by the markers. Each marker is made of: | |
|
119 | # | |
|
120 | # - 1 unsigned byte: number of new changesets "N", can be zero. | |
|
121 | # | |
|
122 | # - 1 unsigned 32-bits integer: metadata size "M" in bytes. | |
|
123 | # | |
|
124 | # - 1 byte: a bit field. It is reserved for flags used in common | |
|
125 | # obsolete marker operations, to avoid repeated decoding of metadata | |
|
126 | # entries. | |
|
127 | # | |
|
128 | # - 20 bytes: obsoleted changeset identifier. | |
|
129 | # | |
|
130 | # - N*20 bytes: new changesets identifiers. | |
|
131 | # | |
|
132 | # - M bytes: metadata as a sequence of nul-terminated strings. Each | |
|
133 | # string contains a key and a value, separated by a colon ':', without | |
|
134 | # additional encoding. Keys cannot contain '\0' or ':' and values | |
|
135 | # cannot contain '\0'. | |
|
136 | _fm0version = 0 | |
|
137 | _fm0fixed = '>BIB20s' | |
|
138 | _fm0node = '20s' | |
|
139 | _fm0fsize = struct.calcsize(_fm0fixed) | |
|
140 | _fm0fnodesize = struct.calcsize(_fm0node) | |
|
158 | 141 | |
|
159 | 142 | def _fm0readmarkers(data, off=0): |
|
160 | 143 | # Loop on markers |
@@ -229,6 +212,26 b' def _fm0encodeonemarker(marker):' | |||
|
229 | 212 | # <version> -> (decoder, encoder) |
|
230 | 213 | formats = {0: (_fm0readmarkers, _fm0encodeonemarker)} |
|
231 | 214 | |
|
215 | def _readmarkers(data): | |
|
216 | """Read and enumerate markers from raw data""" | |
|
217 | off = 0 | |
|
218 | diskversion = _unpack('>B', data[off:off + 1])[0] | |
|
219 | off += 1 | |
|
220 | if diskversion not in formats: | |
|
221 | raise util.Abort(_('parsing obsolete marker: unknown version %r') | |
|
222 | % diskversion) | |
|
223 | return diskversion, formats[diskversion][0](data, off) | |
|
224 | ||
|
225 | def encodemarkers(markers, addheader=False, version=_fm0version): | |
|
226 | # Kept separate from flushmarkers(), it will be reused for | |
|
227 | # markers exchange. | |
|
228 | encodeone = formats[version][1] | |
|
229 | if addheader: | |
|
230 | yield _pack('>B', _fm0version) | |
|
231 | for marker in markers: | |
|
232 | yield encodeone(marker) | |
|
233 | ||
|
234 | ||
|
232 | 235 | def encodemeta(meta): |
|
233 | 236 | """Return encoded metadata string to string mapping. |
|
234 | 237 |
General Comments 0
You need to be logged in to leave comments.
Login now