@@ -212,12 +212,13 @@ int get_octopus_merge_bases(struct commit_list *in, struct commit_list **result)
212
212
}
213
213
214
214
static int remove_redundant_no_gen (struct repository * r ,
215
- struct commit * * array , int cnt )
215
+ struct commit * * array ,
216
+ size_t cnt , size_t * dedup_cnt )
216
217
{
217
218
struct commit * * work ;
218
219
unsigned char * redundant ;
219
- int * filled_index ;
220
- int i , j , filled ;
220
+ size_t * filled_index ;
221
+ size_t i , j , filled ;
221
222
222
223
CALLOC_ARRAY (work , cnt );
223
224
redundant = xcalloc (cnt , 1 );
@@ -267,20 +268,22 @@ static int remove_redundant_no_gen(struct repository *r,
267
268
for (i = filled = 0 ; i < cnt ; i ++ )
268
269
if (!redundant [i ])
269
270
array [filled ++ ] = work [i ];
271
+ * dedup_cnt = filled ;
270
272
free (work );
271
273
free (redundant );
272
274
free (filled_index );
273
- return filled ;
275
+ return 0 ;
274
276
}
275
277
276
278
static int remove_redundant_with_gen (struct repository * r ,
277
- struct commit * * array , int cnt )
279
+ struct commit * * array , size_t cnt ,
280
+ size_t * dedup_cnt )
278
281
{
279
- int i , count_non_stale = 0 , count_still_independent = cnt ;
282
+ size_t i , count_non_stale = 0 , count_still_independent = cnt ;
280
283
timestamp_t min_generation = GENERATION_NUMBER_INFINITY ;
281
284
struct commit * * walk_start , * * sorted ;
282
285
size_t walk_start_nr = 0 , walk_start_alloc = cnt ;
283
- int min_gen_pos = 0 ;
286
+ size_t min_gen_pos = 0 ;
284
287
285
288
/*
286
289
* Sort the input by generation number, ascending. This allows
@@ -326,12 +329,12 @@ static int remove_redundant_with_gen(struct repository *r,
326
329
* terminate early. Otherwise, we will do the same amount of work
327
330
* as before.
328
331
*/
329
- for (i = walk_start_nr - 1 ; i >= 0 && count_still_independent > 1 ; i -- ) {
332
+ for (i = walk_start_nr ; i && count_still_independent > 1 ; i -- ) {
330
333
/* push the STALE bits up to min generation */
331
334
struct commit_list * stack = NULL ;
332
335
333
- commit_list_insert (walk_start [i ], & stack );
334
- walk_start [i ]-> object .flags |= STALE ;
336
+ commit_list_insert (walk_start [i - 1 ], & stack );
337
+ walk_start [i - 1 ]-> object .flags |= STALE ;
335
338
336
339
while (stack ) {
337
340
struct commit_list * parents ;
@@ -388,10 +391,12 @@ static int remove_redundant_with_gen(struct repository *r,
388
391
clear_commit_marks_many (walk_start_nr , walk_start , STALE );
389
392
free (walk_start );
390
393
391
- return count_non_stale ;
394
+ * dedup_cnt = count_non_stale ;
395
+ return 0 ;
392
396
}
393
397
394
- static int remove_redundant (struct repository * r , struct commit * * array , int cnt )
398
+ static int remove_redundant (struct repository * r , struct commit * * array ,
399
+ size_t cnt , size_t * dedup_cnt )
395
400
{
396
401
/*
397
402
* Some commit in the array may be an ancestor of
@@ -401,19 +406,17 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt
401
406
* that number.
402
407
*/
403
408
if (generation_numbers_enabled (r )) {
404
- int i ;
405
-
406
409
/*
407
410
* If we have a single commit with finite generation
408
411
* number, then the _with_gen algorithm is preferred.
409
412
*/
410
- for (i = 0 ; i < cnt ; i ++ ) {
413
+ for (size_t i = 0 ; i < cnt ; i ++ ) {
411
414
if (commit_graph_generation (array [i ]) < GENERATION_NUMBER_INFINITY )
412
- return remove_redundant_with_gen (r , array , cnt );
415
+ return remove_redundant_with_gen (r , array , cnt , dedup_cnt );
413
416
}
414
417
}
415
418
416
- return remove_redundant_no_gen (r , array , cnt );
419
+ return remove_redundant_no_gen (r , array , cnt , dedup_cnt );
417
420
}
418
421
419
422
static int get_merge_bases_many_0 (struct repository * r ,
@@ -425,7 +428,8 @@ static int get_merge_bases_many_0(struct repository *r,
425
428
{
426
429
struct commit_list * list ;
427
430
struct commit * * rslt ;
428
- int cnt , i ;
431
+ size_t cnt , i ;
432
+ int ret ;
429
433
430
434
if (merge_bases_many (r , one , n , twos , result ) < 0 )
431
435
return -1 ;
@@ -452,8 +456,8 @@ static int get_merge_bases_many_0(struct repository *r,
452
456
clear_commit_marks (one , all_flags );
453
457
clear_commit_marks_many (n , twos , all_flags );
454
458
455
- cnt = remove_redundant (r , rslt , cnt );
456
- if (cnt < 0 ) {
459
+ ret = remove_redundant (r , rslt , cnt , & cnt );
460
+ if (ret < 0 ) {
457
461
free (rslt );
458
462
return -1 ;
459
463
}
@@ -582,7 +586,8 @@ struct commit_list *reduce_heads(struct commit_list *heads)
582
586
struct commit_list * p ;
583
587
struct commit_list * result = NULL , * * tail = & result ;
584
588
struct commit * * array ;
585
- int num_head , i ;
589
+ size_t num_head , i ;
590
+ int ret ;
586
591
587
592
if (!heads )
588
593
return NULL ;
@@ -603,11 +608,13 @@ struct commit_list *reduce_heads(struct commit_list *heads)
603
608
p -> item -> object .flags &= ~STALE ;
604
609
}
605
610
}
606
- num_head = remove_redundant (the_repository , array , num_head );
607
- if (num_head < 0 ) {
611
+
612
+ ret = remove_redundant (the_repository , array , num_head , & num_head );
613
+ if (ret < 0 ) {
608
614
free (array );
609
615
return NULL ;
610
616
}
617
+
611
618
for (i = 0 ; i < num_head ; i ++ )
612
619
tail = & commit_list_insert (array [i ], tail )-> next ;
613
620
free (array );
0 commit comments