Skip to content

Commit 9188d45

Browse files
committed
refactor squash me
1 parent e856ca8 commit 9188d45

File tree

4 files changed

+42
-28
lines changed

4 files changed

+42
-28
lines changed
-365 KB
Binary file not shown.

gix-merge/tests/fixtures/tree-baseline.sh

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,6 @@ function baseline () (
6666
git -c merge.conflictStyle=$conflict_style merge-tree -z --write-tree --allow-unrelated-histories "$their_committish" "$our_committish" > "$merge_info" || :
6767
echo "$dir" "$conflict_style" "$their_commit_id" "$their_committish" "$our_commit_id" "$our_committish" "$merge_info" "$maybe_expected_tree" "$opt_deviation_message" >> ../baseline.cases
6868
fi
69-
70-
local index_path=.git/${conflict_style}-${our_committish}-${their_committish}.index
71-
if [ ! -e $index_path ]; then
72-
git checkout -f $our_committish
73-
git merge -m m $their_committish || :
74-
cp .git/index "$index_path"
75-
fi
76-
77-
local index_path=.git/${conflict_style}-${their_committish}-${our_committish}.index
78-
if [ ! -e $index_path ]; then
79-
git checkout -f $their_committish
80-
git merge -m m $our_committish || :
81-
cp .git/index "$index_path"
82-
fi
8369
)
8470

8571
git init simple

gix-merge/tests/merge/tree/baseline.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ pub struct Expectation {
9696
pub their_side_name: String,
9797
pub merge_info: MergeInfo,
9898
pub case_name: String,
99-
pub index: gix_index::File,
10099
pub deviation: Option<Deviation>,
101100
}
102101

@@ -171,15 +170,6 @@ impl Iterator for Expectations<'_> {
171170
let our_commit_id = gix_hash::ObjectId::from_hex(our_commit_id.as_bytes()).unwrap();
172171
let their_commit_id = gix_hash::ObjectId::from_hex(their_commit_id.as_bytes()).unwrap();
173172
let merge_info = parse_merge_info(std::fs::read_to_string(subdir_path.join(merge_info_filename)).unwrap());
174-
let index = gix_index::File::at(
175-
subdir_path
176-
.join(".git")
177-
.join(format!("{conflict_style_name}-{our_side_name}-{their_side_name}.index")),
178-
gix_hash::Kind::Sha1,
179-
false, /* skip hash */
180-
Default::default(),
181-
)
182-
.expect("index should be present for each combination");
183173
Some(Expectation {
184174
root: subdir_path,
185175
conflict_style,
@@ -189,7 +179,6 @@ impl Iterator for Expectations<'_> {
189179
their_commit_id,
190180
their_side_name: their_side_name.to_owned(),
191181
merge_info,
192-
index,
193182
case_name: format!(
194183
"{subdir}-{}",
195184
merge_info_filename
@@ -377,3 +366,35 @@ pub fn show_diff_and_fail(
377366
expected.information
378367
);
379368
}
369+
370+
pub(crate) fn apply_git_index_entries(conflicts: Vec<Conflict>, state: &mut gix_index::State) {
371+
let len = state.entries().len();
372+
for Conflict { ours, theirs, ancestor } in conflicts {
373+
for (entry, stage) in [
374+
ancestor.map(|e| (e, gix_index::entry::Stage::Base)),
375+
ours.map(|e| (e, gix_index::entry::Stage::Ours)),
376+
theirs.map(|e| (e, gix_index::entry::Stage::Theirs)),
377+
]
378+
.into_iter()
379+
.filter_map(std::convert::identity)
380+
{
381+
if let Some(pos) = state.entry_index_by_path_and_stage_bounded(
382+
entry.location.as_str().into(),
383+
gix_index::entry::Stage::Unconflicted,
384+
len,
385+
) {
386+
state.entries_mut()[pos].flags.insert(gix_index::entry::Flags::REMOVE)
387+
}
388+
389+
state.dangerously_push_entry(
390+
Default::default(),
391+
entry.id,
392+
gix_index::entry::Flags::empty() | gix_index::entry::Flags::from_bits((stage as u32) << 12).unwrap(),
393+
entry.mode.into(),
394+
entry.location.as_str().into(),
395+
);
396+
}
397+
}
398+
state.sort_entries();
399+
state.remove_entries(|_, _, e| e.flags.contains(gix_index::entry::Flags::REMOVE));
400+
}

gix-merge/tests/merge/tree/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ fn run_baseline() -> crate::Result {
3232
their_side_name,
3333
merge_info,
3434
case_name,
35-
index,
3635
deviation,
3736
} in baseline::Expectations::new(&root, &cases)
3837
.filter(|case| new_test.map_or(true, |prefix: &str| case.case_name.starts_with(prefix)))
@@ -100,10 +99,18 @@ fn run_baseline() -> crate::Result {
10099
}
101100
}
102101

103-
let actual_index = gix_index::State::from_tree(&actual_id, &odb, Default::default())?;
102+
let mut actual_index = gix_index::State::from_tree(&actual_id, &odb, Default::default())?;
103+
let expected_index = {
104+
let mut index = actual_index.clone();
105+
if let Some(conflicts) = merge_info.conflicts {
106+
baseline::apply_git_index_entries(conflicts, &mut index)
107+
}
108+
index
109+
};
110+
actual.index_changed_after_applying_conflicts(&mut actual_index)?;
104111
pretty_assertions::assert_eq!(
105112
baseline::clear_entries(&actual_index),
106-
baseline::clear_entries(&index),
113+
baseline::clear_entries(&expected_index),
107114
"{case_name}: index mismatch"
108115
);
109116
}

0 commit comments

Comments
 (0)