bisect: output bisect setup status in bisect log

This allows seeing the current intermediate status without adding a new good or bad commit: $ git bisect log | tail -1 # status: waiting for bad commit, 1 good commit known Signed-off-by: Chris Down <chris@chrisdown.name> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Chris Down committed May 11, 2022 at 19:00 UTC f11046e6def11a281a371918793226f30e3f8c12
2 files changed +31 -5
builtin/bisect--helper.c
+21 -5
@@ -400,6 +400,22 @@ static void bisect_status(struct bisect_state *state,
400 free(bad_ref);
401 }
402
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 };
@@ -411,13 +427,13 @@ static void bisect_print_status(const struct bisect_terms *terms)
427 return;
428
429 if (!state.nr_good && !state.nr_bad)
414 - printf(_("status: waiting for both good and bad commits\n"));
430 + bisect_log_printf(_("status: waiting for both good and bad commits\n"));
431 else if (state.nr_good)
416 - printf(Q_("status: waiting for bad commit, %d good commit known\n",
417 - "status: waiting for bad commit, %d good commits known\n",
418 - state.nr_good), 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
420 - printf(_("status: waiting for good commit(s), bad commit known\n"));
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,
t/t6030-bisect-porcelain.sh
+10
@@ -1029,9 +1029,15 @@ test_expect_success 'bisect state output with multiple good commits' '
1029 git bisect reset &&
1030 git bisect start >output &&
1031 grep "waiting for both good and bad commits" output &&
1032 + git bisect log >output &&
1033 + grep "waiting for both good and bad commits" output &&
1034 git bisect good "$HASH1" >output &&
1035 grep "waiting for bad commit, 1 good commit known" output &&
1036 + git bisect log >output &&
1037 + grep "waiting for bad commit, 1 good commit known" output &&
1038 git bisect good "$HASH2" >output &&
1039 + grep "waiting for bad commit, 2 good commits known" output &&
1040 + git bisect log >output &&
1041 grep "waiting for bad commit, 2 good commits known" output
1042 '
1043
@@ -1039,7 +1045,11 @@ test_expect_success 'bisect state output with bad commit' '
1045 git bisect reset &&
1046 git bisect start >output &&
1047 grep "waiting for both good and bad commits" output &&
1048 + git bisect log >output &&
1049 + grep "waiting for both good and bad commits" output &&
1050 git bisect bad "$HASH4" >output &&
1051 + grep -F "waiting for good commit(s), bad commit known" output &&
1052 + git bisect log >output &&
1053 grep -F "waiting for good commit(s), bad commit known" output
1054 '
1055