Skip to content

Commit

Permalink
adapt to changes in gix-index and pass skip-hash through for perfor…
Browse files Browse the repository at this point in the history
…mance..
  • Loading branch information
Byron committed Aug 27, 2023
1 parent 61c2e34 commit 713cd59
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gitoxide-core/src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct Options {
pub mod information;

fn parse_file(index_path: impl AsRef<Path>, object_hash: gix::hash::Kind) -> anyhow::Result<gix::index::File> {
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 {
Expand Down
6 changes: 4 additions & 2 deletions gix-status/tests/status/index_as_worktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const TEST_OPTIONS: index::entry::stat::Options = index::entry::stat::Options {
fn fixture(name: &str, expected_status: &[(&BStr, Option<Change>, 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,
Expand Down Expand Up @@ -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<AtomicUsize>, FastEq);
Expand Down
2 changes: 1 addition & 1 deletion gix-worktree-state/tests/state/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion gix-worktree/tests/worktree/stack/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
5 changes: 4 additions & 1 deletion gix/src/config/tree/sections/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -47,7 +50,7 @@ impl Section for Index {
}

fn keys(&self) -> &[&dyn Key] {
&[&Self::THREADS]
&[&Self::THREADS, &Self::SKIP_HASH]
}
}

Expand Down
17 changes: 14 additions & 3 deletions gix/src/repository/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions gix/src/worktree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
8 changes: 4 additions & 4 deletions src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub mod pretty {
enable: bool,
reverse_lines: bool,
progress: &gix::progress::prodash::tree::Root,
) -> anyhow::Result<tracing::subscriber::DefaultGuard> {
) -> anyhow::Result<()> {
Ok(if enable {
let processor = tracing_forest::Printer::new().formatter({
let progress = std::sync::Mutex::new(progress.add_child("tracing"));
Expand All @@ -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())?;
})
}

Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit 713cd59

Please sign in to comment.