##// END OF EJS Templates
revlog: introduce a compression mode for sidedata in the revlog index...
marmoute -
r48030:2b69555e default
parent child Browse files
Show More
@@ -106,6 +106,7 b' class bundlerevlog(revlog.revlog):'
106 0,
106 0,
107 0,
107 0,
108 revlog_constants.COMP_MODE_INLINE,
108 revlog_constants.COMP_MODE_INLINE,
109 revlog_constants.COMP_MODE_INLINE,
109 )
110 )
110 self.index.append(e)
111 self.index.append(e)
111 self.bundlerevs.add(n)
112 self.bundlerevs.add(n)
@@ -118,9 +118,9 b' static Py_ssize_t inline_scan(indexObjec'
118 static int index_find_node(indexObject *self, const char *node);
118 static int index_find_node(indexObject *self, const char *node);
119
119
120 #if LONG_MAX == 0x7fffffffL
120 #if LONG_MAX == 0x7fffffffL
121 static const char *const tuple_format = PY23("Kiiiiiis#KiB", "Kiiiiiiy#KiB");
121 static const char *const tuple_format = PY23("Kiiiiiis#KiBB", "Kiiiiiiy#KiBB");
122 #else
122 #else
123 static const char *const tuple_format = PY23("kiiiiiis#kiB", "kiiiiiiy#kiB");
123 static const char *const tuple_format = PY23("kiiiiiis#kiBB", "kiiiiiiy#kiBB");
124 #endif
124 #endif
125
125
126 /* A RevlogNG v1 index entry is 64 bytes long. */
126 /* A RevlogNG v1 index entry is 64 bytes long. */
@@ -296,7 +296,7 b' static PyObject *index_get(indexObject *'
296 uint64_t offset_flags, sidedata_offset;
296 uint64_t offset_flags, sidedata_offset;
297 int comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2,
297 int comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2,
298 sidedata_comp_len;
298 sidedata_comp_len;
299 char data_comp_mode;
299 char data_comp_mode, sidedata_comp_mode;
300 const char *c_node_id;
300 const char *c_node_id;
301 const char *data;
301 const char *data;
302 Py_ssize_t length = index_length(self);
302 Py_ssize_t length = index_length(self);
@@ -339,16 +339,18 b' static PyObject *index_get(indexObject *'
339 sidedata_offset = 0;
339 sidedata_offset = 0;
340 sidedata_comp_len = 0;
340 sidedata_comp_len = 0;
341 data_comp_mode = comp_mode_inline;
341 data_comp_mode = comp_mode_inline;
342 sidedata_comp_mode = comp_mode_inline;
342 } else {
343 } else {
343 sidedata_offset = getbe64(data + 64);
344 sidedata_offset = getbe64(data + 64);
344 sidedata_comp_len = getbe32(data + 72);
345 sidedata_comp_len = getbe32(data + 72);
345 data_comp_mode = data[76];
346 data_comp_mode = data[76] & 3;
347 sidedata_comp_mode = ((data[76] >> 2) & 3);
346 }
348 }
347
349
348 return Py_BuildValue(tuple_format, offset_flags, comp_len, uncomp_len,
350 return Py_BuildValue(tuple_format, offset_flags, comp_len, uncomp_len,
349 base_rev, link_rev, parent_1, parent_2, c_node_id,
351 base_rev, link_rev, parent_1, parent_2, c_node_id,
350 self->nodelen, sidedata_offset, sidedata_comp_len,
352 self->nodelen, sidedata_offset, sidedata_comp_len,
351 data_comp_mode);
353 data_comp_mode, sidedata_comp_mode);
352 }
354 }
353 /*
355 /*
354 * Pack header information in binary
356 * Pack header information in binary
@@ -449,16 +451,17 b' static PyObject *index_append(indexObjec'
449 {
451 {
450 uint64_t offset_flags, sidedata_offset;
452 uint64_t offset_flags, sidedata_offset;
451 int rev, comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2;
453 int rev, comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2;
452 char data_comp_mode;
454 char data_comp_mode, sidedata_comp_mode;
453 Py_ssize_t c_node_id_len, sidedata_comp_len;
455 Py_ssize_t c_node_id_len, sidedata_comp_len;
454 const char *c_node_id;
456 const char *c_node_id;
457 char comp_field;
455 char *data;
458 char *data;
456
459
457 if (!PyArg_ParseTuple(obj, tuple_format, &offset_flags, &comp_len,
460 if (!PyArg_ParseTuple(obj, tuple_format, &offset_flags, &comp_len,
458 &uncomp_len, &base_rev, &link_rev, &parent_1,
461 &uncomp_len, &base_rev, &link_rev, &parent_1,
459 &parent_2, &c_node_id, &c_node_id_len,
462 &parent_2, &c_node_id, &c_node_id_len,
460 &sidedata_offset, &sidedata_comp_len,
463 &sidedata_offset, &sidedata_comp_len,
461 &data_comp_mode)) {
464 &data_comp_mode, &sidedata_comp_mode)) {
462 PyErr_SetString(PyExc_TypeError, "11-tuple required");
465 PyErr_SetString(PyExc_TypeError, "11-tuple required");
463 return NULL;
466 return NULL;
464 }
467 }
@@ -467,12 +470,20 b' static PyObject *index_append(indexObjec'
467 PyErr_SetString(PyExc_TypeError, "invalid node");
470 PyErr_SetString(PyExc_TypeError, "invalid node");
468 return NULL;
471 return NULL;
469 }
472 }
470 if (self->format_version == format_v1 &&
473 if (self->format_version == format_v1) {
471 data_comp_mode != comp_mode_inline) {
474
472 PyErr_Format(PyExc_ValueError,
475 if (data_comp_mode != comp_mode_inline) {
473 "invalid data compression mode: %i",
476 PyErr_Format(PyExc_ValueError,
474 data_comp_mode);
477 "invalid data compression mode: %i",
475 return NULL;
478 data_comp_mode);
479 return NULL;
480 }
481 if (sidedata_comp_mode != comp_mode_inline) {
482 PyErr_Format(PyExc_ValueError,
483 "invalid sidedata compression mode: %i",
484 sidedata_comp_mode);
485 return NULL;
486 }
476 }
487 }
477
488
478 if (self->new_length == self->added_length) {
489 if (self->new_length == self->added_length) {
@@ -501,7 +512,9 b' static PyObject *index_append(indexObjec'
501 if (self->format_version == format_v2) {
512 if (self->format_version == format_v2) {
502 putbe64(sidedata_offset, data + 64);
513 putbe64(sidedata_offset, data + 64);
503 putbe32(sidedata_comp_len, data + 72);
514 putbe32(sidedata_comp_len, data + 72);
504 data[76] = (char)data_comp_mode;
515 comp_field = data_comp_mode & 3;
516 comp_field = comp_field | (sidedata_comp_mode & 3) << 2;
517 data[76] = comp_field;
505 /* Padding for 96 bytes alignment */
518 /* Padding for 96 bytes alignment */
506 memset(data + 77, 0, self->entry_size - 77);
519 memset(data + 77, 0, self->entry_size - 77);
507 }
520 }
@@ -2777,9 +2790,9 b' static int index_init(indexObject *self,'
2777 self->entry_size = v1_entry_size;
2790 self->entry_size = v1_entry_size;
2778 }
2791 }
2779
2792
2780 self->nullentry = Py_BuildValue(PY23("iiiiiiis#iiB", "iiiiiiiy#iiB"), 0,
2793 self->nullentry = Py_BuildValue(
2781 0, 0, -1, -1, -1, -1, nullid,
2794 PY23("iiiiiiis#iiBB", "iiiiiiiy#iiBB"), 0, 0, 0, -1, -1, -1, -1,
2782 self->nodelen, 0, 0, comp_mode_inline);
2795 nullid, self->nodelen, 0, 0, comp_mode_inline, comp_mode_inline);
2783
2796
2784 if (!self->nullentry)
2797 if (!self->nullentry)
2785 return -1;
2798 return -1;
@@ -66,6 +66,7 b' class BaseIndexObject(object):'
66 0,
66 0,
67 0,
67 0,
68 revlog_constants.COMP_MODE_INLINE,
68 revlog_constants.COMP_MODE_INLINE,
69 revlog_constants.COMP_MODE_INLINE,
69 )
70 )
70
71
71 @util.propertycache
72 @util.propertycache
@@ -147,7 +148,12 b' class BaseIndexObject(object):'
147
148
148 def _unpack_entry(self, data):
149 def _unpack_entry(self, data):
149 r = self.index_format.unpack(data)
150 r = self.index_format.unpack(data)
150 r = r + (0, 0, revlog_constants.COMP_MODE_INLINE)
151 r = r + (
152 0,
153 0,
154 revlog_constants.COMP_MODE_INLINE,
155 revlog_constants.COMP_MODE_INLINE,
156 )
151 return r
157 return r
152
158
153 def pack_header(self, header):
159 def pack_header(self, header):
@@ -315,10 +321,19 b' class Index2Mixin(object):'
315 self._extra[rev - self._lgt] = new
321 self._extra[rev - self._lgt] = new
316
322
317 def _unpack_entry(self, data):
323 def _unpack_entry(self, data):
318 return self.index_format.unpack(data)
324 data = self.index_format.unpack(data)
325 entry = data[:10]
326 data_comp = data[10] & 3
327 sidedata_comp = (data[10] & (3 << 2)) >> 2
328 return entry + (data_comp, sidedata_comp)
319
329
320 def _pack_entry(self, entry):
330 def _pack_entry(self, entry):
321 return self.index_format.pack(*entry[:11])
331 data = entry[:10]
332 data_comp = entry[10] & 3
333 sidedata_comp = (entry[11] & 3) << 2
334 data += (data_comp | sidedata_comp,)
335
336 return self.index_format.pack(*data)
322
337
323 def entry_binary(self, rev):
338 def entry_binary(self, rev):
324 """return the raw binary string representing a revision"""
339 """return the raw binary string representing a revision"""
@@ -345,6 +345,9 b' class revlog(object):'
345 (see "COMP_MODE_*" constants for details). For revlog version 0 and
345 (see "COMP_MODE_*" constants for details). For revlog version 0 and
346 1 this will always be COMP_MODE_INLINE.
346 1 this will always be COMP_MODE_INLINE.
347
347
348 [11] side-data compression mode:
349 two bits that detail the way the sidedata chunk is compressed on disk.
350 (see "COMP_MODE_*" constants for details)
348 """
351 """
349
352
350 _flagserrorclass = error.RevlogError
353 _flagserrorclass = error.RevlogError
@@ -2517,7 +2520,9 b' class revlog(object):'
2517 compression_mode = COMP_MODE_PLAIN
2520 compression_mode = COMP_MODE_PLAIN
2518 deltainfo = deltautil.drop_u_compression(deltainfo)
2521 deltainfo = deltautil.drop_u_compression(deltainfo)
2519
2522
2523 sidedata_compression_mode = COMP_MODE_INLINE
2520 if sidedata and self.hassidedata:
2524 if sidedata and self.hassidedata:
2525 sidedata_compression_mode = COMP_MODE_PLAIN
2521 serialized_sidedata = sidedatautil.serialize_sidedata(sidedata)
2526 serialized_sidedata = sidedatautil.serialize_sidedata(sidedata)
2522 sidedata_offset = offset + deltainfo.deltalen
2527 sidedata_offset = offset + deltainfo.deltalen
2523 else:
2528 else:
@@ -2539,6 +2544,7 b' class revlog(object):'
2539 sidedata_offset,
2544 sidedata_offset,
2540 len(serialized_sidedata),
2545 len(serialized_sidedata),
2541 compression_mode,
2546 compression_mode,
2547 sidedata_compression_mode,
2542 )
2548 )
2543
2549
2544 self.index.append(e)
2550 self.index.append(e)
@@ -55,6 +55,7 b' class revlogoldindex(list):'
55 0,
55 0,
56 0,
56 0,
57 COMP_MODE_INLINE,
57 COMP_MODE_INLINE,
58 COMP_MODE_INLINE,
58 )
59 )
59
60
60 @property
61 @property
@@ -70,6 +70,7 b' class unionrevlog(revlog.revlog):'
70 _sdo,
70 _sdo,
71 _sds,
71 _sds,
72 _dcm,
72 _dcm,
73 _sdcm,
73 ) = rev
74 ) = rev
74 flags = _start & 0xFFFF
75 flags = _start & 0xFFFF
75
76
@@ -105,6 +106,7 b' class unionrevlog(revlog.revlog):'
105 0, # sidedata offset
106 0, # sidedata offset
106 0, # sidedata size
107 0, # sidedata size
107 revlog_constants.COMP_MODE_INLINE,
108 revlog_constants.COMP_MODE_INLINE,
109 revlog_constants.COMP_MODE_INLINE,
108 )
110 )
109 self.index.append(e)
111 self.index.append(e)
110 self.bundlerevs.add(n)
112 self.bundlerevs.add(n)
@@ -52,7 +52,12 b' def py_parseindex(data, inline):'
52 cache = (0, data)
52 cache = (0, data)
53 while off <= l:
53 while off <= l:
54 e = struct.unpack(indexformatng, data[off : off + s])
54 e = struct.unpack(indexformatng, data[off : off + s])
55 e = e + (0, 0, constants.COMP_MODE_INLINE)
55 e = e + (
56 0,
57 0,
58 constants.COMP_MODE_INLINE,
59 constants.COMP_MODE_INLINE,
60 )
56 nodemap[e[7]] = n
61 nodemap[e[7]] = n
57 append(e)
62 append(e)
58 n += 1
63 n += 1
@@ -62,7 +67,12 b' def py_parseindex(data, inline):'
62 else:
67 else:
63 while off <= l:
68 while off <= l:
64 e = struct.unpack(indexformatng, data[off : off + s])
69 e = struct.unpack(indexformatng, data[off : off + s])
65 e = e + (0, 0, constants.COMP_MODE_INLINE)
70 e = e + (
71 0,
72 0,
73 constants.COMP_MODE_INLINE,
74 constants.COMP_MODE_INLINE,
75 )
66 nodemap[e[7]] = n
76 nodemap[e[7]] = n
67 append(e)
77 append(e)
68 n += 1
78 n += 1
@@ -257,6 +267,7 b' class parseindex2tests(unittest.TestCase'
257 0,
267 0,
258 0,
268 0,
259 constants.COMP_MODE_INLINE,
269 constants.COMP_MODE_INLINE,
270 constants.COMP_MODE_INLINE,
260 )
271 )
261 index, junk = parsers.parse_index2(data_inlined, True)
272 index, junk = parsers.parse_index2(data_inlined, True)
262 got = index[-1]
273 got = index[-1]
@@ -291,6 +302,7 b' class parseindex2tests(unittest.TestCase'
291 0,
302 0,
292 0,
303 0,
293 constants.COMP_MODE_INLINE,
304 constants.COMP_MODE_INLINE,
305 constants.COMP_MODE_INLINE,
294 )
306 )
295 index.append(e)
307 index.append(e)
296
308
General Comments 0
You need to be logged in to leave comments. Login now