Skip to content

Commit

Permalink
adapt to changes in gix-index
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Apr 3, 2024
1 parent a6cc781 commit 1e1fce1
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 25 deletions.
10 changes: 5 additions & 5 deletions gitoxide-core/src/index/information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct Options {

#[cfg(feature = "serde")]
mod serde_only {
use gix::index::entry::Stage;

mod ext {
#[derive(serde::Serialize)]
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions gitoxide-core/src/repository/index/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub(crate) mod function {
io::{BufWriter, Write},
};

use gix::index::entry::Stage;
use gix::{
bstr::{BStr, BString},
worktree::IndexPersistedOrInMemory,
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion gix-index/tests/index/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}"
Expand Down
8 changes: 4 additions & 4 deletions gix-status/src/index_as_worktree/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion gix-worktree/src/stack/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 14 additions & 8 deletions gix/src/revision/spec/parse/delegate/navigate.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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)
Expand All @@ -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,
});
Expand Down
2 changes: 1 addition & 1 deletion gix/src/revision/spec/parse/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1e1fce1

Please sign in to comment.