@@ -329,12 +329,12 @@ static int check_and_set_terms(struct bisect_terms *terms, const char *cmd)
329
329
return 0 ;
330
330
}
331
331
332
- static int mark_good (const char * refname , const struct object_id * oid ,
333
- int flag , void * cb_data )
332
+ static int inc_nr (const char * refname , const struct object_id * oid ,
333
+ int flag , void * cb_data )
334
334
{
335
- int * m_good = (int * )cb_data ;
336
- * m_good = 0 ;
337
- return 1 ;
335
+ unsigned int * nr = (unsigned int * )cb_data ;
336
+ ( * nr ) ++ ;
337
+ return 0 ;
338
338
}
339
339
340
340
static const char need_bad_and_good_revision_warning [] =
@@ -384,23 +384,64 @@ static int decide_next(const struct bisect_terms *terms,
384
384
vocab_good , vocab_bad , vocab_good , vocab_bad );
385
385
}
386
386
387
- static int bisect_next_check ( const struct bisect_terms * terms ,
388
- const char * current_term )
387
+ static void bisect_status ( struct bisect_state * state ,
388
+ const struct bisect_terms * terms )
389
389
{
390
- int missing_good = 1 , missing_bad = 1 ;
391
390
char * bad_ref = xstrfmt ("refs/bisect/%s" , terms -> term_bad );
392
391
char * good_glob = xstrfmt ("%s-*" , terms -> term_good );
393
392
394
393
if (ref_exists (bad_ref ))
395
- missing_bad = 0 ;
394
+ state -> nr_bad = 1 ;
396
395
397
- for_each_glob_ref_in (mark_good , good_glob , "refs/bisect/" ,
398
- (void * ) & missing_good );
396
+ for_each_glob_ref_in (inc_nr , good_glob , "refs/bisect/" ,
397
+ (void * ) & state -> nr_good );
399
398
400
399
free (good_glob );
401
400
free (bad_ref );
401
+ }
402
402
403
- return decide_next (terms , current_term , missing_good , missing_bad );
403
+ __attribute__((format (printf , 1 , 2 )))
404
+ static void bisect_log_printf (const char * fmt , ...)
405
+ {
406
+ struct strbuf buf = STRBUF_INIT ;
407
+ va_list ap ;
408
+
409
+ va_start (ap , fmt );
410
+ strbuf_vaddf (& buf , fmt , ap );
411
+ va_end (ap );
412
+
413
+ printf ("%s" , buf .buf );
414
+ append_to_file (git_path_bisect_log (), "# %s" , buf .buf );
415
+
416
+ strbuf_release (& buf );
417
+ }
418
+
419
+ static void bisect_print_status (const struct bisect_terms * terms )
420
+ {
421
+ struct bisect_state state = { 0 };
422
+
423
+ bisect_status (& state , terms );
424
+
425
+ /* If we had both, we'd already be started, and shouldn't get here. */
426
+ if (state .nr_good && state .nr_bad )
427
+ return ;
428
+
429
+ if (!state .nr_good && !state .nr_bad )
430
+ bisect_log_printf (_ ("status: waiting for both good and bad commits\n" ));
431
+ else if (state .nr_good )
432
+ bisect_log_printf (Q_ ("status: waiting for bad commit, %d good commit known\n" ,
433
+ "status: waiting for bad commit, %d good commits known\n" ,
434
+ state .nr_good ), state .nr_good );
435
+ else
436
+ bisect_log_printf (_ ("status: waiting for good commit(s), bad commit known\n" ));
437
+ }
438
+
439
+ static int bisect_next_check (const struct bisect_terms * terms ,
440
+ const char * current_term )
441
+ {
442
+ struct bisect_state state = { 0 };
443
+ bisect_status (& state , terms );
444
+ return decide_next (terms , current_term , !state .nr_good , !state .nr_bad );
404
445
}
405
446
406
447
static int get_terms (struct bisect_terms * terms )
@@ -606,8 +647,10 @@ static enum bisect_error bisect_next(struct bisect_terms *terms, const char *pre
606
647
607
648
static enum bisect_error bisect_auto_next (struct bisect_terms * terms , const char * prefix )
608
649
{
609
- if (bisect_next_check (terms , NULL ))
650
+ if (bisect_next_check (terms , NULL )) {
651
+ bisect_print_status (terms );
610
652
return BISECT_OK ;
653
+ }
611
654
612
655
return bisect_next (terms , prefix );
613
656
}
0 commit comments