changeset 52182:bd8081e9fd62

rust: don't star export from the `revlog` module This made a lot of the imports confusing because they didn't make sense at the top level (so, outside of `revlog`), and they hide the more common types when autocompleting.
author Raphaël Gomès <rgomes@octobus.net>
date Thu, 26 Sep 2024 14:26:24 +0200
parents 3d797007905d
children 82007b8c189e
files rust/hg-core/examples/nodemap/index.rs rust/hg-core/src/lib.rs rust/hg-core/src/operations/cat.rs rust/hg-core/src/operations/debugdata.rs rust/hg-core/src/repo.rs rust/hg-core/src/revlog/index.rs rust/hg-core/src/revlog/mod.rs rust/hg-core/src/revlog/patch.rs rust/hg-core/src/update.rs rust/hg-core/src/vfs.rs rust/hg-cpython/src/conversion.rs rust/hg-cpython/src/revlog.rs rust/rhg/src/commands/debugdata.rs rust/rhg/src/commands/status.rs
diffstat 14 files changed, 54 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/examples/nodemap/index.rs	Thu Aug 01 11:27:20 2024 +0200
+++ b/rust/hg-core/examples/nodemap/index.rs	Thu Sep 26 14:26:24 2024 +0200
@@ -4,6 +4,7 @@
 // GNU General Public License version 2 or any later version.
 
 //! Minimal `RevlogIndex`, readable from standard Mercurial file format
+use hg::revlog::RevlogIndex;
 use hg::*;
 use memmap2::*;
 use std::fs::File;
--- a/rust/hg-core/src/lib.rs	Thu Aug 01 11:27:20 2024 +0200
+++ b/rust/hg-core/src/lib.rs	Thu Sep 26 14:26:24 2024 +0200
@@ -30,7 +30,12 @@
 pub mod matchers;
 pub mod repo;
 pub mod revlog;
-pub use revlog::*;
+// Export very common types to make discovery easier
+pub use revlog::{
+    BaseRevision, Graph, GraphError, Node, NodePrefix, Revision,
+    UncheckedRevision, NULL_NODE, NULL_NODE_ID, NULL_REVISION,
+    WORKING_DIRECTORY_HEX, WORKING_DIRECTORY_REVISION,
+};
 pub mod checkexec;
 pub mod config;
 pub mod lock;
--- a/rust/hg-core/src/operations/cat.rs	Thu Aug 01 11:27:20 2024 +0200
+++ b/rust/hg-core/src/operations/cat.rs	Thu Sep 26 14:26:24 2024 +0200
@@ -12,8 +12,8 @@
 use crate::utils::hg_path::HgPath;
 
 use crate::errors::HgError;
-use crate::manifest::Manifest;
-use crate::manifest::ManifestEntry;
+use crate::revlog::manifest::Manifest;
+use crate::revlog::manifest::ManifestEntry;
 use itertools::put_back;
 use itertools::PutBack;
 use std::cmp::Ordering;
--- a/rust/hg-core/src/operations/debugdata.rs	Thu Aug 01 11:27:20 2024 +0200
+++ b/rust/hg-core/src/operations/debugdata.rs	Thu Sep 26 14:26:24 2024 +0200
@@ -6,10 +6,10 @@
 // GNU General Public License version 2 or any later version.
 
 use crate::errors::HgError;
+use crate::exit_codes;
 use crate::repo::Repo;
 use crate::revlog::options::default_revlog_options;
