git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] bisect: report actual bisect_state() argument on error

From
René Scharfe <l.s.r@web.de>
Date
Jan 10, 2022, 09:01 UTC
Message-ID
<5d8c8a72-6c4f-35e4-a6a4-4ed7d6f23c4e@web.de>
In-Reply-To
<fead25d6-6f5f-487a-ad4c-0657fe9785fd@www.fastmail.com>

The strvec "args" in bisect_run() is initialized and cleared, but never added to. Nevertheless its first member is printed when reporting a bisect_state() error. That's not useful, since it's always NULL.

Before d1bbbe45df (bisect--helper: reimplement `bisect_run` shell function in C, 2021-09-13) the new state was reported if it could not been set. Reinstate that behavior and remove the unused strvec.

Reported-by: Ramkumar Ramachandra <r@artagnon.com>
Signed-off-by: René Scharfe <l.s.r@web.de>
---
This doesn't fix your problem, only replace the "(null)" in the error
messages with the actual state name -- which may be useful for
diagnosing its cause, though.
Patch generated with --function-context for easier review.
 builtin/bisect--helper.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
index 28a2e6a575..1dbc6294ef 100644
--- a/builtin/bisect--helper.c
+++ b/builtin/bisect--helper.c
@@ -1092,80 +1092,76 @@ static int bisect_visualize(struct bisect_terms *terms, const char **argv, int a
 static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
 {
 	int res = BISECT_OK;
 	struct strbuf command = STRBUF_INIT;
-	struct strvec args = STRVEC_INIT;
 	struct strvec run_args = STRVEC_INIT;
 	const char *new_state;
 	int temporary_stdout_fd, saved_stdout;

 	if (bisect_next_check(terms, NULL))
 		return BISECT_FAILED;

 	if (argc)
 		sq_quote_argv(&command, argv);
 	else {
 		error(_("bisect run failed: no command provided."));
 		return BISECT_FAILED;
 	}

 	strvec_push(&run_args, command.buf);

 	while (1) {
-		strvec_clear(&args);
-
 		printf(_("running %s\n"), command.buf);
 		res = run_command_v_opt(run_args.v, RUN_USING_SHELL);

 		if (res < 0 || 128 <= res) {
 			error(_("bisect run failed: exit code %d from"
 				" '%s' is < 0 or >= 128"), res, command.buf);
 			strbuf_release(&command);
 			return res;
 		}

 		if (res == 125)
 			new_state = "skip";
 		else if (!res)
 			new_state = terms->term_good;
 		else
 			new_state = terms->term_bad;

 		temporary_stdout_fd = open(git_path_bisect_run(), O_CREAT | O_WRONLY | O_TRUNC, 0666);

 		if (temporary_stdout_fd < 0)
 			return error_errno(_("cannot open file '%s' for writing"), git_path_bisect_run());

 		fflush(stdout);
 		saved_stdout = dup(1);
 		dup2(temporary_stdout_fd, 1);

 		res = bisect_state(terms, &new_state, 1);

 		fflush(stdout);
 		dup2(saved_stdout, 1);
 		close(saved_stdout);
 		close(temporary_stdout_fd);

 		print_file_to_stdout(git_path_bisect_run());

 		if (res == BISECT_ONLY_SKIPPED_LEFT)
 			error(_("bisect run cannot continue any more"));
 		else if (res == BISECT_INTERNAL_SUCCESS_MERGE_BASE) {
 			printf(_("bisect run success"));
 			res = BISECT_OK;
 		} else if (res == BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND) {
 			printf(_("bisect found first bad commit"));
 			res = BISECT_OK;
 		} else if (res) {
 			error(_("bisect run failed: 'git bisect--helper --bisect-state"
-			" %s' exited with error code %d"), args.v[0], res);
+			" %s' exited with error code %d"), new_state, res);
 		} else {
 			continue;
 		}

 		strbuf_release(&command);
-		strvec_clear(&args);
 		strvec_clear(&run_args);
 		return res;
 	}
 }
--
2.34.1
Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 4 of 31 in “git bisect bad @”
  1. Ramkumar RamachandraJan 9, 2022
  2. Junio C HamanoJan 9, 2022
  3. Ramkumar RamachandraJan 9, 2022
  4. bisect: report actual bisect_state() argument on errorRené Scharfe, Jan 10, 2022
  5. Ramkumar RamachandraJan 10, 2022
  6. Junio C HamanoJan 10, 2022
  7. Ramkumar RamachandraJan 10, 2022
  8. René ScharfeJan 12, 2022
  9. Junio C HamanoJan 12, 2022
  10. René ScharfeJan 12, 2022
  11. René ScharfeJan 13, 2022
  12. Ramkumar RamachandraJan 13, 2022
  13. Christian CouderJan 13, 2022
  14. René ScharfeJan 13, 2022
  15. Ramkumar RamachandraJan 13, 2022
  16. René ScharfeJan 14, 2022
  17. Ramkumar RamachandraJan 14, 2022
  18. René ScharfeJan 18, 2022
  19. Junio C HamanoJan 14, 2022
  20. Junio C HamanoJan 13, 2022
  21. 1/4 bisect--helper: report actual bisect_state() argument on errorRené Scharfe, Jan 18, 2022
  22. 2/4 bisect--helper: release strbuf and strvec on run errorRené Scharfe, Jan 18, 2022
  23. 3/4 bisect: document run behavior with exit codes 126 and 127René Scharfe, Jan 18, 2022
  24. 4/4 bisect--helper: double-check run command on exit code 126 and 127René Scharfe, Jan 18, 2022
  25. Junio C HamanoJan 19, 2022
  26. René ScharfeJan 19, 2022
  27. Junio C HamanoFeb 4, 2022
  28. René ScharfeFeb 4, 2022
  29. Ramkumar RamachandraFeb 4, 2022
  30. Junio C HamanoFeb 4, 2022
  31. Ramkumar RamachandraFeb 4, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.