Patchwork D7362: revlog: deprecate direct `nodemap` access

login
register
mail settings
Submitter phabricator
Date Nov. 8, 2019, 4:29 p.m.
Message ID <differential-rev-PHID-DREV-cujockzfoaepjybftrq2-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/42967/
State Superseded
Headers show

Comments

phabricator - Nov. 8, 2019, 4:29 p.m.
marmoute created this revision.
Herald added a reviewer: indygreg.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Now that all in-core user have been updated to the new API, we can deprecated
  direct access to nodemap.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D7362

AFFECTED FILES
  mercurial/pure/parsers.py
  mercurial/revlog.py

CHANGE DETAILS




To: marmoute, indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -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
diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -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):