Skip to contentSkip to conversation

bisect: status improvements when bisect is not fully fleshed out

PATCH In review Chris Down 2 participants 4 messages May 11, 2022

lore
Share & tools
lore

Chris Down

author
#0 lore raw

v3 cover bisect: status improvements when bisect is not fully fleshed out

When bisecting, we currently don't output anything before bisection starts in earnest, which can result in some confusion. For example, in the case illustrated in the first commit in this patch series, it's trivial to accidentally misspell a tag or branch and accidentally end up in an unintended state with no clear indication about what happened.

This patch series makes it so that we give information about bisect state even before the bisect is ready to begin. We also store these changes in state to the bisect log.

v2:

- Move to improve bisect output overall, instead of just warning for the specific unintended pathspec case.

v3:

- Fix test indentation
- Rename bs to state
- Use `unsigned int' for nr_{good,bad}
- Pass the bisect state struct as an argument into bisect_print_status
- Zero-initialise bisect_state directly, don't use memset()
- Fix multiline comment style in bisect.h
- Use strbuf in bisect_log_printf
- Change `git bisect log' use an output file in tests instead of piping

Chris Down (2):
bisect: output state before we are ready to compute bisection
bisect: output bisect setup status in bisect log

 bisect.h                    |  9 +++++
 builtin/bisect--helper.c    | 69 ++++++++++++++++++++++++++++++-------
 t/t6030-bisect-porcelain.sh | 28 +++++++++++++++
 3 files changed, 93 insertions(+), 13 deletions(-)
Signature · 1 line
2.36.0
author
#1 lore raw

PATCH v3 1/2 bisect: output state before we are ready to compute bisection

Commit 73c6de06aff8 ("bisect: don't use invalid oid as rev when starting") changes the behaviour of git bisect to consider invalid oids as pathspecs again, as in the old shell implementation.

While that behaviour may be desirable, it can also cause confusion. For example, while bisecting in a particular repo I encountered this:

    $ git bisect start d93ff48803f0 v6.3
    $

...which led to me sitting for a few moments, wondering why there's no printout stating the first rev to check.

It turns out that the tag was actually "6.3", not "v6.3", and thus the bisect was still silently started with only a bad rev, because d93ff48803f0 was a valid oid and "v6.3" was silently considered to be a pathspec.

While this behaviour may be desirable, it can be confusing, especially with different repo conventions either using or not using "v" before release names, or when a branch name or tag is simply misspelled on the command line.

In order to avoid situations like this, make it more clear what we're waiting for:

    $ git bisect start d93ff48803f0 v6.3
    status: waiting for good commit(s), bad commit known

We already have good output once the bisect process has begun in earnest, so we don't need to do anything more there.

---
 bisect.h                    |  9 +++++++
 builtin/bisect--helper.c    | 53 ++++++++++++++++++++++++++++---------
 t/t6030-bisect-porcelain.sh | 18 +++++++++++++
 3 files changed, 67 insertions(+), 13 deletions(-)
bisect.h +9 -0
index 1015aeb8ea..ee3fd65f3b 100644
@@ -62,6 +62,15 @@ enum bisect_error {
 	BISECT_INTERNAL_SUCCESS_MERGE_BASE = -11
 };
 
+/*
+ * Stores how many good/bad commits we have stored for a bisect. nr_bad can
+ * only be 0 or 1.
+ */
+struct bisect_state {
+	unsigned int nr_good;
+	unsigned int nr_bad;
+};
+
 enum bisect_error bisect_next_all(struct repository *r, const char *prefix);
 
 int estimate_bisect_steps(int all);
builtin/bisect--helper.c +40 -13

83 lines not on this page · raw message

t/t6030-bisect-porcelain.sh +18 -0
index 5382e5d216..686f6d5c7f 100755
@@ -1025,4 +1025,22 @@ test_expect_success 'bisect visualize with a filename with dash and space' '
 	git bisect visualize -p -- "-hello 2"
 '
 
+test_expect_success 'bisect state output with multiple good commits' '
+	git bisect reset &&
+	git bisect start >output &&
+	grep "waiting for both good and bad commits" output &&
+	git bisect good "$HASH1" >output &&
+	grep "waiting for bad commit, 1 good commit known" output &&
+	git bisect good "$HASH2" >output &&
+	grep "waiting for bad commit, 2 good commits known" output
+'
+
+test_expect_success 'bisect state output with bad commit' '
+	git bisect reset &&
+	git bisect start >output &&
+	grep "waiting for both good and bad commits" output &&
+	git bisect bad "$HASH4" >output &&
+	grep -F "waiting for good commit(s), bad commit known" output
+'
+
 test_done
