##// END OF EJS Templates
revlog: extract entry byte offsets into named constants...
pacien -
r49570:a9364de9 default
parent child Browse files
Show More
@@ -136,6 +136,20 b' static const long v2_entry_size = 96;'
136 136 static const long format_v1 = 1; /* Internal only, could be any number */
137 137 static const long format_v2 = 2; /* Internal only, could be any number */
138 138
139 static const long entry_offset_high = 0;
140 static const long entry_offset_offset_flags = 4;
141 static const long entry_offset_comp_len = 8;
142 static const long entry_offset_uncomp_len = 12;
143 static const long entry_offset_base_rev = 16;
144 static const long entry_offset_link_rev = 20;
145 static const long entry_offset_parent_1 = 24;
146 static const long entry_offset_parent_2 = 28;
147 static const long entry_offset_node_id = 32;
148 static const long entry_offset_sidedata_offset = 64;
149 static const long entry_offset_sidedata_comp_len = 72;
150 static const long entry_offset_all_comp_mode = 76;
151 static const long entry_offset_padding_start = 77;
152
139 153 static const char comp_mode_inline = 2;
140 154 static const char rank_unknown = -1;
141 155
@@ -206,8 +220,8 b' static inline int index_get_parents(inde'
206 220 {
207 221 const char *data = index_deref(self, rev);
208 222
209 ps[0] = getbe32(data + 24);
210 ps[1] = getbe32(data + 28);
223 ps[0] = getbe32(data + entry_offset_parent_1);
224 ps[1] = getbe32(data + entry_offset_parent_2);
211 225
212 226 /* If index file is corrupted, ps[] may point to invalid revisions. So
213 227 * there is a risk of buffer overflow to trust them unconditionally. */
@@ -254,12 +268,12 b' static inline int64_t index_get_start(in'
254 268 return 0;
255 269
256 270 data = index_deref(self, rev);
257 offset = getbe32(data + 4);
271 offset = getbe32(data + entry_offset_offset_flags);
258 272 if (rev == 0) {
259 273 /* mask out version number for the first entry */
260 274 offset &= 0xFFFF;
261 275 } else {
262 uint32_t offset_high = getbe32(data);
276 uint32_t offset_high = getbe32(data + entry_offset_high);
263 277 offset |= ((uint64_t)offset_high) << 32;
264 278 }
265 279 return (int64_t)(offset >> 16);
@@ -275,7 +289,7 b' static inline int index_get_length(index'
275 289
276 290 data = index_deref(self, rev);
277 291
278 tmp = (int)getbe32(data + 8);
292 tmp = (int)getbe32(data + entry_offset_comp_len);
279 293 if (tmp < 0) {
280 294 PyErr_Format(PyExc_OverflowError,
281 295 "revlog entry size out of bound (%d)", tmp);
@@ -320,7 +334,7 b' static PyObject *index_get(indexObject *'
320 334 if (data == NULL)
321 335 return NULL;
322 336
323 offset_flags = getbe32(data + 4);
337 offset_flags = getbe32(data + entry_offset_offset_flags);
324 338 /*
325 339 * The first entry on-disk needs the version number masked out,
326 340 * but this doesn't apply if entries are added to an empty index.
@@ -328,17 +342,17 b' static PyObject *index_get(indexObject *'
328 342 if (self->length && pos == 0)
329 343 offset_flags &= 0xFFFF;
330 344 else {
331 uint32_t offset_high = getbe32(data);
345 uint32_t offset_high = getbe32(data + entry_offset_high);
332 346 offset_flags |= ((uint64_t)offset_high) << 32;
333 347 }
334 348
335 comp_len = getbe32(data + 8);
336 uncomp_len = getbe32(data + 12);
337 base_rev = getbe32(data + 16);
338 link_rev = getbe32(data + 20);
339 parent_1 = getbe32(data + 24);
340 parent_2 = getbe32(data + 28);
341 c_node_id = data + 32;
349 comp_len = getbe32(data + entry_offset_comp_len);
350 uncomp_len = getbe32(data + entry_offset_uncomp_len);
351 base_rev = getbe32(data + entry_offset_base_rev);
352 link_rev = getbe32(data + entry_offset_link_rev);
353 parent_1 = getbe32(data + entry_offset_parent_1);
354 parent_2 = getbe32(data + entry_offset_parent_2);
355 c_node_id = data + entry_offset_node_id;
342 356
343 357 if (self->format_version == format_v1) {
344 358 sidedata_offset = 0;
@@ -346,10 +360,12 b' static PyObject *index_get(indexObject *'
346 360 data_comp_mode = comp_mode_inline;
347 361 sidedata_comp_mode = comp_mode_inline;
348 362 } else {
349 sidedata_offset = getbe64(data + 64);
350 sidedata_comp_len = getbe32(data + 72);
351 data_comp_mode = data[76] & 3;
352 sidedata_comp_mode = ((data[76] >> 2) & 3);
363 sidedata_offset = getbe64(data + entry_offset_sidedata_offset);
364 sidedata_comp_len =
365 getbe32(data + entry_offset_sidedata_comp_len);
366 data_comp_mode = data[entry_offset_all_comp_mode] & 3;
367 sidedata_comp_mode =
368 ((data[entry_offset_all_comp_mode] >> 2) & 3);
353 369 }
354 370
355 371 return Py_BuildValue(tuple_format, offset_flags, comp_len, uncomp_len,
@@ -421,7 +437,7 b' static const char *index_node(indexObjec'
421 437 return NULL;
422 438
423 439 data = index_deref(self, pos);
424 return data ? data + 32 : NULL;
440 return data ? data + entry_offset_node_id : NULL;
425 441 }
426 442
427 443 /*
@@ -504,25 +520,28 b' static PyObject *index_append(indexObjec'
504 520 }
505 521 rev = self->length + self->new_length;
506 522 data = self->added + self->entry_size * self->new_length++;
507 putbe32(offset_flags >> 32, data);
508 putbe32(offset_flags & 0xffffffffU, data + 4);
509 putbe32(comp_len, data + 8);
510 putbe32(uncomp_len, data + 12);
511 putbe32(base_rev, data + 16);
512 putbe32(link_rev, data + 20);
513 putbe32(parent_1, data + 24);
514 putbe32(parent_2, data + 28);
515 memcpy(data + 32, c_node_id, c_node_id_len);
523 putbe32(offset_flags >> 32, data + entry_offset_high);
524 putbe32(offset_flags & 0xffffffffU, data + entry_offset_offset_flags);
525 putbe32(comp_len, data + entry_offset_comp_len);
526 putbe32(uncomp_len, data + entry_offset_uncomp_len);
527 putbe32(base_rev, data + entry_offset_base_rev);
528 putbe32(link_rev, data + entry_offset_link_rev);
529 putbe32(parent_1, data + entry_offset_parent_1);
530 putbe32(parent_2, data + entry_offset_parent_2);
531 memcpy(data + entry_offset_node_id, c_node_id, c_node_id_len);
516 532 /* Padding since SHA-1 is only 20 bytes for now */
517 memset(data + 32 + c_node_id_len, 0, 32 - c_node_id_len);
533 memset(data + entry_offset_node_id + c_node_id_len, 0,
534 entry_offset_node_id - c_node_id_len);
518 535 if (self->format_version == format_v2) {
519 putbe64(sidedata_offset, data + 64);
520 putbe32(sidedata_comp_len, data + 72);
536 putbe64(sidedata_offset, data + entry_offset_sidedata_offset);
537 putbe32(sidedata_comp_len,
538 data + entry_offset_sidedata_comp_len);
521 539 comp_field = data_comp_mode & 3;
522 540 comp_field = comp_field | (sidedata_comp_mode & 3) << 2;
523 data[76] = comp_field;
541 data[entry_offset_all_comp_mode] = comp_field;
524 542 /* Padding for 96 bytes alignment */
525 memset(data + 77, 0, self->entry_size - 77);
543 memset(data + entry_offset_padding_start, 0,
544 self->entry_size - entry_offset_padding_start);
526 545 }
527 546
528 547 if (self->ntinitialized)
@@ -577,10 +596,12 b' static PyObject *index_replace_sidedata_'
577 596 /* Find the newly added node, offset from the "already on-disk" length
578 597 */
579 598 data = self->added + self->entry_size * (rev - self->length);
580 putbe64(offset_flags, data);
581 putbe64(sidedata_offset, data + 64);
582 putbe32(sidedata_comp_len, data + 72);
583 data[76] = (data[76] & ~(3 << 2)) | ((comp_mode & 3) << 2);
599 putbe64(offset_flags, data + entry_offset_high);
600 putbe64(sidedata_offset, data + entry_offset_sidedata_offset);
601 putbe32(sidedata_comp_len, data + entry_offset_sidedata_comp_len);
602 data[entry_offset_all_comp_mode] =
603 (data[entry_offset_all_comp_mode] & ~(3 << 2)) |
604 ((comp_mode & 3) << 2);
584 605
585 606 Py_RETURN_NONE;
586 607 }
@@ -1123,7 +1144,7 b' static inline int index_baserev(indexObj'
1123 1144 data = index_deref(self, rev);
1124 1145 if (data == NULL)
1125 1146 return -2;
1126 result = getbe32(data + 16);
1147 result = getbe32(data + entry_offset_base_rev);
1127 1148
1128 1149 if (result > rev) {
1129 1150 PyErr_Format(
@@ -2735,9 +2756,10 b' static Py_ssize_t inline_scan(indexObjec'
2735 2756 while (pos + self->entry_size <= end && pos >= 0) {
2736 2757 uint32_t comp_len, sidedata_comp_len = 0;
2737 2758 /* 3rd element of header is length of compressed inline data */
2738 comp_len = getbe32(data + pos + 8);
2759 comp_len = getbe32(data + pos + entry_offset_comp_len);
2739 2760 if (self->entry_size == v2_entry_size) {
2740 sidedata_comp_len = getbe32(data + pos + 72);
2761 sidedata_comp_len = getbe32(
2762 data + pos + entry_offset_sidedata_comp_len);
2741 2763 }
2742 2764 incr = self->entry_size + comp_len + sidedata_comp_len;
2743 2765 if (offsets)
General Comments 0
You need to be logged in to leave comments. Login now