index: add a `get_rev` method (API)
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sat, 09 Nov 2019 13:23:51 +0100
changeset 43554 b56de57c45ce
parent 43553 2da51e292734
child 43555 ded3d545b6f0
index: add a `get_rev` method (API) The new `index.getrev(node)` is to be preferred over using: `index.nodemap.get(node)`. This get us closer to be able to remove the `nodemap` attribute of the index. Differential Revision: https://phab.mercurial-scm.org/D7326
mercurial/cext/parsers.c
mercurial/cext/revlog.c
mercurial/policy.py
mercurial/pure/parsers.py
mercurial/revlog.py
--- a/mercurial/cext/parsers.c	Sat Nov 09 13:23:51 2019 +0100
+++ b/mercurial/cext/parsers.c	Sat Nov 09 13:23:51 2019 +0100
@@ -667,7 +667,7 @@
 void manifest_module_init(PyObject *mod);
 void revlog_module_init(PyObject *mod);
 
-static const int version = 15;
+static const int version = 16;
 
 static void module_init(PyObject *mod)
 {
--- a/mercurial/cext/revlog.c	Sat Nov 09 13:23:51 2019 +0100
+++ b/mercurial/cext/revlog.c	Sat Nov 09 13:23:51 2019 +0100
@@ -2746,6 +2746,8 @@
     {"clearcaches", (PyCFunction)index_clearcaches, METH_NOARGS,
      "clear the index caches"},
     {"get", (PyCFunction)index_m_get, METH_VARARGS, "get an index entry"},
+    {"get_rev", (PyCFunction)index_m_get, METH_VARARGS,
+     "return `rev` associated with a node or None"},
     {"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,
--- a/mercurial/policy.py	Sat Nov 09 13:23:51 2019 +0100
+++ b/mercurial/policy.py	Sat Nov 09 13:23:51 2019 +0100
@@ -80,7 +80,7 @@
     ('cext', 'bdiff'): 3,
     ('cext', 'mpatch'): 1,
     ('cext', 'osutil'): 4,
-    ('cext', 'parsers'): 15,
+    ('cext', 'parsers'): 16,
 }
 
 # map import request to other package or module
--- a/mercurial/pure/parsers.py	Sat Nov 09 13:23:51 2019 +0100
+++ b/mercurial/pure/parsers.py	Sat Nov 09 13:23:51 2019 +0100
@@ -65,6 +65,12 @@
         If the node is unknown, raise a RevlogError"""
         return self.nodemap[node]
 
+    def get_rev(self, node):
+        """return a revision for a node
+
+        If the node is unknown, return None"""
+        return self.nodemap.get(node)
+
     def _stripnodes(self, start):
         if 'nodemap' in vars(self):
             for r in range(start, len(self)):
--- a/mercurial/revlog.py	Sat Nov 09 13:23:51 2019 +0100
+++ b/mercurial/revlog.py	Sat Nov 09 13:23:51 2019 +0100
@@ -223,6 +223,12 @@
         If the node is unknown, raise a RevlogError"""
         return self.nodemap[node]
 
+    def get_rev(self, node):
+        """return a revision for a node
+
+        If the node is unknown, return None"""
+        return self.nodemap.get(node)
+
     def append(self, tup):
         self.nodemap[tup[7]] = len(self)
         super(revlogoldindex, self).append(tup)