Skip to content

Commit 1e1fce1

Browse files
committed
adapt to changes in gix-index
1 parent a6cc781 commit 1e1fce1

File tree

7 files changed

+31
-25
lines changed

7 files changed

+31
-25
lines changed

gitoxide-core/src/index/information.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub struct Options {
66

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

1011
mod ext {
1112
#[derive(serde::Serialize)]
@@ -115,11 +116,10 @@ mod serde_only {
115116
let (mut intent_to_add, mut skip_worktree) = (0, 0);
116117
for entry in f.entries() {
117118
match entry.flags.stage() {
118-
0 => stage_0_merged += 1,
119-
1 => stage_1_base += 1,
120-
2 => stage_2_ours += 1,
121-
3 => stage_3_theirs += 1,
122-
invalid => anyhow::bail!("Invalid stage {} encountered", invalid),
119+
Stage::Unconflicted => stage_0_merged += 1,
120+
Stage::Base => stage_1_base += 1,
121+
Stage::Ours => stage_2_ours += 1,
122+
Stage::Theirs => stage_3_theirs += 1,
123123
}
124124
match entry.mode {
125125
gix::index::entry::Mode::DIR => dir += 1,

gitoxide-core/src/repository/index/entries.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub(crate) mod function {
2323
io::{BufWriter, Write},
2424
};
2525

26+
use gix::index::entry::Stage;
2627
use gix::{
2728
bstr::{BStr, BString},
2829
worktree::IndexPersistedOrInMemory,
@@ -392,11 +393,10 @@ pub(crate) mod function {
392393
out,
393394
"{} {}{:?} {} {}{}{}",
394395
match entry.flags.stage() {
395-
0 => " ",
396-
1 => "BASE ",
397-
2 => "OURS ",
398-
3 => "THEIRS ",
399-
_ => "UNKNOWN",
396+
Stage::Unconflicted => " ",
397+
Stage::Base => "BASE ",
398+
Stage::Ours => "OURS ",
399+
Stage::Theirs => "THEIRS ",
400400
},
401401
if entry.flags.is_empty() {
402402
"".to_string()

gix-index/tests/index/access.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fn entry_by_path_and_stage() {
152152
#[test]
153153
fn entry_by_path_with_conflicting_file() {
154154
let file = Fixture::Loose("conflicting-file").open();
155-
for expected_stage in [Stage::Base,Stage::Ours, Stage::Theirs] {
155+
for expected_stage in [Stage::Base, Stage::Ours, Stage::Theirs] {
156156
assert!(
157157
file.entry_by_path_and_stage("file".into(), expected_stage).is_some(),
158158
"we have no stage 0 during a conflict, but all other ones. Missed {expected_stage:?}"

gix-status/src/index_as_worktree/function.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ where
157157
let mut idx = 0;
158158
while let Some(entry) = chunk_entries.get(idx) {
159159
let absolute_entry_index = entry_offset + idx;
160-
if idx == 0 && entry.stage() != 0 {
160+
if idx == 0 && entry.stage_raw() != 0 {
161161
let offset = entry_offset.checked_sub(1).and_then(|prev_idx| {
162162
let prev_entry = &all_entries[prev_idx];
163163
let entry_path = entry.path_in(state.path_backing);
164-
if prev_entry.stage() == 0 || prev_entry.path_in(state.path_backing) != entry_path {
164+
if prev_entry.stage_raw() == 0 || prev_entry.path_in(state.path_backing) != entry_path {
165165
// prev_entry (in previous chunk) does not belong to our conflict
166166
return None;
167167
}
@@ -286,7 +286,7 @@ impl<'index> State<'_, 'index> {
286286
self.skipped_by_pathspec.fetch_add(1, Ordering::Relaxed);
287287
return None;
288288
}
289-
let status = if entry.stage() != 0 {
289+
let status = if entry.stage_raw() != 0 {
290290
Ok(
291291
Conflict::try_from_entry(entries, self.path_backing, entry_index, path).map(|(conflict, offset)| {
292292
*outer_entry_index += offset; // let out loop skip over entries related to the conflict
@@ -604,7 +604,7 @@ impl Conflict {
604604
let mut count = 0_usize;
605605
for stage in (start_index..(start_index + 3).min(entries.len())).filter_map(|idx| {
606606
let entry = &entries[idx];
607-
let stage = entry.stage();
607+
let stage = entry.stage_raw();
608608
(stage > 0 && entry.path_in(path_backing) == entry_path).then_some(stage)
609609
}) {
610610
// This could be `1 << (stage - 1)` but let's be specific.

gix-worktree/src/stack/state/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl State {
131131

132132
// Stage 0 means there is no merge going on, stage 2 means it's 'our' side of the merge, but then
133133
// there won't be a stage 0.
134-
if entry.mode == gix_index::entry::Mode::FILE && (entry.stage() == 0 || entry.stage() == 2) {
134+
if entry.mode == gix_index::entry::Mode::FILE && (entry.stage_raw() == 0 || entry.stage_raw() == 2) {
135135
let basename = path.rfind_byte(b'/').map_or(path, |pos| path[pos + 1..].as_bstr());
136136
let ignore_source = names.iter().find_map(|t| {
137137
match case {

gix/src/revision/spec/parse/delegate/navigate.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::collections::HashSet;
22

33
use gix_hash::ObjectId;
4+
use gix_index::entry::Stage;
45
use gix_revision::spec::parse::{
56
delegate,
67
delegate::{PeelTo, Traversal},
@@ -305,9 +306,18 @@ impl<'repo> delegate::Navigate for Delegate<'repo> {
305306
}
306307

307308
fn index_lookup(&mut self, path: &BStr, stage: u8) -> Option<()> {
309+
let stage = match stage {
310+
0 => Stage::Unconflicted,
311+
1 => Stage::Base,
312+
2 => Stage::Ours,
313+
3 => Stage::Theirs,
314+
_ => unreachable!(
315+
"BUG: driver will not pass invalid stages (and it uses integer to avoid gix-index as dependency)"
316+
),
317+
};
308318
self.unset_disambiguate_call();
309319
match self.repo.index() {
310-
Ok(index) => match index.entry_by_path_and_stage(path, stage.into()) {
320+
Ok(index) => match index.entry_by_path_and_stage(path, stage) {
311321
Some(entry) => {
312322
self.objs[self.idx]
313323
.get_or_insert_with(HashSet::default)
@@ -323,21 +333,17 @@ impl<'repo> delegate::Navigate for Delegate<'repo> {
323333
Some(())
324334
}
325335
None => {
326-
let stage_hint = [0, 1, 2]
336+
let stage_hint = [Stage::Unconflicted, Stage::Base, Stage::Ours]
327337
.iter()
328338
.filter(|our_stage| **our_stage != stage)
329-
.find_map(|stage| {
330-
index
331-
.entry_index_by_path_and_stage(path, (*stage).into())
332-
.map(|_| (*stage).into())
333-
});
339+
.find_map(|stage| index.entry_index_by_path_and_stage(path, *stage).map(|_| *stage));
334340
let exists = self
335341
.repo
336342
.work_dir()
337343
.map_or(false, |root| root.join(gix_path::from_bstr(path)).exists());
338344
self.err.push(Error::IndexLookup {
339345
desired_path: path.into(),
340-
desired_stage: stage.into(),
346+
desired_stage: stage,
341347
exists,
342348
stage_hint,
343349
});

gix/src/revision/spec/parse/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub enum Error {
9898
desired: usize,
9999
available: usize,
100100
},
101-
#[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"))]
101+
#[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"))]
102102
IndexLookup {
103103
desired_path: BString,
104104
desired_stage: gix_index::entry::Stage,

0 commit comments

Comments
 (0)