diff --git a/gitoxide-core/src/index/information.rs b/gitoxide-core/src/index/information.rs index aa618ab10c3..4540e5bc832 100644 --- a/gitoxide-core/src/index/information.rs +++ b/gitoxide-core/src/index/information.rs @@ -6,6 +6,7 @@ pub struct Options { #[cfg(feature = "serde")] mod serde_only { + use gix::index::entry::Stage; mod ext { #[derive(serde::Serialize)] @@ -115,11 +116,10 @@ mod serde_only { let (mut intent_to_add, mut skip_worktree) = (0, 0); for entry in f.entries() { match entry.flags.stage() { - 0 => stage_0_merged += 1, - 1 => stage_1_base += 1, - 2 => stage_2_ours += 1, - 3 => stage_3_theirs += 1, - invalid => anyhow::bail!("Invalid stage {} encountered", invalid), + Stage::Unconflicted => stage_0_merged += 1, + Stage::Base => stage_1_base += 1, + Stage::Ours => stage_2_ours += 1, + Stage::Theirs => stage_3_theirs += 1, } match entry.mode { gix::index::entry::Mode::DIR => dir += 1, diff --git a/gitoxide-core/src/repository/index/entries.rs b/gitoxide-core/src/repository/index/entries.rs index 7126849ad4d..3f17d55b3c3 100644 --- a/gitoxide-core/src/repository/index/entries.rs +++ b/gitoxide-core/src/repository/index/entries.rs @@ -23,6 +23,7 @@ pub(crate) mod function { io::{BufWriter, Write}, }; + use gix::index::entry::Stage; use gix::{ bstr::{BStr, BString}, worktree::IndexPersistedOrInMemory, @@ -392,11 +393,10 @@ pub(crate) mod function { out, "{} {}{:?} {} {}{}{}", match entry.flags.stage() { - 0 => " ", - 1 => "BASE ", - 2 => "OURS ", - 3 => "THEIRS ", - _ => "UNKNOWN", + Stage::Unconflicted => " ", + Stage::Base => "BASE ", + Stage::Ours => "OURS ", + Stage::Theirs => "THEIRS ", }, if entry.flags.is_empty() { "".to_string() diff --git a/gix-index/tests/index/access.rs b/gix-index/tests/index/access.rs index 3df4fb5ca3a..d3e720486a4 100644 --- a/gix-index/tests/index/access.rs +++ b/gix-index/tests/index/access.rs @@ -152,7 +152,7 @@ fn entry_by_path_and_stage() { #[test] fn entry_by_path_with_conflicting_file() { let file = Fixture::Loose("conflicting-file").open(); - for expected_stage in [Stage::Base,Stage::Ours, Stage::Theirs] { + for expected_stage in [Stage::Base, Stage::Ours, Stage::Theirs] { assert!( file.entry_by_path_and_stage("file".into(), expected_stage).is_some(), "we have no stage 0 during a conflict, but all other ones. Missed {expected_stage:?}" diff --git a/gix-status/src/index_as_worktree/function.rs b/gix-status/src/index_as_worktree/function.rs index e69d6629b64..dbe7a838ed2 100644 --- a/gix-status/src/index_as_worktree/function.rs +++ b/gix-status/src/index_as_worktree/function.rs @@ -157,11 +157,11 @@ where let mut idx = 0; while let Some(entry) = chunk_entries.get(idx) { let absolute_entry_index = entry_offset + idx; - if idx == 0 && entry.stage() != 0 { + if idx == 0 && entry.stage_raw() != 0 { let offset = entry_offset.checked_sub(1).and_then(|prev_idx| { let prev_entry = &all_entries[prev_idx]; let entry_path = entry.path_in(state.path_backing); - if prev_entry.stage() == 0 || prev_entry.path_in(state.path_backing) != entry_path { + if prev_entry.stage_raw() == 0 || prev_entry.path_in(state.path_backing) != entry_path { // prev_entry (in previous chunk) does not belong to our conflict return None; } @@ -286,7 +286,7 @@ impl<'index> State<'_, 'index> { self.skipped_by_pathspec.fetch_add(1, Ordering::Relaxed); return None; } - let status = if entry.stage() != 0 { + let status = if entry.stage_raw() != 0 { Ok( Conflict::try_from_entry(entries, self.path_backing, entry_index, path).map(|(conflict, offset)| { *outer_entry_index += offset; // let out loop skip over entries related to the conflict @@ -604,7 +604,7 @@ impl Conflict { let mut count = 0_usize; for stage in (start_index..(start_index + 3).min(entries.len())).filter_map(|idx| { let entry = &entries[idx]; - let stage = entry.stage(); + let stage = entry.stage_raw(); (stage > 0 && entry.path_in(path_backing) == entry_path).then_some(stage) }) { // This could be `1 << (stage - 1)` but let's be specific. diff --git a/gix-worktree/src/stack/state/mod.rs b/gix-worktree/src/stack/state/mod.rs index ba6383fee85..04afb046368 100644 --- a/gix-worktree/src/stack/state/mod.rs +++ b/gix-worktree/src/stack/state/mod.rs @@ -131,7 +131,7 @@ impl State { // Stage 0 means there is no merge going on, stage 2 means it's 'our' side of the merge, but then // there won't be a stage 0. - if entry.mode == gix_index::entry::Mode::FILE && (entry.stage() == 0 || entry.stage() == 2) { + if entry.mode == gix_index::entry::Mode::FILE && (entry.stage_raw() == 0 || entry.stage_raw() == 2) { let basename = path.rfind_byte(b'/').map_or(path, |pos| path[pos + 1..].as_bstr()); let ignore_source = names.iter().find_map(|t| { match case { diff --git a/gix/src/revision/spec/parse/delegate/navigate.rs b/gix/src/revision/spec/parse/delegate/navigate.rs index 731a24136d3..acd8ecc530b 100644 --- a/gix/src/revision/spec/parse/delegate/navigate.rs +++ b/gix/src/revision/spec/parse/delegate/navigate.rs @@ -1,6 +1,7 @@ use std::collections::HashSet; use gix_hash::ObjectId; +use gix_index::entry::Stage; use gix_revision::spec::parse::{ delegate, delegate::{PeelTo, Traversal}, @@ -305,9 +306,18 @@ impl<'repo> delegate::Navigate for Delegate<'repo> { } fn index_lookup(&mut self, path: &BStr, stage: u8) -> Option<()> { + let stage = match stage { + 0 => Stage::Unconflicted, + 1 => Stage::Base, + 2 => Stage::Ours, + 3 => Stage::Theirs, + _ => unreachable!( + "BUG: driver will not pass invalid stages (and it uses integer to avoid gix-index as dependency)" + ), + }; self.unset_disambiguate_call(); match self.repo.index() { - Ok(index) => match index.entry_by_path_and_stage(path, stage.into()) { + Ok(index) => match index.entry_by_path_and_stage(path, stage) { Some(entry) => { self.objs[self.idx] .get_or_insert_with(HashSet::default) @@ -323,21 +333,17 @@ impl<'repo> delegate::Navigate for Delegate<'repo> { Some(()) } None => { - let stage_hint = [0, 1, 2] + let stage_hint = [Stage::Unconflicted, Stage::Base, Stage::Ours] .iter() .filter(|our_stage| **our_stage != stage) - .find_map(|stage| { - index - .entry_index_by_path_and_stage(path, (*stage).into()) - .map(|_| (*stage).into()) - }); + .find_map(|stage| index.entry_index_by_path_and_stage(path, *stage).map(|_| *stage)); let exists = self .repo .work_dir() .map_or(false, |root| root.join(gix_path::from_bstr(path)).exists()); self.err.push(Error::IndexLookup { desired_path: path.into(), - desired_stage: stage.into(), + desired_stage: stage, exists, stage_hint, }); diff --git a/gix/src/revision/spec/parse/types.rs b/gix/src/revision/spec/parse/types.rs index 297ab5b467b..fc09e13c097 100644 --- a/gix/src/revision/spec/parse/types.rs +++ b/gix/src/revision/spec/parse/types.rs @@ -98,7 +98,7 @@ pub enum Error { desired: usize, available: usize, }, - #[error("Path {desired_path:?} did not exist in index at stage {desired_stage}{}{}", stage_hint.map(|actual|format!(". It does exist at stage {actual}")).unwrap_or_default(), exists.then(|| ". It exists on disk").unwrap_or(". It does not exist on disk"))] + #[error("Path {desired_path:?} did not exist in index at stage {}{}{}", *desired_stage as u8, stage_hint.map(|actual|format!(". It does exist at stage {}", actual as u8)).unwrap_or_default(), exists.then(|| ". It exists on disk").unwrap_or(". It does not exist on disk"))] IndexLookup { desired_path: BString, desired_stage: gix_index::entry::Stage,