From 713cd59f0b1eff6397b80f1e1fceec278532fd59 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 27 Aug 2023 18:31:58 +0200 Subject: [PATCH] adapt to changes in `gix-index` and pass skip-hash through for performance.. --- gitoxide-core/src/index/mod.rs | 2 +- gix-status/tests/status/index_as_worktree.rs | 6 ++++-- gix-worktree-state/tests/state/checkout.rs | 2 +- gix-worktree/tests/worktree/stack/ignore.rs | 2 +- gix/src/config/tree/sections/index.rs | 5 ++++- gix/src/repository/index.rs | 17 ++++++++++++++--- gix/src/worktree/mod.rs | 4 ++++ src/shared.rs | 8 ++++---- 8 files changed, 33 insertions(+), 13 deletions(-) diff --git a/gitoxide-core/src/index/mod.rs b/gitoxide-core/src/index/mod.rs index df75cf541b6..4b6b50b36ef 100644 --- a/gitoxide-core/src/index/mod.rs +++ b/gitoxide-core/src/index/mod.rs @@ -8,7 +8,7 @@ pub struct Options { pub mod information; fn parse_file(index_path: impl AsRef, object_hash: gix::hash::Kind) -> anyhow::Result { - gix::index::File::at(index_path.as_ref(), object_hash, Default::default()).map_err(Into::into) + gix::index::File::at(index_path.as_ref(), object_hash, false, Default::default()).map_err(Into::into) } pub mod checkout_exclusive { diff --git a/gix-status/tests/status/index_as_worktree.rs b/gix-status/tests/status/index_as_worktree.rs index c075f96a0b8..2629c3e1033 100644 --- a/gix-status/tests/status/index_as_worktree.rs +++ b/gix-status/tests/status/index_as_worktree.rs @@ -31,7 +31,8 @@ const TEST_OPTIONS: index::entry::stat::Options = index::entry::stat::Options { fn fixture(name: &str, expected_status: &[(&BStr, Option, bool)]) { let worktree = fixture_path(name); let git_dir = worktree.join(".git"); - let mut index = gix_index::File::at(git_dir.join("index"), gix_hash::Kind::Sha1, Default::default()).unwrap(); + let mut index = + gix_index::File::at(git_dir.join("index"), gix_hash::Kind::Sha1, false, Default::default()).unwrap(); let mut recorder = Recorder::default(); index_as_worktree( &mut index, @@ -139,7 +140,8 @@ fn racy_git() { let worktree = dir.path(); let git_dir = worktree.join(".git"); let fs = gix_fs::Capabilities::probe(&git_dir); - let mut index = gix_index::File::at(git_dir.join("index"), gix_hash::Kind::Sha1, Default::default()).unwrap(); + let mut index = + gix_index::File::at(git_dir.join("index"), gix_hash::Kind::Sha1, false, Default::default()).unwrap(); #[derive(Clone)] struct CountCalls(Arc, FastEq); diff --git a/gix-worktree-state/tests/state/checkout.rs b/gix-worktree-state/tests/state/checkout.rs index 4c2e1f87b5d..9fa590667f0 100644 --- a/gix-worktree-state/tests/state/checkout.rs +++ b/gix-worktree-state/tests/state/checkout.rs @@ -492,7 +492,7 @@ fn checkout_index_in_tmp_dir_opts( ) -> crate::Result<(PathBuf, TempDir, gix_index::File, gix_worktree_state::checkout::Outcome)> { let source_tree = fixture_path(name); let git_dir = source_tree.join(".git"); - let mut index = gix_index::File::at(git_dir.join("index"), gix_hash::Kind::Sha1, Default::default())?; + let mut index = gix_index::File::at(git_dir.join("index"), gix_hash::Kind::Sha1, false, Default::default())?; let odb = gix_odb::at(git_dir.join("objects"))?.into_inner().into_arc()?; let destination = gix_testtools::tempfile::tempdir_in(std::env::current_dir()?)?; prep_dest(destination.path()).expect("preparation must succeed"); diff --git a/gix-worktree/tests/worktree/stack/ignore.rs b/gix-worktree/tests/worktree/stack/ignore.rs index f20092b76b0..9173cb1f5f1 100644 --- a/gix-worktree/tests/worktree/stack/ignore.rs +++ b/gix-worktree/tests/worktree/stack/ignore.rs @@ -89,7 +89,7 @@ fn check_against_baseline() -> crate::Result { // Due to the way our setup differs from gits dynamic stack (which involves trying to read files from disk // by path) we can only test one case baseline, so we require multiple platforms (or filesystems) to run this. let case = probe_case()?; - let mut index = gix_index::File::at(git_dir.join("index"), gix_hash::Kind::Sha1, Default::default())?; + let mut index = gix_index::File::at(git_dir.join("index"), gix_hash::Kind::Sha1, false, Default::default())?; let odb = gix_odb::at(git_dir.join("objects"))?; let state = gix_worktree::stack::State::for_add( Default::default(), diff --git a/gix/src/config/tree/sections/index.rs b/gix/src/config/tree/sections/index.rs index 08f7ec1bd41..026f35b6daf 100644 --- a/gix/src/config/tree/sections/index.rs +++ b/gix/src/config/tree/sections/index.rs @@ -7,6 +7,9 @@ impl Index { /// The `index.threads` key. pub const THREADS: IndexThreads = IndexThreads::new_with_validate("threads", &config::Tree::INDEX, validate::IndexThreads); + /// The `index.skipHash` key. + pub const SKIP_HASH: keys::Boolean = keys::Boolean::new_boolean("skipHash", &config::Tree::INDEX) + .with_deviation("also used to skip the hash when reading, even if a hash exists in the index file"); } /// The `index.threads` key. @@ -47,7 +50,7 @@ impl Section for Index { } fn keys(&self) -> &[&dyn Key] { - &[&Self::THREADS] + &[&Self::THREADS, &Self::SKIP_HASH] } } diff --git a/gix/src/repository/index.rs b/gix/src/repository/index.rs index e823d233e57..a21b138a569 100644 --- a/gix/src/repository/index.rs +++ b/gix/src/repository/index.rs @@ -16,16 +16,27 @@ impl crate::Repository { .map(|value| crate::config::tree::Index::THREADS.try_into_index_threads(value)) .transpose() .with_lenient_default(self.config.lenient_config)?; - gix_index::File::at( + let skip_hash = self + .config + .resolved + .boolean("index", None, "skipHash") + .map(|res| crate::config::tree::Index::SKIP_HASH.enrich_error(res)) + .transpose() + .with_lenient_default(self.config.lenient_config)? + .unwrap_or_default(); + + let index = gix_index::File::at( self.index_path(), self.object_hash(), + skip_hash, gix_index::decode::Options { thread_limit, min_extension_block_in_bytes_for_threading: 0, expected_checksum: None, }, - ) - .map_err(Into::into) + )?; + + Ok(index) } /// Return a shared worktree index which is updated automatically if the in-memory snapshot has become stale as the underlying file diff --git a/gix/src/worktree/mod.rs b/gix/src/worktree/mod.rs index 18be6dc1fe6..c780d8838e5 100644 --- a/gix/src/worktree/mod.rs +++ b/gix/src/worktree/mod.rs @@ -90,7 +90,11 @@ pub mod open_index { #[error(transparent)] ConfigIndexThreads(#[from] crate::config::key::GenericErrorWithValue), #[error(transparent)] + ConfigSkipHash(#[from] crate::config::boolean::Error), + #[error(transparent)] IndexFile(#[from] gix_index::file::init::Error), + #[error(transparent)] + IndexCorrupt(#[from] gix_index::file::verify::Error), } impl<'repo> crate::Worktree<'repo> { diff --git a/src/shared.rs b/src/shared.rs index 892e14c034b..179229af1e4 100644 --- a/src/shared.rs +++ b/src/shared.rs @@ -101,7 +101,7 @@ pub mod pretty { enable: bool, reverse_lines: bool, progress: &gix::progress::prodash::tree::Root, - ) -> anyhow::Result { + ) -> anyhow::Result<()> { Ok(if enable { let processor = tracing_forest::Printer::new().formatter({ let progress = std::sync::Mutex::new(progress.add_child("tracing")); @@ -124,9 +124,9 @@ pub mod pretty { }); use tracing_subscriber::layer::SubscriberExt; let subscriber = tracing_subscriber::Registry::default().with(tracing_forest::ForestLayer::from(processor)); - tracing::subscriber::set_default(subscriber) + tracing::subscriber::set_global_default(subscriber)?; } else { - tracing::subscriber::set_default(tracing_subscriber::Registry::default()) + tracing::subscriber::set_global_default(tracing_subscriber::Registry::default())?; }) } @@ -158,7 +158,7 @@ pub mod pretty { use crate::shared::{self, STANDARD_RANGE}; let progress = shared::progress_tree(); let sub_progress = progress.add_child(name); - let _trace = init_tracing(trace, false, &progress)?; + init_tracing(trace, false, &progress)?; let handle = shared::setup_line_renderer_range(&progress, range.into().unwrap_or(STANDARD_RANGE));