changeset 43574:02802fa87b74

revlog: deprecate direct `nodemap` access Now that all in-core user have been updated to the new API, we can deprecated direct access to nodemap. Differential Revision: https://phab.mercurial-scm.org/D7362
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 09 Nov 2019 13:23:55 +0100
parents d3df05bab081
children 67b4439c09b2
files mercurial/pure/parsers.py mercurial/revlog.py
diffstat 2 files changed, 34 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/pure/parsers.py	Sat Nov 09 13:23:55 2019 +0100
+++ b/mercurial/pure/parsers.py	Sat Nov 09 13:23:55 2019 +0100
@@ -47,8 +47,14 @@
 
 
 class BaseIndexObject(object):
+    @property
+    def nodemap(self):
+        msg = "index.nodemap is deprecated, " "use index.[has_node|rev|get_rev]"
+        util.nouideprecwarn(msg, b'5.3', stacklevel=2)
+        return self._nodemap
+
     @util.propertycache
-    def nodemap(self):
+    def _nodemap(self):
         nodemap = revlogutils.NodeMap({nullid: nullrev})
         for r in range(0, len(self)):
             n = self[r][7]
@@ -57,35 +63,35 @@
 
     def has_node(self, node):
         """return True if the node exist in the index"""
-        return node in self.nodemap
+        return node in self._nodemap
 
     def rev(self, node):
         """return a revision for a node
 
         If the node is unknown, raise a RevlogError"""
-        return self.nodemap[node]
+        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)
+        return self._nodemap.get(node)
 
     def _stripnodes(self, start):
-        if 'nodemap' in vars(self):
+        if '_nodemap' in vars(self):
             for r in range(start, len(self)):
                 n = self[r][7]
-                del self.nodemap[n]
+                del self._nodemap[n]
 
     def clearcaches(self):
-        self.__dict__.pop('nodemap', None)
+        self.__dict__.pop('_nodemap', None)
 
     def __len__(self):
         return self._lgt + len(self._extra)
 
     def append(self, tup):
-        if 'nodemap' in vars(self):
-            self.nodemap[tup[7]] = len(self)
+        if '_nodemap' in vars(self):
+            self._nodemap[tup[7]] = len(self)
         self._extra.append(tup)
 
     def _check_index(self, i):
--- a/mercurial/revlog.py	Sat Nov 09 13:23:55 2019 +0100
+++ b/mercurial/revlog.py	Sat Nov 09 13:23:55 2019 +0100
@@ -205,8 +205,14 @@
 
 
 class revlogoldindex(list):
+    @property
+    def nodemap(self):
+        msg = "index.nodemap is deprecated, " "use index.[has_node|rev|get_rev]"
+        util.nouideprecwarn(msg, b'5.3', stacklevel=2)
+        return self._nodemap
+
     @util.propertycache
-    def nodemap(self):
+    def _nodemap(self):
         nodemap = revlogutils.NodeMap({nullid: nullrev})
         for r in range(0, len(self)):
             n = self[r][7]
@@ -215,33 +221,33 @@
 
     def has_node(self, node):
         """return True if the node exist in the index"""
-        return node in self.nodemap
+        return node in self._nodemap
 
     def rev(self, node):
         """return a revision for a node
 
         If the node is unknown, raise a RevlogError"""
-        return self.nodemap[node]
+        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)
+        return self._nodemap.get(node)
 
     def append(self, tup):
-        self.nodemap[tup[7]] = len(self)
+        self._nodemap[tup[7]] = len(self)
         super(revlogoldindex, self).append(tup)
 
     def __delitem__(self, i):
         if not isinstance(i, slice) or not i.stop == -1 or i.step is not None:
             raise ValueError(b"deleting slices only supports a:-1 with step 1")
         for r in pycompat.xrange(i.start, len(self)):
-            del self.nodemap[self[r][7]]
+            del self._nodemap[self[r][7]]
         super(revlogoldindex, self).__delitem__(i)
 
     def clearcaches(self):
-        self.__dict__.pop('nodemap', None)
+        self.__dict__.pop('_nodemap', None)
 
     def __getitem__(self, i):
         if i == -1:
@@ -579,7 +585,6 @@
                 _(b"index %s is corrupted") % self.indexfile
             )
         self.index, self._chunkcache = d
-        self.nodemap = self.index.nodemap
         if not self._chunkcache:
             self._chunkclear()
         # revnum -> (chain-length, sum-delta-length)
@@ -650,8 +655,13 @@
         """iterate over all rev in this revlog (from start to stop)"""
         return storageutil.iterrevs(len(self), start=start, stop=stop)
 
-    @util.propertycache
+    @property
     def nodemap(self):
+        msg = (
+            "revlog.nodemap is deprecated, "
+            "use revlog.index.[has_node|rev|get_rev]"
+        )
+        util.nouideprecwarn(msg, b'5.3', stacklevel=2)
         return self.index.nodemap
 
     @property