Skip to content

Commit 945b9f2

Browse files
committed
Merge branch 'cd/bisect-messages-from-pre-flight-states'
"git bisect" was too silent before it is ready to start computing the actual bisection, which has been corrected. * cd/bisect-messages-from-pre-flight-states: bisect: output bisect setup status in bisect log bisect: output state before we are ready to compute bisection
2 parents 9a7176d + f11046e commit 945b9f2

File tree

3 files changed

+93
-13
lines changed

3 files changed

+93
-13
lines changed

bisect.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ enum bisect_error {
6262
BISECT_INTERNAL_SUCCESS_MERGE_BASE = -11
6363
};
6464

65+
/*
66+
* Stores how many good/bad commits we have stored for a bisect. nr_bad can
67+
* only be 0 or 1.
68+
*/
69+
struct bisect_state {
70+
unsigned int nr_good;
71+
unsigned int nr_bad;
72+
};
73+
6574
enum bisect_error bisect_next_all(struct repository *r, const char *prefix);
6675

6776
int estimate_bisect_steps(int all);

builtin/bisect--helper.c

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,12 @@ static int check_and_set_terms(struct bisect_terms *terms, const char *cmd)
329329
return 0;
330330
}
331331

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)
334334
{
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;
338338
}
339339

340340
static const char need_bad_and_good_revision_warning[] =
@@ -384,23 +384,64 @@ static int decide_next(const struct bisect_terms *terms,
384384
vocab_good, vocab_bad, vocab_good, vocab_bad);
385385
}
386386

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)
389389
{
390-
int missing_good = 1, missing_bad = 1;
391390
char *bad_ref = xstrfmt("refs/bisect/%s", terms->term_bad);
392391
char *good_glob = xstrfmt("%s-*", terms->term_good);
393392

394393
if (ref_exists(bad_ref))
395-
missing_bad = 0;
394+
state->nr_bad = 1;
396395

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);
399398

400399
free(good_glob);
401400
free(bad_ref);
401+
}
402402

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);
404445
}
405446

406447
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
606647

607648
static enum bisect_error bisect_auto_next(struct bisect_terms *terms, const char *prefix)
608649
{
609-
if (bisect_next_check(terms, NULL))
650+
if (bisect_next_check(terms, NULL)) {
651+
bisect_print_status(terms);
610652
return BISECT_OK;
653+
}
611654

612655
return bisect_next(terms, prefix);
613656
}

t/t6030-bisect-porcelain.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,4 +1025,32 @@ test_expect_success 'bisect visualize with a filename with dash and space' '
10251025
git bisect visualize -p -- "-hello 2"
10261026
'
10271027

1028+
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+
1044+
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+
10281056
test_done

0 commit comments

Comments
 (0)