Patchwork D7321: revlog: deal with nodemap deletion within the index

login
register
mail settings
Submitter phabricator
Date Nov. 9, 2019, 5:17 a.m.
Message ID <239450ecfaaaf9457d4aca11dbfe0c6e@localhost.localdomain>
Download mbox | patch
Permalink /patch/43020/
State Not Applicable
Headers show

Comments

phabricator - Nov. 9, 2019, 5:17 a.m.
marmoute updated this revision to Diff 17834.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7321?vs=17738&id=17834

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7321/new/

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

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

CHANGE DETAILS




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

Patch

diff --git a/mercurial/unionrepo.py b/mercurial/unionrepo.py
--- a/mercurial/unionrepo.py
+++ b/mercurial/unionrepo.py
@@ -83,7 +83,6 @@ 
                 node,
             )
             self.index.append(e)
-            self.nodemap[node] = n
             self.bundlerevs.add(n)
             n += 1
 
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -217,6 +217,13 @@ 
         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]]
+        super(revlogoldindex, self).__delitem__(i)
+
     def clearcaches(self):
         self.__dict__.pop('nodemap', None)
 
@@ -2431,8 +2438,6 @@ 
         self._revisioncache = None
         self._chaininfocache = {}
         self._chunkclear()
-        for x in pycompat.xrange(rev, len(self)):
-            del self.nodemap[self.node(x)]
 
         del self.index[rev:-1]
         self._nodepos = None
diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -55,6 +55,12 @@ 
             nodemap[n] = r
         return nodemap
 
+    def _stripnodes(self, start):
+        if 'nodemap' in vars(self):
+            for r in range(start, len(self)):
+                n = self[r][7]
+                del self.nodemap[n]
+
     def clearcaches(self):
         self.__dict__.pop('nodemap', None)
 
@@ -103,6 +109,7 @@ 
             raise ValueError(b"deleting slices only supports a:-1 with step 1")
         i = i.start
         self._check_index(i)
+        self._stripnodes(i)
         if i < self._lgt:
             self._data = self._data[: i * indexsize]
             self._lgt = i
@@ -140,6 +147,7 @@ 
             raise ValueError(b"deleting slices only supports a:-1 with step 1")
         i = i.start
         self._check_index(i)
+        self._stripnodes(i)
         if i < self._lgt:
             self._offsets = self._offsets[:i]
             self._lgt = i
diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -93,7 +93,6 @@ 
                 node,
             )
             self.index.append(e)
-            self.nodemap[node] = n
             self.bundlerevs.add(n)
             n += 1