Mercurial > hg-stable
diff mercurial/cext/revlog.c @ 43600:bd87114ce341
index: add a `rev` method (API)
The new `index.rev(node)` is to be preferred over using `node
index.nodemap[node]`.
This get us closer to be able to remove the `nodemap` attribute of the index.
Differential Revision: https://phab.mercurial-scm.org/D7324
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sat, 09 Nov 2019 13:23:51 +0100 |
parents | 0c659fc20207 |
children | b56de57c45ce |
line wrap: on
line diff
--- a/mercurial/cext/revlog.c Fri Nov 08 13:26:55 2019 +0100 +++ b/mercurial/cext/revlog.c Sat Nov 09 13:23:51 2019 +0100 @@ -2073,6 +2073,21 @@ return PyBool_FromLong((long)ret); } +static PyObject *index_m_rev(indexObject *self, PyObject *val) +{ + char *node; + int rev; + + if (node_check(val, &node) == -1) + return NULL; + rev = index_find_node(self, node, 20); + if (rev >= -1) + return PyInt_FromLong(rev); + if (rev == -2) + raise_revlog_error(); + return NULL; +} + typedef uint64_t bitmask; /* @@ -2733,6 +2748,8 @@ {"get", (PyCFunction)index_m_get, METH_VARARGS, "get an index entry"}, {"has_node", (PyCFunction)index_m_has_node, METH_O, "return True if the node exist in the index"}, + {"rev", (PyCFunction)index_m_rev, METH_O, + "return `rev` associated with a node or raise RevlogError"}, {"computephasesmapsets", (PyCFunction)compute_phases_map_sets, METH_VARARGS, "compute phases"}, {"reachableroots2", (PyCFunction)reachableroots2, METH_VARARGS,