changeset 44309:6c07480d6659

nodemap: add a function to read the data from disk This changeset is small and mostly an excuse to introduce an API function reading the data from disk. Differential Revision: https://phab.mercurial-scm.org/D7836
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 15 Jan 2020 15:47:31 +0100
parents 5962fd0d1045
children daad3aace942
files mercurial/debugcommands.py mercurial/revlogutils/nodemap.py tests/test-completion.t tests/test-persistent-nodemap.t
diffstat 4 files changed, 25 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/debugcommands.py	Wed Jan 15 15:47:21 2020 +0100
+++ b/mercurial/debugcommands.py	Wed Jan 15 15:47:31 2020 +0100
@@ -2086,16 +2086,29 @@
 
 @command(
     b'debugnodemap',
-    [(b'', b'dump', False, _(b'write persistent binary nodemap on stdin'))],
+    [
+        (
+            b'',
+            b'dump-new',
+            False,
+            _(b'write a (new) persistent binary nodemap on stdin'),
+        ),
+        (b'', b'dump-disk', False, _(b'dump on-disk data on stdin')),
+    ],
 )
 def debugnodemap(ui, repo, **opts):
     """write and inspect on disk nodemap
     """
-    if opts['dump']:
+    if opts['dump_new']:
         unfi = repo.unfiltered()
         cl = unfi.changelog
         data = nodemap.persistent_data(cl.index)
         ui.write(data)
+    elif opts['dump_disk']:
+        unfi = repo.unfiltered()
+        cl = unfi.changelog
+        data = nodemap.persisted_data(cl)
+        ui.write(data)
 
 
 @command(
--- a/mercurial/revlogutils/nodemap.py	Wed Jan 15 15:47:21 2020 +0100
+++ b/mercurial/revlogutils/nodemap.py	Wed Jan 15 15:47:31 2020 +0100
@@ -22,6 +22,13 @@
         raise error.RevlogError(b'unknown node: %s' % x)
 
 
+def persisted_data(revlog):
+    """read the nodemap for a revlog from disk"""
+    if revlog.nodemap_file is None:
+        return None
+    return revlog.opener.tryread(revlog.nodemap_file)
+
+
 def setup_persistent_nodemap(tr, revlog):
     """Install whatever is needed transaction side to persist a nodemap on disk
 
--- a/tests/test-completion.t	Wed Jan 15 15:47:21 2020 +0100
+++ b/tests/test-completion.t	Wed Jan 15 15:47:31 2020 +0100
@@ -291,7 +291,7 @@
   debugmanifestfulltextcache: clear, add
   debugmergestate: 
   debugnamecomplete: 
-  debugnodemap: dump
+  debugnodemap: dump-new, dump-disk
   debugobsolete: flags, record-parents, rev, exclusive, index, delete, date, user, template
   debugp1copies: rev
   debugp2copies: rev
--- a/tests/test-persistent-nodemap.t	Wed Jan 15 15:47:21 2020 +0100
+++ b/tests/test-persistent-nodemap.t	Wed Jan 15 15:47:31 2020 +0100
@@ -10,9 +10,9 @@
   > exp-persistent-nodemap=yes
   > EOF
   $ hg debugbuilddag .+5000
-  $ hg debugnodemap --dump | f --sha256 --size
+  $ hg debugnodemap --dump-new | f --sha256 --size
   size=122880, sha256=b961925120e1c9bc345c199b2cc442abc477029fdece37ef9d99cbe59c0558b7
-  $ f --sha256 --bytes=256 --hexdump --size < .hg/store/00changelog.n
+  $ hg debugnodemap --dump-disk | f --sha256 --bytes=256 --hexdump --size
   size=122880, sha256=b961925120e1c9bc345c199b2cc442abc477029fdece37ef9d99cbe59c0558b7
   0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
   0010: ff ff ff ff ff ff ff ff ff ff fa c2 ff ff ff ff |................|