9
9
#include "run-command.h"
10
10
#include "log-tree.h"
11
11
#include "bisect.h"
12
-
13
- struct sha1_array {
14
- unsigned char (* sha1 )[20 ];
15
- int sha1_nr ;
16
- int sha1_alloc ;
17
- int sorted ;
18
- };
12
+ #include "sha1-array.h"
19
13
20
14
static struct sha1_array good_revs ;
21
15
static struct sha1_array skipped_revs ;
@@ -425,22 +419,15 @@ static void argv_array_push_sha1(struct argv_array *array,
425
419
argv_array_push (array , strbuf_detach (& buf , NULL ));
426
420
}
427
421
428
- static void sha1_array_push (struct sha1_array * array ,
429
- const unsigned char * sha1 )
430
- {
431
- ALLOC_GROW (array -> sha1 , array -> sha1_nr + 1 , array -> sha1_alloc );
432
- hashcpy (array -> sha1 [array -> sha1_nr ++ ], sha1 );
433
- }
434
-
435
422
static int register_ref (const char * refname , const unsigned char * sha1 ,
436
423
int flags , void * cb_data )
437
424
{
438
425
if (!strcmp (refname , "bad" )) {
439
426
current_bad_sha1 = sha1 ;
440
427
} else if (!prefixcmp (refname , "good-" )) {
441
- sha1_array_push (& good_revs , sha1 );
428
+ sha1_array_append (& good_revs , sha1 );
442
429
} else if (!prefixcmp (refname , "skip-" )) {
443
- sha1_array_push (& skipped_revs , sha1 );
430
+ sha1_array_append (& skipped_revs , sha1 );
444
431
}
445
432
446
433
return 0 ;
@@ -477,41 +464,14 @@ static void read_bisect_paths(struct argv_array *array)
477
464
fclose (fp );
478
465
}
479
466
480
- static int array_cmp (const void * a , const void * b )
481
- {
482
- return hashcmp (a , b );
483
- }
484
-
485
- static void sort_sha1_array (struct sha1_array * array )
486
- {
487
- qsort (array -> sha1 , array -> sha1_nr , sizeof (* array -> sha1 ), array_cmp );
488
-
489
- array -> sorted = 1 ;
490
- }
491
-
492
- static const unsigned char * sha1_access (size_t index , void * table )
493
- {
494
- unsigned char (* array )[20 ] = table ;
495
- return array [index ];
496
- }
497
-
498
- static int lookup_sha1_array (struct sha1_array * array ,
499
- const unsigned char * sha1 )
500
- {
501
- if (!array -> sorted )
502
- sort_sha1_array (array );
503
-
504
- return sha1_pos (sha1 , array -> sha1 , array -> sha1_nr , sha1_access );
505
- }
506
-
507
467
static char * join_sha1_array_hex (struct sha1_array * array , char delim )
508
468
{
509
469
struct strbuf joined_hexs = STRBUF_INIT ;
510
470
int i ;
511
471
512
- for (i = 0 ; i < array -> sha1_nr ; i ++ ) {
472
+ for (i = 0 ; i < array -> nr ; i ++ ) {
513
473
strbuf_addstr (& joined_hexs , sha1_to_hex (array -> sha1 [i ]));
514
- if (i + 1 < array -> sha1_nr )
474
+ if (i + 1 < array -> nr )
515
475
strbuf_addch (& joined_hexs , delim );
516
476
}
517
477
@@ -546,13 +506,13 @@ struct commit_list *filter_skipped(struct commit_list *list,
546
506
if (count )
547
507
* count = 0 ;
548
508
549
- if (!skipped_revs .sha1_nr )
509
+ if (!skipped_revs .nr )
550
510
return list ;
551
511
552
512
while (list ) {
553
513
struct commit_list * next = list -> next ;
554
514
list -> next = NULL ;
555
- if (0 <= lookup_sha1_array (& skipped_revs ,
515
+ if (0 <= sha1_array_lookup (& skipped_revs ,
556
516
list -> item -> object .sha1 )) {
557
517
if (skipped_first && !* skipped_first )
558
518
* skipped_first = 1 ;
@@ -647,7 +607,7 @@ static struct commit_list *managed_skipped(struct commit_list *list,
647
607
648
608
* tried = NULL ;
649
609
650
- if (!skipped_revs .sha1_nr )
610
+ if (!skipped_revs .nr )
651
611
return list ;
652
612
653
613
list = filter_skipped (list , tried , 0 , & count , & skipped_first );
@@ -672,7 +632,7 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
672
632
/* rev_argv.argv[0] will be ignored by setup_revisions */
673
633
argv_array_push (& rev_argv , xstrdup ("bisect_rev_setup" ));
674
634
argv_array_push_sha1 (& rev_argv , current_bad_sha1 , bad_format );
675
- for (i = 0 ; i < good_revs .sha1_nr ; i ++ )
635
+ for (i = 0 ; i < good_revs .nr ; i ++ )
676
636
argv_array_push_sha1 (& rev_argv , good_revs .sha1 [i ],
677
637
good_format );
678
638
argv_array_push (& rev_argv , xstrdup ("--" ));
@@ -772,12 +732,12 @@ static struct commit *get_commit_reference(const unsigned char *sha1)
772
732
773
733
static struct commit * * get_bad_and_good_commits (int * rev_nr )
774
734
{
775
- int len = 1 + good_revs .sha1_nr ;
735
+ int len = 1 + good_revs .nr ;
776
736
struct commit * * rev = xmalloc (len * sizeof (* rev ));
777
737
int i , n = 0 ;
778
738
779
739
rev [n ++ ] = get_commit_reference (current_bad_sha1 );
780
- for (i = 0 ; i < good_revs .sha1_nr ; i ++ )
740
+ for (i = 0 ; i < good_revs .nr ; i ++ )
781
741
rev [n ++ ] = get_commit_reference (good_revs .sha1 [i ]);
782
742
* rev_nr = n ;
783
743
@@ -840,9 +800,9 @@ static void check_merge_bases(void)
840
800
const unsigned char * mb = result -> item -> object .sha1 ;
841
801
if (!hashcmp (mb , current_bad_sha1 )) {
842
802
handle_bad_merge_base ();
843
- } else if (0 <= lookup_sha1_array (& good_revs , mb )) {
803
+ } else if (0 <= sha1_array_lookup (& good_revs , mb )) {
844
804
continue ;
845
- } else if (0 <= lookup_sha1_array (& skipped_revs , mb )) {
805
+ } else if (0 <= sha1_array_lookup (& skipped_revs , mb )) {
846
806
handle_skipped_merge_base (mb );
847
807
} else {
848
808
printf ("Bisecting: a merge base must be tested\n" );
@@ -903,7 +863,7 @@ static void check_good_are_ancestors_of_bad(const char *prefix)
903
863
return ;
904
864
905
865
/* Bisecting with no good rev is ok. */
906
- if (good_revs .sha1_nr == 0 )
866
+ if (good_revs .nr == 0 )
907
867
return ;
908
868
909
869
/* Check if all good revs are ancestor of the bad rev. */
@@ -968,7 +928,7 @@ int bisect_next_all(const char *prefix)
968
928
bisect_common (& revs );
969
929
970
930
revs .commits = find_bisection (revs .commits , & reaches , & all ,
971
- !!skipped_revs .sha1_nr );
931
+ !!skipped_revs .nr );
972
932
revs .commits = managed_skipped (revs .commits , & tried );
973
933
974
934
if (!revs .commits ) {
0 commit comments