##// END OF EJS Templates
revlog: implement fast_rank retrieval in C...
pacien -
r49707:e633e660 default
parent child Browse files
Show More
@@ -33,6 +33,7 b' typedef struct {'
33 int abi_version;
33 int abi_version;
34 Py_ssize_t (*index_length)(const indexObject *);
34 Py_ssize_t (*index_length)(const indexObject *);
35 const char *(*index_node)(indexObject *, Py_ssize_t);
35 const char *(*index_node)(indexObject *, Py_ssize_t);
36 int (*fast_rank)(indexObject *, Py_ssize_t);
36 int (*index_parents)(PyObject *, int, int *);
37 int (*index_parents)(PyObject *, int, int *);
37 } Revlog_CAPI;
38 } Revlog_CAPI;
38
39
@@ -564,6 +565,34 b' static const char *index_node(indexObjec'
564 }
565 }
565
566
566 /*
567 /*
568 * Return the stored rank of a given revision if known, or rank_unknown
569 * otherwise.
570 *
571 * The rank of a revision is the size of the sub-graph it defines as a head.
572 * Equivalently, the rank of a revision `r` is the size of the set
573 * `ancestors(r)`, `r` included.
574 *
575 * This method returns the rank retrieved from the revlog in constant time. It
576 * makes no attempt at computing unknown values for versions of the revlog
577 * which do not persist the rank.
578 */
579 static int index_fast_rank(indexObject *self, Py_ssize_t pos)
580 {
581 Py_ssize_t length = index_length(self);
582 int rank;
583
584 if (self->format_version != format_cl2 || pos >= length) {
585 return rank_unknown;
586 }
587
588 if (pos == nullrev) {
589 return 0; /* convention */
590 }
591
592 return *(index_deref(self, pos) + entry_cl2_offset_rank);
593 }
594
595 /*
567 * Return the hash of the node corresponding to the given rev. The
596 * Return the hash of the node corresponding to the given rev. The
568 * rev is assumed to be existing. If not, an exception is set.
597 * rev is assumed to be existing. If not, an exception is set.
569 */
598 */
@@ -3248,10 +3277,7 b' bail:'
3248 static Revlog_CAPI CAPI = {
3277 static Revlog_CAPI CAPI = {
3249 /* increment the abi_version field upon each change in the Revlog_CAPI
3278 /* increment the abi_version field upon each change in the Revlog_CAPI
3250 struct or in the ABI of the listed functions */
3279 struct or in the ABI of the listed functions */
3251 2,
3280 3, index_length, index_node, index_fast_rank, HgRevlogIndex_GetParents,
3252 index_length,
3253 index_node,
3254 HgRevlogIndex_GetParents,
3255 };
3281 };
3256
3282
3257 void revlog_module_init(PyObject *mod)
3283 void revlog_module_init(PyObject *mod)
@@ -18,7 +18,7 b' use hg::revlog::{Node, RevlogIndex};'
18 use hg::{Graph, GraphError, Revision, WORKING_DIRECTORY_REVISION};
18 use hg::{Graph, GraphError, Revision, WORKING_DIRECTORY_REVISION};
19 use libc::{c_int, ssize_t};
19 use libc::{c_int, ssize_t};
20
20
21 const REVLOG_CABI_VERSION: c_int = 2;
21 const REVLOG_CABI_VERSION: c_int = 3;
22
22
23 #[repr(C)]
23 #[repr(C)]
24 pub struct Revlog_CAPI {
24 pub struct Revlog_CAPI {
@@ -29,6 +29,10 b' pub struct Revlog_CAPI {'
29 index: *mut revlog_capi::RawPyObject,
29 index: *mut revlog_capi::RawPyObject,
30 rev: ssize_t,
30 rev: ssize_t,
31 ) -> *const Node,
31 ) -> *const Node,
32 fast_rank: unsafe extern "C" fn(
33 index: *mut revlog_capi::RawPyObject,
34 rev: ssize_t,
35 ) -> ssize_t,
32 index_parents: unsafe extern "C" fn(
36 index_parents: unsafe extern "C" fn(
33 index: *mut revlog_capi::RawPyObject,
37 index: *mut revlog_capi::RawPyObject,
34 rev: c_int,
38 rev: c_int,
General Comments 0
You need to be logged in to leave comments. Login now