[Updated] [+- ] D12494: [RFC] rust-revlog: create nodemap on the fly if it's not persisted

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Mon May 9 19:13:48 UTC 2022


martinvonz updated this revision to Diff 33396.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D12494?vs=33191&id=33396

BRANCH
  default

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

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

AFFECTED FILES
  rust/hg-core/src/revlog/revlog.rs

CHANGE DETAILS

diff --git a/rust/hg-core/src/revlog/revlog.rs b/rust/hg-core/src/revlog/revlog.rs
--- a/rust/hg-core/src/revlog/revlog.rs
+++ b/rust/hg-core/src/revlog/revlog.rs
@@ -18,7 +18,7 @@
 use crate::errors::HgError;
 use crate::revlog::Revision;
 use crate::vfs::Vfs;
-use crate::{Node, NULL_REVISION};
+use crate::{Node, RevlogIndex, NULL_REVISION};
 
 const REVISION_FLAG_CENSORED: u16 = 1 << 15;
 const REVISION_FLAG_ELLIPSIS: u16 = 1 << 14;
@@ -115,14 +115,23 @@
         } else if !use_nodemap {
             None
         } else {
-            NodeMapDocket::read_from_file(store_vfs, index_path)?.map(
-                |(docket, data)| {
-                    nodemap::NodeTree::load_bytes(
-                        Box::new(data),
-                        docket.data_length,
-                    )
-                },
-            )
+            if let Some((docket, data)) =
+                NodeMapDocket::read_from_file(store_vfs, index_path)?
+            {
+                Some(nodemap::NodeTree::load_bytes(
+                    Box::new(data),
+                    docket.data_length,
+                ))
+            } else {
+                let mut nodemap = nodemap::NodeTree::default();
+                for rev in 0..index.len() {
+                    let rev = rev as Revision;
+                    nodemap
+                        .insert(&index, index.node(rev).unwrap(), rev)
+                        .unwrap();
+                }
+                Some(nodemap)
+            }
         };
 
         Ok(Revlog {



To: martinvonz, #hg-reviewers
Cc: marmoute, Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20220509/f293f50b/attachment-0001.html>


More information about the Mercurial-patches mailing list