1
1
use super :: { Action , ChangeRef , Error , RewriteOptions } ;
2
2
use crate :: rewrites;
3
- use bstr:: { BStr , BString , ByteSlice } ;
3
+ use bstr:: BStr ;
4
4
use gix_filter:: attributes:: glob:: pattern:: Case ;
5
5
use std:: borrow:: Cow ;
6
6
use std:: cell:: RefCell ;
@@ -20,7 +20,8 @@ use std::cmp::Ordering;
20
20
/// Return the outcome of the rewrite tracker if it was enabled.
21
21
///
22
22
/// 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
+ ///
24
25
/// Conceptually, `rhs` is *ours*, and `lhs` is *theirs*.
25
26
/// The entries in `lhs` and `rhs` are both expected to be sorted like index entries are typically sorted.
26
27
///
74
75
. filter ( |( _, path, e) | pattern_matches. borrow_mut ( ) ( path, e) ) ,
75
76
) ;
76
77
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
- } ;
94
78
let mut resource_cache_storage = None ;
95
79
let mut tracker = rewrite_options. map (
96
80
|RewriteOptions {
@@ -107,15 +91,6 @@ where
107
91
loop {
108
92
match ( lhs_storage, rhs_storage) {
109
93
( 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
-
119
94
let ( lhs_idx, lhs_path, lhs_entry) = lhs;
120
95
let ( rhs_idx, rhs_path, rhs_entry) = rhs;
121
96
match lhs_path. cmp ( rhs_path) {
@@ -126,6 +101,11 @@ where
126
101
Action :: Cancel => return Ok ( None ) ,
127
102
} ,
128
103
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
+ }
129
109
if lhs_entry. id != rhs_entry. id || lhs_entry. mode != rhs_entry. mode {
130
110
let change = ChangeRef :: Modification {
131
111
location : Cow :: Borrowed ( rhs_path) ,
@@ -274,8 +254,8 @@ fn emit_addition<'rhs, 'lhs: 'rhs, E>(
274
254
where
275
255
E : Into < Box < dyn std:: error:: Error + Send + Sync > > ,
276
256
{
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 ) ;
279
259
}
280
260
281
261
let change = ChangeRef :: Addition {
@@ -296,29 +276,9 @@ where
296
276
cb ( change) . map_err ( |err| Error :: Callback ( err. into ( ) ) )
297
277
}
298
278
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 {
309
282
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
324
284
}
0 commit comments