@@ -6,7 +6,7 @@ use gix_object::FindExt;
66use std:: path:: { Path , PathBuf } ;
77
88/// An entry in the conflict
9- #[ derive( Debug ) ]
9+ #[ derive( Debug , Eq , PartialEq ) ]
1010pub struct Entry {
1111 /// The relative path in the repository
1212 pub location : String ,
@@ -17,7 +17,7 @@ pub struct Entry {
1717}
1818
1919/// Keep track of all the sides of a conflict. Some might not be set to indicate removal, including the ancestor.
20- #[ derive( Default , Debug ) ]
20+ #[ derive( Default , Debug , Eq , PartialEq ) ]
2121pub struct Conflict {
2222 pub ancestor : Option < Entry > ,
2323 pub ours : Option < Entry > ,
@@ -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
@@ -232,6 +221,10 @@ fn parse_merge_info(content: String) -> MergeInfo {
232221 * field = Some ( entry) ;
233222 }
234223
224+ if conflicts. last ( ) != Some ( & conflict) {
225+ conflicts. push ( conflict) ;
226+ }
227+
235228 while lines. peek ( ) . is_some ( ) {
236229 out. information
237230 . push ( parse_info ( & mut lines) . expect ( "if there are lines, it should be valid info" ) ) ;
@@ -377,3 +370,35 @@ pub fn show_diff_and_fail(
377370 expected. information
378371 ) ;
379372}
373+
374+ pub ( crate ) fn apply_git_index_entries ( conflicts : Vec < Conflict > , state : & mut gix_index:: State ) {
375+ let len = state. entries ( ) . len ( ) ;
376+ for Conflict { ours, theirs, ancestor } in conflicts {
377+ for ( entry, stage) in [
378+ ancestor. map ( |e| ( e, gix_index:: entry:: Stage :: Base ) ) ,
379+ ours. map ( |e| ( e, gix_index:: entry:: Stage :: Ours ) ) ,
380+ theirs. map ( |e| ( e, gix_index:: entry:: Stage :: Theirs ) ) ,
381+ ]
382+ . into_iter ( )
383+ . filter_map ( std:: convert:: identity)
384+ {
385+ if let Some ( pos) = state. entry_index_by_path_and_stage_bounded (
386+ entry. location . as_str ( ) . into ( ) ,
387+ gix_index:: entry:: Stage :: Unconflicted ,
388+ len,
389+ ) {
390+ state. entries_mut ( ) [ pos] . flags . insert ( gix_index:: entry:: Flags :: REMOVE )
391+ }
392+
393+ state. dangerously_push_entry (
394+ Default :: default ( ) ,
395+ entry. id ,
396+ gix_index:: entry:: Flags :: empty ( ) | gix_index:: entry:: Flags :: from_bits ( ( stage as u32 ) << 12 ) . unwrap ( ) ,
397+ entry. mode . into ( ) ,
398+ entry. location . as_str ( ) . into ( ) ,
399+ ) ;
400+ }
401+ }
402+ state. sort_entries ( ) ;
403+ state. remove_entries ( |_, _, e| e. flags . contains ( gix_index:: entry:: Flags :: REMOVE ) ) ;
404+ }
0 commit comments