Signature · 1 line
2.36.0
author
#2 lore raw

PATCH v3 2/2 bisect: output bisect setup status in bisect log

In reply to Chris Down

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
---
 builtin/bisect--helper.c    | 26 +++++++++++++++++++++-----
 t/t6030-bisect-porcelain.sh | 10 ++++++++++
 2 files changed, 31 insertions(+), 5 deletions(-)
builtin/bisect--helper.c +21 -5
index fa8024a864..e358e3dd5b 100644
@@ -400,6 +400,22 @@ static void bisect_status(struct bisect_state *state,
 	free(bad_ref);
 }
 
+__attribute__((format (printf, 1, 2)))
+static void bisect_log_printf(const char *fmt, ...)
+{
+	struct strbuf buf = STRBUF_INIT;
+	va_list ap;
+
+	va_start(ap, fmt);
+	strbuf_vaddf(&buf, fmt, ap);
+	va_end(ap);
+
+	printf("%s", buf.buf);
+	append_to_file(git_path_bisect_log(), "# %s", buf.buf);
+
+	strbuf_release(&buf);
+}
+
 static void bisect_print_status(const struct bisect_terms *terms)
 {
 	struct bisect_state state = { 0 };
@@ -411,13 +427,13 @@ static void bisect_print_status(const struct bisect_terms *terms)
 		return;
 
 	if (!state.nr_good && !state.nr_bad)
-		printf(_("status: waiting for both good and bad commits\n"));
+		bisect_log_printf(_("status: waiting for both good and bad commits\n"));
 	else if (state.nr_good)
-		printf(Q_("status: waiting for bad commit, %d good commit known\n",
-			  "status: waiting for bad commit, %d good commits known\n",
-			  state.nr_good), state.nr_good);
+		bisect_log_printf(Q_("status: waiting for bad commit, %d good commit known\n",
+				     "status: waiting for bad commit, %d good commits known\n",
+				     state.nr_good), state.nr_good);
 	else
-		printf(_("status: waiting for good commit(s), bad commit known\n"));
+		bisect_log_printf(_("status: waiting for good commit(s), bad commit known\n"));
 }
 
 static int bisect_next_check(const struct bisect_terms *terms,
t/t6030-bisect-porcelain.sh +10 -0
index 686f6d5c7f..83931d482f 100755
@@ -1029,9 +1029,15 @@ test_expect_success 'bisect state output with multiple good commits' '
 	git bisect reset &&
 	git bisect start >output &&
 	grep "waiting for both good and bad commits" output &&
+	git bisect log >output &&
+	grep "waiting for both good and bad commits" output &&
 	git bisect good "$HASH1" >output &&
 	grep "waiting for bad commit, 1 good commit known" output &&
+	git bisect log >output &&
+	grep "waiting for bad commit, 1 good commit known" output &&
 	git bisect good "$HASH2" >output &&
+	grep "waiting for bad commit, 2 good commits known" output &&
+	git bisect log >output &&
 	grep "waiting for bad commit, 2 good commits known" output
 '
 
@@ -1039,7 +1045,11 @@ test_expect_success 'bisect state output with bad commit' '
 	git bisect reset &&
 	git bisect start >output &&
 	grep "waiting for both good and bad commits" output &&
+	git bisect log >output &&
+	grep "waiting for both good and bad commits" output &&
 	git bisect bad "$HASH4" >output &&
+	grep -F "waiting for good commit(s), bad commit known" output &&
+	git bisect log >output &&
 	grep -F "waiting for good commit(s), bad commit known" output
 '
 
Signature · 1 line
2.36.0
#3 lore raw
In reply to Chris Down
Quoted 17 lines · Chris Down

When bisecting, we currently don't output anything before bisection starts in earnest, which can result in some confusion. For example, in the case illustrated in the first commit in this patch series, it's trivial to accidentally misspell a tag or branch and accidentally end up in an unintended state with no clear indication about what happened.

This patch series makes it so that we give information about bisect state even before the bisect is ready to begin. We also store these changes in state to the bisect log.

v2:

- Move to improve bisect output overall, instead of just warning for the specific unintended pathspec case.

v3:

Quoted 8 lines

- Fix test indentation
- Rename bs to state
- Use `unsigned int' for nr_{good,bad}
- Pass the bisect state struct as an argument into bisect_print_status
- Zero-initialise bisect_state directly, don't use memset()
- Fix multiline comment style in bisect.h
- Use strbuf in bisect_log_printf
- Change `git bisect log' use an output file in tests instead of piping

Will replace. Unless there are more inputs, let's merge it to 'next'. This round looks more than good enough to me.

Thanks.