# HG changeset patch # User Pierre-Yves David # Date 1572735669 -3600 # Node ID 0c659fc2020738054b07549a68bc95c93c87a3e9 # Parent 642433629e20a723190aafccbf4688de3116ae7d index: add a `has_node` method (API) The new `index.has_node(node)` is to be preferred over: `node in index.nodemap`. This get us closer to be able to remove the `nodemap` attribute of the index. Differential Revision: https://phab.mercurial-scm.org/D7322 diff -r 642433629e20 -r 0c659fc20207 mercurial/cext/parsers.c --- a/mercurial/cext/parsers.c Sat Nov 09 05:54:22 2019 +0100 +++ b/mercurial/cext/parsers.c Sun Nov 03 00:01:09 2019 +0100 @@ -667,7 +667,7 @@ void manifest_module_init(PyObject *mod); void revlog_module_init(PyObject *mod); -static const int version = 13; +static const int version = 14; static void module_init(PyObject *mod) { diff -r 642433629e20 -r 0c659fc20207 mercurial/cext/revlog.c --- a/mercurial/cext/revlog.c Sat Nov 09 05:54:22 2019 +0100 +++ b/mercurial/cext/revlog.c Sun Nov 03 00:01:09 2019 +0100 @@ -2065,6 +2065,14 @@ } } +static PyObject *index_m_has_node(indexObject *self, PyObject *args) +{ + int ret = index_contains(self, args); + if (ret < 0) + return NULL; + return PyBool_FromLong((long)ret); +} + typedef uint64_t bitmask; /* @@ -2723,6 +2731,8 @@ {"clearcaches", (PyCFunction)index_clearcaches, METH_NOARGS, "clear the index caches"}, {"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"}, {"computephasesmapsets", (PyCFunction)compute_phases_map_sets, METH_VARARGS, "compute phases"}, {"reachableroots2", (PyCFunction)reachableroots2, METH_VARARGS, diff -r 642433629e20 -r 0c659fc20207 mercurial/policy.py --- a/mercurial/policy.py Sat Nov 09 05:54:22 2019 +0100 +++ b/mercurial/policy.py Sun Nov 03 00:01:09 2019 +0100 @@ -80,7 +80,7 @@ ('cext', 'bdiff'): 3, ('cext', 'mpatch'): 1, ('cext', 'osutil'): 4, - ('cext', 'parsers'): 13, + ('cext', 'parsers'): 14, } # map import request to other package or module diff -r 642433629e20 -r 0c659fc20207 mercurial/pure/parsers.py --- a/mercurial/pure/parsers.py Sat Nov 09 05:54:22 2019 +0100 +++ b/mercurial/pure/parsers.py Sun Nov 03 00:01:09 2019 +0100 @@ -55,6 +55,10 @@ nodemap[n] = r return nodemap + def has_node(self, node): + """return True if the node exist in the index""" + return node in self.nodemap + def _stripnodes(self, start): if 'nodemap' in vars(self): for r in range(start, len(self)): diff -r 642433629e20 -r 0c659fc20207 mercurial/revlog.py --- a/mercurial/revlog.py Sat Nov 09 05:54:22 2019 +0100 +++ b/mercurial/revlog.py Sun Nov 03 00:01:09 2019 +0100 @@ -213,6 +213,10 @@ nodemap[n] = r return nodemap + def has_node(self, node): + """return True if the node exist in the index""" + return node in self.nodemap + def append(self, tup): self.nodemap[tup[7]] = len(self) super(revlogoldindex, self).append(tup)