341 parent_2, c_node_id, self->nodelen, |
341 parent_2, c_node_id, self->nodelen, |
342 sidedata_offset, sidedata_comp_len); |
342 sidedata_offset, sidedata_comp_len); |
343 } |
343 } |
344 } |
344 } |
345 /* |
345 /* |
|
346 * Pack header information in binary |
|
347 */ |
|
348 static PyObject *index_pack_header(indexObject *self, PyObject *args) |
|
349 { |
|
350 int header; |
|
351 char out[4]; |
|
352 if (!PyArg_ParseTuple(args, "I", &header)) { |
|
353 return NULL; |
|
354 } |
|
355 putbe32(header, out); |
|
356 return PyBytes_FromStringAndSize(out, 4); |
|
357 } |
|
358 /* |
346 * Return the raw binary string representing a revision |
359 * Return the raw binary string representing a revision |
347 */ |
360 */ |
348 static PyObject *index_entry_binary(indexObject *self, PyObject *args) |
361 static PyObject *index_entry_binary(indexObject *self, PyObject *value) |
349 { |
362 { |
350 long rev; |
363 long rev; |
351 int header; |
|
352 const char *data; |
364 const char *data; |
353 char entry[v2_hdrsize]; |
|
354 |
|
355 Py_ssize_t length = index_length(self); |
365 Py_ssize_t length = index_length(self); |
356 |
366 |
357 if (!PyArg_ParseTuple(args, "lI", &rev, &header)) { |
367 if (!pylong_to_long(value, &rev)) { |
358 return NULL; |
368 return NULL; |
359 } |
369 } |
360 if (rev < 0 || rev >= length) { |
370 if (rev < 0 || rev >= length) { |
361 PyErr_Format(PyExc_ValueError, "revlog index out of range: %ld", |
371 PyErr_Format(PyExc_ValueError, "revlog index out of range: %ld", |
362 rev); |
372 rev); |
365 |
375 |
366 data = index_deref(self, rev); |
376 data = index_deref(self, rev); |
367 if (data == NULL) |
377 if (data == NULL) |
368 return NULL; |
378 return NULL; |
369 if (rev == 0) { |
379 if (rev == 0) { |
370 /* put the header at the start of the first entry */ |
380 /* the header is eating the start of the first entry */ |
371 memcpy(entry, data, self->hdrsize); |
381 return PyBytes_FromStringAndSize(data + 4, self->hdrsize - 4); |
372 putbe32(header, entry); |
|
373 return PyBytes_FromStringAndSize(entry, self->hdrsize); |
|
374 } |
382 } |
375 return PyBytes_FromStringAndSize(data, self->hdrsize); |
383 return PyBytes_FromStringAndSize(data, self->hdrsize); |
376 } |
384 } |
377 |
385 |
378 /* |
386 /* |
2889 {"partialmatch", (PyCFunction)index_partialmatch, METH_VARARGS, |
2897 {"partialmatch", (PyCFunction)index_partialmatch, METH_VARARGS, |
2890 "match a potentially ambiguous node ID"}, |
2898 "match a potentially ambiguous node ID"}, |
2891 {"shortest", (PyCFunction)index_shortest, METH_VARARGS, |
2899 {"shortest", (PyCFunction)index_shortest, METH_VARARGS, |
2892 "find length of shortest hex nodeid of a binary ID"}, |
2900 "find length of shortest hex nodeid of a binary ID"}, |
2893 {"stats", (PyCFunction)index_stats, METH_NOARGS, "stats for the index"}, |
2901 {"stats", (PyCFunction)index_stats, METH_NOARGS, "stats for the index"}, |
2894 {"entry_binary", (PyCFunction)index_entry_binary, METH_VARARGS, |
2902 {"entry_binary", (PyCFunction)index_entry_binary, METH_O, |
2895 "return an entry in binary form"}, |
2903 "return an entry in binary form"}, |
|
2904 {"pack_header", (PyCFunction)index_pack_header, METH_VARARGS, |
|
2905 "pack the revlog header information into binary"}, |
2896 {NULL} /* Sentinel */ |
2906 {NULL} /* Sentinel */ |
2897 }; |
2907 }; |
2898 |
2908 |
2899 static PyGetSetDef index_getset[] = { |
2909 static PyGetSetDef index_getset[] = { |
2900 {"nodemap", (getter)index_nodemap, NULL, "nodemap", NULL}, |
2910 {"nodemap", (getter)index_nodemap, NULL, "nodemap", NULL}, |