142 # include <stdint.h> |
142 # include <stdint.h> |
143 # endif |
143 # endif |
144 static uint32_t ntohl(uint32_t x) |
144 static uint32_t ntohl(uint32_t x) |
145 { |
145 { |
146 return ((x & 0x000000ffUL) << 24) | |
146 return ((x & 0x000000ffUL) << 24) | |
147 ((x & 0x0000ff00UL) << 8) | |
147 ((x & 0x0000ff00UL) << 8) | |
148 ((x & 0x00ff0000UL) >> 8) | |
148 ((x & 0x00ff0000UL) >> 8) | |
149 ((x & 0xff000000UL) >> 24); |
149 ((x & 0xff000000UL) >> 24); |
150 } |
150 } |
151 #else |
151 #else |
152 /* not windows */ |
152 /* not windows */ |
153 # include <sys/types.h> |
153 # include <sys/types.h> |
154 # if defined __BEOS__ && !defined __HAIKU__ |
154 # if defined __BEOS__ && !defined __HAIKU__ |
297 const char *end = data + size; |
297 const char *end = data + size; |
298 char decode[64]; /* to enforce alignment with inline data */ |
298 char decode[64]; /* to enforce alignment with inline data */ |
299 |
299 |
300 while (data < end) { |
300 while (data < end) { |
301 unsigned int step; |
301 unsigned int step; |
302 |
302 |
303 memcpy(decode, data, 64); |
303 memcpy(decode, data, 64); |
304 offset_flags = ntohl(*((uint32_t *) (decode + 4))); |
304 offset_flags = ntohl(*((uint32_t *) (decode + 4))); |
305 if (n == 0) /* mask out version number for the first entry */ |
305 if (n == 0) /* mask out version number for the first entry */ |
306 offset_flags &= 0xFFFF; |
306 offset_flags &= 0xFFFF; |
307 else { |
307 else { |
342 if (!PyErr_Occurred()) |
342 if (!PyErr_Occurred()) |
343 PyErr_SetString(PyExc_ValueError, "corrupt index file"); |
343 PyErr_SetString(PyExc_ValueError, "corrupt index file"); |
344 return 0; |
344 return 0; |
345 } |
345 } |
346 |
346 |
347 /* create the nullid/nullrev entry in the nodemap and the |
347 /* create the nullid/nullrev entry in the nodemap and the |
348 * magic nullid entry in the index at [-1] */ |
348 * magic nullid entry in the index at [-1] */ |
349 entry = _build_idx_entry(nodemap, |
349 entry = _build_idx_entry(nodemap, |
350 nullrev, 0, 0, 0, -1, -1, -1, -1, nullid); |
350 nullrev, 0, 0, 0, -1, -1, -1, -1, nullid); |
351 if (!entry) |
351 if (!entry) |
352 return 0; |
352 return 0; |
353 if (inlined) { |
353 if (inlined) { |
354 err = PyList_Append(index, entry); |
354 err = PyList_Append(index, entry); |
370 */ |
370 */ |
371 static PyObject *parse_index(PyObject *self, PyObject *args) |
371 static PyObject *parse_index(PyObject *self, PyObject *args) |
372 { |
372 { |
373 const char *data; |
373 const char *data; |
374 int size, inlined; |
374 int size, inlined; |
375 PyObject *rval = NULL, *index = NULL, *nodemap = NULL, *cache = NULL; |
375 PyObject *rval = NULL, *index = NULL, *nodemap = NULL, *cache = NULL; |
376 PyObject *data_obj = NULL, *inlined_obj; |
376 PyObject *data_obj = NULL, *inlined_obj; |
377 |
377 |
378 if (!PyArg_ParseTuple(args, "s#O", &data, &size, &inlined_obj)) |
378 if (!PyArg_ParseTuple(args, "s#O", &data, &size, &inlined_obj)) |
379 return NULL; |
379 return NULL; |
380 inlined = inlined_obj && PyObject_IsTrue(inlined_obj); |
380 inlined = inlined_obj && PyObject_IsTrue(inlined_obj); |
381 |
381 |
382 /* If no data is inlined, we know the size of the index list in |
382 /* If no data is inlined, we know the size of the index list in |
383 * advance: size divided by size of one one revlog record (64 bytes) |
383 * advance: size divided by size of one one revlog record (64 bytes) |
384 * plus one for the nullid */ |
384 * plus one for the nullid */ |
385 index = inlined ? PyList_New(0) : PyList_New(size / 64 + 1); |
385 index = inlined ? PyList_New(0) : PyList_New(size / 64 + 1); |
386 if (!index) |
386 if (!index) |
387 goto quit; |
387 goto quit; |
388 |
388 |
389 nodemap = PyDict_New(); |
389 nodemap = PyDict_New(); |