Patchwork [STABLE] nodemap: fix validity checking when revlog is too short

login
register
mail settings
Submitter Pierre-Yves David
Date June 13, 2020, 11:15 a.m.
Message ID <ad7e7c2b78bed2b4036d.1592046925@nodosa.octobus.net>
Download mbox | patch
Permalink /patch/46501/
State Accepted
Headers show

Comments

Pierre-Yves David - June 13, 2020, 11:15 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1592042278 -7200
#      Sat Jun 13 11:57:58 2020 +0200
# Branch stable
# Node ID ad7e7c2b78bed2b4036d04cc2c0756f045b419e8
# Parent  9c515ea84b93341b14c5743f89b63a6194fb27d6
# EXP-Topic fix-nodemap-strip
# Available At https://foss.heptapod.net/octobus/mercurial-devel/
#              hg pull https://foss.heptapod.net/octobus/mercurial-devel/ -r ad7e7c2b78be
nodemap: fix validity checking when revlog is too short

We cannot check the nodeid of a revision that is not even there. We add a simple
fix and simple test.
Yuya Nishihara - June 14, 2020, 3:10 a.m.
On Sat, 13 Jun 2020 13:15:25 +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@octobus.net>
> # Date 1592042278 -7200
> #      Sat Jun 13 11:57:58 2020 +0200
> # Branch stable
> # Node ID ad7e7c2b78bed2b4036d04cc2c0756f045b419e8
> # Parent  9c515ea84b93341b14c5743f89b63a6194fb27d6
> # EXP-Topic fix-nodemap-strip
> # Available At https://foss.heptapod.net/octobus/mercurial-devel/
> #              hg pull https://foss.heptapod.net/octobus/mercurial-devel/ -r ad7e7c2b78be
> nodemap: fix validity checking when revlog is too short

Queued for stable, thanks.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -651,7 +651,10 @@  class revlog(object):
                 nodemap_data = nodemaputil.persisted_data(self)
                 if nodemap_data is not None:
                     docket = nodemap_data[0]
-                    if d[0][docket.tip_rev][7] == docket.tip_node:
+                    if (
+                        len(d[0]) > docket.tip_rev
+                        and d[0][docket.tip_rev][7] == docket.tip_node
+                    ):
                         # no changelog tampering
                         self._nodemap_docket = docket
                         index.update_nodemap_data(*nodemap_data)
diff --git a/tests/test-persistent-nodemap.t b/tests/test-persistent-nodemap.t
--- a/tests/test-persistent-nodemap.t
+++ b/tests/test-persistent-nodemap.t
@@ -411,3 +411,25 @@  Check that a failing transaction will pr
   .hg/store/00changelog-????????????????.nd: size=123584, sha256=8c6cef6fd3d3fac291968793ee19a4be6d0b8375e9508bd5c7d4a8879e8df180 (glob) (pure !)
   .hg/store/00changelog-????????????????.nd: size=123584, sha256=eb9e9a4bcafdb5e1344bc8a0cbb3288b2106413b8efae6265fb8a7973d7e97f9 (glob) (rust !)
   .hg/store/00changelog-????????????????.nd: size=123136, sha256=4f504f5a834db3811ced50ab3e9e80bcae3581bb0f9b13a7a9f94b7fc34bcebe (glob) (no-pure no-rust !)
+
+Check that removing content does not confuse the nodemap
+--------------------------------------------------------
+
+removing data with rollback
+
+  $ echo aso > a
+  $ hg ci -m a4
+  $ hg rollback
+  repository tip rolled back to revision 5005 (undo commit)
+  working directory now based on revision 5005
+  $ hg id -r .
+  bae4d45c759e tip
+
+roming data with strip
+
+  $ echo aso > a
+  $ hg ci -m a4
+  $ hg --config extensions.strip= strip -r . --no-backup
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg id -r . --traceback
+  bae4d45c759e tip