@@ -78,9 +78,11 @@ fn find_unapply_base(
78
78
filtered : git2:: Oid ,
79
79
) -> super :: JoshResult < git2:: Oid > {
80
80
if contained_in == git2:: Oid :: zero ( ) {
81
+ tracing:: info!( "contained in zero" , ) ;
81
82
return Ok ( git2:: Oid :: zero ( ) ) ;
82
83
}
83
84
if let Some ( original) = bm. get ( & filtered) {
85
+ tracing:: info!( "Found in bm" , ) ;
84
86
return Ok ( * original) ;
85
87
}
86
88
let contained_in_commit = transaction. repo ( ) . find_commit ( contained_in) ?;
@@ -96,10 +98,12 @@ fn find_unapply_base(
96
98
let original = transaction. repo ( ) . find_commit ( original?) ?;
97
99
if filtered == filter:: apply_to_commit ( filter, & original, transaction) ? {
98
100
bm. insert ( filtered, original. id ( ) ) ;
101
+ tracing:: info!( "found original properly" , ) ;
99
102
return Ok ( original. id ( ) ) ;
100
103
}
101
104
}
102
105
106
+ tracing:: info!( "Didn't find original" , ) ;
103
107
Ok ( git2:: Oid :: zero ( ) )
104
108
}
105
109
@@ -199,6 +203,71 @@ fn all_equal(a: git2::Parents, b: &[&git2::Commit]) -> bool {
199
203
true
200
204
}
201
205
206
+ fn find_oldest_similar_commit (
207
+ transaction : & cache:: Transaction ,
208
+ filter : filter:: Filter ,
209
+ unfiltered : git2:: Oid ,
210
+ ) -> super :: JoshResult < git2:: Oid > {
211
+ let walk = {
212
+ let mut walk = transaction. repo ( ) . revwalk ( ) ?;
213
+ walk. set_sorting ( git2:: Sort :: TOPOLOGICAL ) ?;
214
+ walk. push ( unfiltered) ?;
215
+ walk
216
+ } ;
217
+ tracing:: info!( "oldest similar?" ) ;
218
+ let unfiltered_commit = transaction. repo ( ) . find_commit ( unfiltered) ?;
219
+ let filtered = filter:: apply_to_commit ( filter, & unfiltered_commit, transaction) ?;
220
+ let mut prev_rev = unfiltered;
221
+ for rev in walk {
222
+ let rev = rev?;
223
+ tracing:: info!( "next" ) ;
224
+ let rev_commit = transaction. repo ( ) . find_commit ( rev) ?;
225
+ if filtered != filter:: apply_to_commit ( filter, & rev_commit, transaction) ? {
226
+ tracing:: info!( "diff! {}" , prev_rev) ;
227
+ return Ok ( prev_rev) ;
228
+ }
229
+ prev_rev = rev;
230
+ }
231
+ tracing:: info!( "bottom" ) ;
232
+ return Ok ( unfiltered) ;
233
+ }
234
+
235
+ fn find_new_branch_base (
236
+ transaction : & cache:: Transaction ,
237
+ bm : & mut std:: collections:: HashMap < git2:: Oid , git2:: Oid > ,
238
+ filter : filter:: Filter ,
239
+ contained_in : git2:: Oid ,
240
+ filtered : git2:: Oid ,
241
+ ) -> super :: JoshResult < git2:: Oid > {
242
+ let walk = {
243
+ let mut walk = transaction. repo ( ) . revwalk ( ) ?;
244
+ walk. set_sorting ( git2:: Sort :: TOPOLOGICAL ) ?;
245
+ walk. push ( filtered) ?;
246
+ walk
247
+ } ;
248
+ tracing:: info!( "new branch base?" ) ;
249
+
250
+ for rev in walk {
251
+ let rev = rev?;
252
+ if let Ok ( base) = find_unapply_base ( transaction, bm, filter, contained_in, rev) {
253
+ if base != git2:: Oid :: zero ( ) {
254
+ tracing:: info!( "new branch base: {:?}" , base) ;
255
+ let base =
256
+ if let Ok ( new_base) = find_oldest_similar_commit ( transaction, filter, base) {
257
+ new_base
258
+ } else {
259
+ base
260
+ } ;
261
+ tracing:: info!( "inserting in bm {}, {}" , rev, base) ;
262
+ bm. insert ( rev, base) ;
263
+ return Ok ( rev) ;
264
+ }
265
+ }
266
+ }
267
+ tracing:: info!( "new branch base not found" ) ;
268
+ return Ok ( git2:: Oid :: zero ( ) ) ;
269
+ }
270
+
202
271
#[ tracing:: instrument( skip( transaction) ) ]
203
272
pub fn unapply_filter (
204
273
transaction : & cache:: Transaction ,
@@ -213,12 +282,30 @@ pub fn unapply_filter(
213
282
let mut bm = std:: collections:: HashMap :: new ( ) ;
214
283
let mut ret = original_target;
215
284
285
+ let old = if old == git2:: Oid :: zero ( ) {
286
+ match find_new_branch_base ( transaction, & mut bm, filterobj, original_target, new) {
287
+ Ok ( res) => {
288
+ tracing:: info!( "No error, branch base {} " , res) ;
289
+ res
290
+ }
291
+ Err ( _) => {
292
+ tracing:: info!( "Error in new branch base" ) ;
293
+ old
294
+ }
295
+ }
296
+ } else {
297
+ tracing:: info!( "Old not zero" ) ;
298
+ old
299
+ } ;
300
+
301
+ tracing:: info!( "before walk" ) ;
302
+
216
303
let walk = {
217
304
let mut walk = transaction. repo ( ) . revwalk ( ) ?;
218
305
walk. set_sorting ( git2:: Sort :: REVERSE | git2:: Sort :: TOPOLOGICAL ) ?;
219
306
walk. push ( new) ?;
220
307
if walk. hide ( old) . is_ok ( ) {
221
- tracing:: trace !( "walk: hidden {}" , old) ;
308
+ tracing:: info !( "walk: hidden {}" , old) ;
222
309
} else {
223
310
tracing:: warn!( "walk: can't hide" ) ;
224
311
}
@@ -230,6 +317,7 @@ pub fn unapply_filter(
230
317
231
318
let s = tracing:: span!( tracing:: Level :: TRACE , "walk commit" , ?rev) ;
232
319
let _e = s. enter ( ) ;
320
+ tracing:: info!( "walk commit: {:?}" , rev) ;
233
321
234
322
let module_commit = transaction. repo ( ) . find_commit ( rev) ?;
235
323
0 commit comments