11use super :: { Action , ChangeRef , Error , RewriteOptions } ;
22use crate :: rewrites;
3- use bstr:: { BStr , BString , ByteSlice } ;
3+ use bstr:: BStr ;
44use gix_filter:: attributes:: glob:: pattern:: Case ;
55use std:: borrow:: Cow ;
66use std:: cell:: RefCell ;
@@ -20,7 +20,8 @@ use std::cmp::Ordering;
2020/// Return the outcome of the rewrite tracker if it was enabled.
2121///
2222/// Note that only `rhs` may contain unmerged entries, as `rhs` is expected to be the index read from `.git/index`.
23- /// Unmerged entries are always provided as changes, one stage at a time, up to three stages for *base*, *ours* and *theirs*.
23+ /// Unmerged entries are skipped entirely.
24+ ///
2425/// Conceptually, `rhs` is *ours*, and `lhs` is *theirs*.
2526/// The entries in `lhs` and `rhs` are both expected to be sorted like index entries are typically sorted.
2627///
7475 . filter ( |( _, path, e) | pattern_matches. borrow_mut ( ) ( path, e) ) ,
7576 ) ;
7677
77- let mut conflicting_paths = Vec :: < BString > :: new ( ) ;
78- let mut cb = move |change : ChangeRef < ' lhs , ' rhs > | {
79- let ( location, ..) = change. fields ( ) ;
80- if let ChangeRef :: Unmerged { .. } = & change {
81- if let Err ( insert_idx) = conflicting_paths. binary_search_by ( |p| p. as_bstr ( ) . cmp ( location) ) {
82- conflicting_paths. insert ( insert_idx, location. to_owned ( ) ) ;
83- }
84- cb ( change)
85- } else if conflicting_paths
86- . binary_search_by ( |p| p. as_bstr ( ) . cmp ( location) )
87- . is_err ( )
88- {
89- cb ( change)
90- } else {
91- Ok ( Action :: Continue )
92- }
93- } ;
9478 let mut resource_cache_storage = None ;
9579 let mut tracker = rewrite_options. map (
9680 |RewriteOptions {
@@ -107,15 +91,6 @@ where
10791 loop {
10892 match ( lhs_storage, rhs_storage) {
10993 ( Some ( lhs) , Some ( rhs) ) => {
110- match emit_unmerged_ignore_intent_to_add ( rhs, & mut cb) ? {
111- None => { }
112- Some ( Action :: Cancel ) => return Ok ( None ) ,
113- Some ( Action :: Continue ) => {
114- rhs_storage = rhs_iter. next ( ) ;
115- continue ;
116- }
117- } ;
118-
11994 let ( lhs_idx, lhs_path, lhs_entry) = lhs;
12095 let ( rhs_idx, rhs_path, rhs_entry) = rhs;
12196 match lhs_path. cmp ( rhs_path) {
@@ -126,6 +101,11 @@ where
126101 Action :: Cancel => return Ok ( None ) ,
127102 } ,
128103 Ordering :: Equal => {
104+ if ignore_unmerged_and_intent_to_add ( rhs) {
105+ rhs_storage = rhs_iter. next ( ) ;
106+ lhs_storage = lhs_iter. next ( ) ;
107+ continue ;
108+ }
129109 if lhs_entry. id != rhs_entry. id || lhs_entry. mode != rhs_entry. mode {
130110 let change = ChangeRef :: Modification {
131111 location : Cow :: Borrowed ( rhs_path) ,
@@ -274,8 +254,8 @@ fn emit_addition<'rhs, 'lhs: 'rhs, E>(
274254where
275255 E : Into < Box < dyn std:: error:: Error + Send + Sync > > ,
276256{
277- if let Some ( action ) = emit_unmerged_ignore_intent_to_add ( ( idx, path, entry) , & mut cb ) ? {
278- return Ok ( action ) ;
257+ if ignore_unmerged_and_intent_to_add ( ( idx, path, entry) ) {
258+ return Ok ( Action :: Continue ) ;
279259 }
280260
281261 let change = ChangeRef :: Addition {
@@ -296,29 +276,9 @@ where
296276 cb ( change) . map_err ( |err| Error :: Callback ( err. into ( ) ) )
297277}
298278
299- fn emit_unmerged_ignore_intent_to_add < ' rhs , ' lhs : ' rhs , E > (
300- ( idx, path, entry) : ( usize , & ' rhs BStr , & ' rhs gix_index:: Entry ) ,
301- cb : & mut impl FnMut ( ChangeRef < ' lhs , ' rhs > ) -> Result < Action , E > ,
302- ) -> Result < Option < Action > , Error >
303- where
304- E : Into < Box < dyn std:: error:: Error + Send + Sync > > ,
305- {
306- if entry. flags . contains ( gix_index:: entry:: Flags :: INTENT_TO_ADD ) {
307- return Ok ( Some ( Action :: Continue ) ) ;
308- }
279+ fn ignore_unmerged_and_intent_to_add < ' rhs , ' lhs : ' rhs > (
280+ ( _idx, _path, entry) : ( usize , & ' rhs BStr , & ' rhs gix_index:: Entry ) ,
281+ ) -> bool {
309282 let stage = entry. stage ( ) ;
310- if stage == gix_index:: entry:: Stage :: Unconflicted {
311- return Ok ( None ) ;
312- }
313-
314- Ok ( Some (
315- cb ( ChangeRef :: Unmerged {
316- location : Cow :: Borrowed ( path) ,
317- stage,
318- index : idx,
319- entry_mode : entry. mode ,
320- id : Cow :: Borrowed ( entry. id . as_ref ( ) ) ,
321- } )
322- . map_err ( |err| Error :: Callback ( err. into ( ) ) ) ?,
323- ) )
283+ entry. flags . contains ( gix_index:: entry:: Flags :: INTENT_TO_ADD ) || stage != gix_index:: entry:: Stage :: Unconflicted
324284}
0 commit comments