99#include "run-command.h"
1010#include "log-tree.h"
1111#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"
1913
2014static struct sha1_array good_revs ;
2115static struct sha1_array skipped_revs ;
@@ -425,22 +419,15 @@ static void argv_array_push_sha1(struct argv_array *array,
425419 argv_array_push (array , strbuf_detach (& buf , NULL ));
426420}
427421
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-
435422static int register_ref (const char * refname , const unsigned char * sha1 ,
436423 int flags , void * cb_data )
437424{
438425 if (!strcmp (refname , "bad" )) {
439426 current_bad_sha1 = sha1 ;
440427 } else if (!prefixcmp (refname , "good-" )) {
441- sha1_array_push (& good_revs , sha1 );
428+ sha1_array_append (& good_revs , sha1 );
442429 } else if (!prefixcmp (refname , "skip-" )) {
443- sha1_array_push (& skipped_revs , sha1 );
430+ sha1_array_append (& skipped_revs , sha1 );
444431 }
445432
446433 return 0 ;
@@ -477,41 +464,14 @@ static void read_bisect_paths(struct argv_array *array)
477464 fclose (fp );
478465}
479466
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-
507467static char * join_sha1_array_hex (struct sha1_array * array , char delim )
508468{
509469 struct strbuf joined_hexs = STRBUF_INIT ;
510470 int i ;
511471
512- for (i = 0 ; i < array -> sha1_nr ; i ++ ) {
472+ for (i = 0 ; i < array -> nr ; i ++ ) {
513473 strbuf_addstr (& joined_hexs , sha1_to_hex (array -> sha1 [i ]));
514- if (i + 1 < array -> sha1_nr )
474+ if (i + 1 < array -> nr )
515475 strbuf_addch (& joined_hexs , delim );
516476 }
517477
@@ -546,13 +506,13 @@ struct commit_list *filter_skipped(struct commit_list *list,
546506 if (count )
547507 * count = 0 ;
548508
549- if (!skipped_revs .sha1_nr )
509+ if (!skipped_revs .nr )
550510 return list ;
551511
552512 while (list ) {
553513 struct commit_list * next = list -> next ;
554514 list -> next = NULL ;
555- if (0 <= lookup_sha1_array (& skipped_revs ,
515+ if (0 <= sha1_array_lookup (& skipped_revs ,
556516 list -> item -> object .sha1 )) {
557517 if (skipped_first && !* skipped_first )
558518 * skipped_first = 1 ;
@@ -647,7 +607,7 @@ static struct commit_list *managed_skipped(struct commit_list *list,
647607
648608 * tried = NULL ;
649609
650- if (!skipped_revs .sha1_nr )
610+ if (!skipped_revs .nr )
651611 return list ;
652612
653613 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,
672632 /* rev_argv.argv[0] will be ignored by setup_revisions */
673633 argv_array_push (& rev_argv , xstrdup ("bisect_rev_setup" ));
674634 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 ++ )
676636 argv_array_push_sha1 (& rev_argv , good_revs .sha1 [i ],
677637 good_format );
678638 argv_array_push (& rev_argv , xstrdup ("--" ));
@@ -772,12 +732,12 @@ static struct commit *get_commit_reference(const unsigned char *sha1)
772732
773733static struct commit * * get_bad_and_good_commits (int * rev_nr )
774734{
775- int len = 1 + good_revs .sha1_nr ;
735+ int len = 1 + good_revs .nr ;
776736 struct commit * * rev = xmalloc (len * sizeof (* rev ));
777737 int i , n = 0 ;
778738
779739 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 ++ )
781741 rev [n ++ ] = get_commit_reference (good_revs .sha1 [i ]);
782742 * rev_nr = n ;
783743
@@ -840,9 +800,9 @@ static void check_merge_bases(void)
840800 const unsigned char * mb = result -> item -> object .sha1 ;
841801 if (!hashcmp (mb , current_bad_sha1 )) {
842802 handle_bad_merge_base ();
843- } else if (0 <= lookup_sha1_array (& good_revs , mb )) {
803+ } else if (0 <= sha1_array_lookup (& good_revs , mb )) {
844804 continue ;
845- } else if (0 <= lookup_sha1_array (& skipped_revs , mb )) {
805+ } else if (0 <= sha1_array_lookup (& skipped_revs , mb )) {
846806 handle_skipped_merge_base (mb );
847807 } else {
848808 printf ("Bisecting: a merge base must be tested\n" );
@@ -903,7 +863,7 @@ static void check_good_are_ancestors_of_bad(const char *prefix)
903863 return ;
904864
905865 /* Bisecting with no good rev is ok. */
906- if (good_revs .sha1_nr == 0 )
866+ if (good_revs .nr == 0 )
907867 return ;
908868
909869 /* Check if all good revs are ancestor of the bad rev. */
@@ -968,7 +928,7 @@ int bisect_next_all(const char *prefix)
968928 bisect_common (& revs );
969929
970930 revs .commits = find_bisection (revs .commits , & reaches , & all ,
971- !!skipped_revs .sha1_nr );
931+ !!skipped_revs .nr );
972932 revs .commits = managed_skipped (revs .commits , & tried );
973933
974934 if (!revs .commits ) {
0 commit comments