-use crate::revlog::Revlog;
-use crate::{exit_codes, RevlogError, RevlogType};
+use crate::revlog::{Revlog, RevlogError, RevlogType};
 
 /// Dump the contents data of a revision.
 pub fn debug_data(
--- a/rust/hg-core/src/repo.rs	Thu Aug 01 11:27:20 2024 +0200
+++ b/rust/hg-core/src/repo.rs	Thu Sep 26 14:26:24 2024 +0200
@@ -1,4 +1,3 @@
-use crate::changelog::Changelog;
 use crate::config::{Config, ConfigError, ConfigParseError};
 use crate::dirstate::DirstateParents;
 use crate::dirstate_tree::dirstate_map::{
@@ -9,20 +8,19 @@
 use crate::errors::HgResultExt;
 use crate::errors::{HgError, IoResultExt};
 use crate::lock::{try_with_lock_no_wait, LockError};
-use crate::manifest::{Manifest, Manifestlog};
-use crate::options::default_revlog_options;
 use crate::requirements::DIRSTATE_TRACKED_HINT_V1;
+use crate::revlog::changelog::Changelog;
 use crate::revlog::filelog::Filelog;
-use crate::revlog::RevlogError;
+use crate::revlog::manifest::{Manifest, Manifestlog};
+use crate::revlog::options::default_revlog_options;
+use crate::revlog::{RevlogError, RevlogType};
 use crate::utils::debug::debug_wait_for_file_or_print;
 use crate::utils::files::get_path_from_bytes;
 use crate::utils::hg_path::HgPath;
 use crate::utils::SliceExt;
 use crate::vfs::{is_dir, is_file, Vfs, VfsImpl};
 use crate::DirstateError;
-use crate::{
-    exit_codes, requirements, NodePrefix, RevlogType, UncheckedRevision,
-};
+use crate::{exit_codes, requirements, NodePrefix, UncheckedRevision};
 use std::cell::{Ref, RefCell, RefMut};
 use std::collections::HashSet;
 use std::io::Seek;
--- a/rust/hg-core/src/revlog/index.rs	Thu Aug 01 11:27:20 2024 +0200
+++ b/rust/hg-core/src/revlog/index.rs	Thu Sep 26 14:26:24 2024 +0200
@@ -7,14 +7,14 @@
 use byteorder::{BigEndian, ByteOrder};
 use bytes_cast::{unaligned, BytesCast};
 
-use super::{NodePrefix, REVIDX_KNOWN_FLAGS};
+use super::{NodePrefix, RevlogError, RevlogIndex, REVIDX_KNOWN_FLAGS};
 use crate::errors::HgError;
-use crate::node::{NODE_BYTES_LENGTH, NULL_NODE, STORED_NODE_ID_BYTES};
-use crate::revlog::node::Node;
+use crate::revlog::node::{
+    Node, NODE_BYTES_LENGTH, NULL_NODE, STORED_NODE_ID_BYTES,
+};
 use crate::revlog::{Revision, NULL_REVISION};
 use crate::{
-    dagops, BaseRevision, FastHashMap, Graph, GraphError, RevlogError,
-    RevlogIndex, UncheckedRevision,
+    dagops, BaseRevision, FastHashMap, Graph, GraphError, UncheckedRevision,
 };
 
 pub const INDEX_ENTRY_SIZE: usize = 64;
@@ -1825,7 +1825,7 @@
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::node::NULL_NODE;
+    use crate::NULL_NODE;
 
     #[cfg(test)]
     #[derive(Debug, Copy, Clone)]
--- a/rust/hg-core/src/revlog/mod.rs	Thu Aug 01 11:27:20 2024 +0200
+++ b/rust/hg-core/src/revlog/mod.rs	Thu Sep 26 14:26:24 2024 +0200
@@ -13,7 +13,7 @@
 use inner_revlog::InnerRevlog;
 use inner_revlog::RevisionBuffer;
 use memmap2::MmapOptions;
-pub use node::{FromHexError, Node, NodePrefix};
+pub use node::{FromHexError, Node, NodePrefix, NULL_NODE, NULL_NODE_ID};
 use options::RevlogOpenOptions;
 pub mod changelog;
 pub mod compression;
@@ -31,13 +31,12 @@
 use std::ops::Deref;
 use std::path::Path;
 
-use self::node::NULL_NODE;
 use self::nodemap_docket::NodeMapDocket;
-use super::index::Index;
-use super::nodemap::{NodeMap, NodeMapError};
 use crate::errors::HgError;
 use crate::errors::IoResultExt;
 use crate::exit_codes;
+use crate::revlog::index::Index;
+use crate::revlog::nodemap::{NodeMap, NodeMapError};
 use crate::vfs::Vfs;
 use crate::vfs::VfsImpl;
 
@@ -724,7 +723,7 @@
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::index::IndexEntryBuilder;
+    use crate::revlog::index::IndexEntryBuilder;
     use itertools::Itertools;
 
     #[test]
--- a/rust/hg-core/src/revlog/patch.rs	Thu Aug 01 11:27:20 2024 +0200
+++ b/rust/hg-core/src/revlog/patch.rs	Thu Sep 26 14:26:24 2024 +0200
@@ -1,6 +1,6 @@
 use byteorder::{BigEndian, ByteOrder};
 
-use crate::RevlogError;
+use crate::revlog::RevlogError;
 
 use super::inner_revlog::RevisionBuffer;
 
@@ -229,7 +229,7 @@
 
 #[cfg(test)]
 mod tests {
-    use crate::inner_revlog::CoreRevisionBuffer;
+    use crate::revlog::inner_revlog::CoreRevisionBuffer;
 
     use super::*;
 
--- a/rust/hg-core/src/update.rs	Thu Aug 01 11:27:20 2024 +0200
+++ b/rust/hg-core/src/update.rs	Thu Sep 26 14:26:24 2024 +0200
@@ -14,14 +14,14 @@
         dirstate_map::DirstateEntryReset, on_disk::write_tracked_key,
     },
     errors::{HgError, IoResultExt},
-    exit_codes,
-    filelog::Filelog,
-    narrow,
-    node::NULL_NODE,
+    exit_codes, narrow,
     operations::{list_rev_tracked_files, ExpandedManifestEntry},
-    options::{default_revlog_options, RevlogOpenOptions},
     progress::Progress,
     repo::Repo,
+    revlog::filelog::Filelog,
+    revlog::node::NULL_NODE,
+    revlog::options::{default_revlog_options, RevlogOpenOptions},
+    revlog::RevlogError,
     sparse,
     utils::{
         files::{filesystem_now, get_path_from_bytes},
@@ -29,7 +29,7 @@
         path_auditor::PathAuditor,
     },
     vfs::{is_on_nfs_mount, VfsImpl},
-    DirstateParents, RevlogError, UncheckedRevision,
+    DirstateParents, UncheckedRevision,
 };
 use crossbeam_channel::{Receiver, Sender};
 use rayon::prelude::*;
@@ -93,7 +93,7 @@
     let options = default_revlog_options(
         repo.config(),
         repo.requirements(),
-        crate::RevlogType::Filelog,
+        crate::revlog::RevlogType::Filelog,
     )?;
     let (errors_sender, errors_receiver) = crossbeam_channel::unbounded();
     let (files_sender, files_receiver) = crossbeam_channel::unbounded();
@@ -134,7 +134,7 @@
 
 fn handle_revlog_error(e: RevlogError) -> HgError {
     match e {
-        crate::RevlogError::Other(hg_error) => hg_error,
+        crate::revlog::RevlogError::Other(hg_error) => hg_error,
         e => HgError::abort(
             format!("revlog error: {}", e),
             exit_codes::ABORT,
--- a/rust/hg-core/src/vfs.rs	Thu Aug 01 11:27:20 2024 +0200
+++ b/rust/hg-core/src/vfs.rs	Thu Sep 26 14:26:24 2024 +0200
@@ -1,7 +1,7 @@
 use crate::errors::{HgError, IoErrorContext, IoResultExt};
 use crate::exit_codes;
 use crate::fncache::FnCache;
-use crate::path_encode::path_encode;
+use crate::revlog::path_encode::path_encode;
 use crate::utils::files::{get_bytes_from_path, get_path_from_bytes};
 use dyn_clone::DynClone;
 use memmap2::{Mmap, MmapOptions};
--- a/rust/hg-cpython/src/conversion.rs	Thu Aug 01 11:27:20 2024 +0200
+++ b/rust/hg-cpython/src/conversion.rs	Thu Sep 26 14:26:24 2024 +0200
@@ -9,7 +9,7 @@
 //! `hg-core` crate. From Python, this will be seen as `rustext.ancestor`
 
 use cpython::{ObjectProtocol, PyErr, PyObject, PyResult, Python};
-use hg::{Revision, RevlogIndex, UncheckedRevision};
+use hg::{revlog::RevlogIndex, Revision, UncheckedRevision};
 
 use crate::{exceptions::GraphError, PyRevision};
 
--- a/rust/hg-cpython/src/revlog.rs	Thu Aug 01 11:27:20 2024 +0200
+++ b/rust/hg-cpython/src/revlog.rs	Thu Sep 26 14:26:24 2024 +0200
@@ -22,23 +22,24 @@
 use hg::{
     errors::HgError,
     fncache::FnCache,
-    index::{Phase, RevisionDataParams, SnapshotsCache, INDEX_ENTRY_SIZE},
-    nodemap::{Block, NodeMapError, NodeTree as CoreNodeTree},
     revlog::{
         compression::CompressionConfig,
+        index::{
+            Index, IndexHeader, Phase, RevisionDataParams, SnapshotsCache,
+            INDEX_ENTRY_SIZE,
+        },
         inner_revlog::{InnerRevlog as CoreInnerRevlog, RevisionBuffer},
-        nodemap::NodeMap,
+        nodemap::{Block, NodeMap, NodeMapError, NodeTree as CoreNodeTree},
         options::{
             RevlogDataConfig, RevlogDeltaConfig, RevlogFeatureConfig,
             RevlogOpenOptions,
         },
-        Graph, NodePrefix, RevlogError, RevlogIndex,
+        Graph, NodePrefix, RevlogError, RevlogIndex, RevlogType,
     },
     transaction::Transaction,
     utils::files::{get_bytes_from_path, get_path_from_bytes},
     vfs::FnCacheVfs,
-    BaseRevision, Node, Revision, RevlogType, UncheckedRevision,
-    NULL_REVISION,
+    BaseRevision, Node, Revision, UncheckedRevision, NULL_REVISION,
 };
 use std::{
     cell::{Cell, RefCell},
@@ -50,7 +51,7 @@
 
 pub struct PySharedIndex {
     /// The underlying hg-core index
-    pub(crate) inner: &'static hg::index::Index,
+    pub(crate) inner: &'static Index,
 }
 
 /// Return a Struct implementing the Graph trait
@@ -989,7 +990,7 @@
             },
             None => None,
         };
-        let header = hg::index::IndexHeader::parse(&header.to_be_bytes());
+        let header = IndexHeader::parse(&header.to_be_bytes());
         let header = header.expect("invalid header bytes");
         let path = inner
             .split_inline(header, new_index_file_path)
@@ -1732,7 +1733,7 @@
     }
 
     fn check_revision(
-        index: &hg::index::Index,
+        index: &Index,
         rev: UncheckedRevision,
         py: Python,
     ) -> PyResult<Revision> {
@@ -1999,7 +2000,7 @@
 
         // Safety: we keep the buffer around inside the class as `index_mmap`
         let (buf, bytes) = unsafe { mmap_keeparound(py, index_data)? };
-        let index = hg::index::Index::new(bytes, options.index_header())
+        let index = Index::new(bytes, options.index_header())
             .map_err(|e| revlog_error_from_msg(py, e))?;
 
         let base = &vfs_base.extract::<PyBytes>(py)?;
--- a/rust/rhg/src/commands/debugdata.rs	Thu Aug 01 11:27:20 2024 +0200
+++ b/rust/rhg/src/commands/debugdata.rs	Thu Sep 26 14:26:24 2024 +0200
@@ -2,7 +2,7 @@
 use clap::Arg;
 use clap::ArgGroup;
 use hg::operations::debug_data;
-use hg::RevlogType;
+use hg::revlog::RevlogType;
 
 pub const HELP_TEXT: &str = "
 Dump the contents of a data file revision
--- a/rust/rhg/src/commands/status.rs	Thu Aug 01 11:27:20 2024 +0200
+++ b/rust/rhg/src/commands/status.rs	Thu Sep 26 14:26:24 2024 +0200
@@ -20,21 +20,22 @@
 use hg::errors::{HgError, IoResultExt};
 use hg::filepatterns::parse_pattern_args;
 use hg::lock::LockError;
-use hg::manifest::Manifest;
 use hg::matchers::{AlwaysMatcher, IntersectionMatcher};
 use hg::repo::Repo;
+use hg::revlog::manifest::Manifest;
 use hg::revlog::options::{default_revlog_options, RevlogOpenOptions};
+use hg::revlog::RevlogType;
 use hg::utils::debug::debug_wait_for_file;
 use hg::utils::files::{
     get_bytes_from_os_str, get_bytes_from_os_string, get_path_from_bytes,
 };
 use hg::utils::hg_path::{hg_path_to_path_buf, HgPath};
 use hg::DirstateStatus;
+use hg::PatternFileWarning;
 use hg::Revision;
 use hg::StatusError;
 use hg::StatusOptions;
 use hg::{self, narrow, sparse};
-use hg::{PatternFileWarning, RevlogType};
 use log::info;
 use rayon::prelude::*;
 use std::borrow::Cow;
@@ -789,7 +790,7 @@
     if entry_flags.map(|f| f.into()) != fs_flags {
         return Ok(UnsureOutcome::Modified);
     }
-    let filelog = hg::filelog::Filelog::open_vfs(
+    let filelog = hg::revlog::filelog::Filelog::open_vfs(
         store_vfs,
         hg_path,
         revlog_open_options,