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

[PATCH 13/29] bisect--helper: finish porting `bisect_start()` to C

From
Miriam Rubio <mirucam@gmail.com>
Date
Jan 20, 2020, 14:37 UTC
Message-ID
<20200120143800.900-14-mirucam@gmail.com>
In-Reply-To
<20200120143800.900-1-mirucam@gmail.com>
From: Pranit Bauva <pranit.bauva@gmail.com>

Add the subcommand to `git bisect--helper` and call it from git-bisect.sh.

With the conversion of `bisect_auto_next()` from shell to C in a previous commit, `bisect_start()` can now be fully ported to C.

So let's complete the `--bisect-start` subcommand of `git bisect--helper` so that it fully implements `bisect_start()`, and let's use this subcommand in `git-bisect.sh` instead of `bisect_start()`.

This removes the signal handling we had in `bisect_start()` as we don't really need it. While at it, "trap" is changed to "handle". As "trap" is a reference to the shell "trap" builtin, which isn't used anymore.

Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
Signed-off-by: Tanushree Tumane <tanushreetumane@gmail.com>
Signed-off-by: Miriam Rubio <mirucam@gmail.com>
---
 builtin/bisect--helper.c | 38 +++++++++++++++++++++++++++++++++-----
 git-bisect.sh            | 29 +++--------------------------
 2 files changed, 36 insertions(+), 31 deletions(-)
diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
index 29bbc1573b..e604334c91 100644
--- a/builtin/bisect--helper.c
+++ b/builtin/bisect--helper.c
@@ -632,9 +632,12 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
 			return error(_("unrecognized option: '%s'"), arg);
 		} else {
 			char *commit_id = xstrfmt("%s^{commit}", arg);
-			if (get_oid(commit_id, &oid) && has_double_dash)
-				die(_("'%s' does not appear to be a valid "
-				      "revision"), arg);
+			if (get_oid(commit_id, &oid) && has_double_dash) {
+				error(_("'%s' does not appear to be a valid "
+					"revision"), arg);
+				free(commit_id);
+				return -1;
+			}
 
 			string_list_append(&revs, oid_to_hex(&oid));
 			free(commit_id);
@@ -715,9 +718,9 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
 		return -1;
 
 	/*
-	 * In case of mistaken revs or checkout error, or signals received,
+	 * In case of mistaken revs or checkout error,
 	 * "bisect_auto_next" below may exit or misbehave.
-	 * We have to trap this to be able to clean up using
+	 * We have to handle this to be able to clean up using
 	 * "bisect_clean_state".
 	 */
 
@@ -764,6 +767,31 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
 	string_list_clear(&states, 0);
 	strbuf_release(&start_head);
 	strbuf_release(&bisect_names);
+	if (res)
+		return res;
+
+	res = bisect_auto_next(terms, NULL);
+	/*
+	 * In case of mistaken revs or checkout error, or signals received,
+	 * "bisect_auto_next" below may exit or misbehave.
+	 * We have to handle this to be able to clean up using
+	 * "bisect_clean_state".
+	 * return code -11 is special code that indicates special success.
+	 *	-> bisect_start()
+	 *	   . res = bisect_auto_next()
+	 *	    -> bisect_auto_next()
+	 *	       . return bisect_next()
+	 *	       -> bisect_next()
+	 *		  . res = bisect_next_all()
+	 *		  -> bisect_next_all()
+	 *		     . res = check_good_are_ancestors_of_bad()
+	 *		     -> check_good_are_ancestors_of_bad()
+	 *			. res = check_merge_bases()
+	 *			-> check_merge_bases()
+	 *			   . res = -11
+	 */
+	if (res && res != -11)
+		bisect_clean_state();
 	return res;
 }
 
diff --git a/git-bisect.sh b/git-bisect.sh
index 7531b74708..fec527e1ef 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -63,35 +63,13 @@ bisect_autostart() {
 			[Nn]*)
 				exit ;;
 			esac
-			bisect_start
+			git bisect--helper --bisect-start
 		else
 			exit 1
 		fi
 	}
 }
 
-bisect_start() {
-	git bisect--helper --bisect-start $@ || exit
-
-	#
-	# Change state.
-	# In case of mistaken revs or checkout error, or signals received,
-	# "bisect_auto_next" below may exit or misbehave.
-	# We have to trap this to be able to clean up using
-	# "bisect_clean_state".
-	#
-	trap 'git bisect--helper --bisect-clean-state' 0
-	trap 'exit 255' 1 2 3 15
-
-	#
-	# Check if we can proceed to the next bisect state.
-	#
-	get_terms
-	git bisect--helper --bisect-auto-next || exit
-
-	trap '-' 0
-}
-
 bisect_skip() {
 	all=''
 	for arg in "$@"
@@ -184,8 +162,7 @@ bisect_replay () {
 		get_terms
 		case "$command" in
 		start)
-			cmd="bisect_start $rev"
-			eval "$cmd" ;;
+			eval "git bisect--helper --bisect-start $rev" ;;
 		"$TERM_GOOD"|"$TERM_BAD"|skip)
 			git bisect--helper --bisect-write "$command" "$rev" "$TERM_GOOD" "$TERM_BAD" || exit;;
 		terms)
@@ -284,7 +261,7 @@ case "$#" in
 	help)
 		git bisect -h ;;
 	start)
-		bisect_start "$@" ;;
+		git bisect--helper --bisect-start "$@" ;;
 	bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD")
 		bisect_state "$cmd" "$@" ;;
 	skip)
-- 
2.21.1 (Apple Git-122.3)
Previous: Johannes SchindelinNext: Miriam Rubio
Message 28 of 54 in “Finish converting git bisect to C part 1”
  1. Miriam RubioJan 20, 2020
  2. 03/29 bisect: use the standard 'if (!var)' way to check for 0Miriam Rubio, Jan 20, 2020
  3. 01/29 bisect--helper: convert `vocab_*` char pointers to char arraysMiriam Rubio, Jan 20, 2020
  4. 02/29 bisect--helper: change `retval` to `res`Miriam Rubio, Jan 20, 2020
  5. 07/29 bisect: libify `bisect_checkout`Miriam Rubio, Jan 20, 2020
  6. 08/29 bisect: libify `check_merge_bases` and its dependentsMiriam Rubio, Jan 20, 2020
  7. Johannes SchindelinJan 20, 2020
  8. Miriam R.Jan 21, 2020
  9. 04/29 run-command: make `exists_in_PATH()` non-staticMiriam Rubio, Jan 20, 2020
  10. 09/29 bisect: libify `check_good_are_ancestors_of_bad` and its dependentsMiriam Rubio, Jan 20, 2020
  11. Johannes SchindelinJan 20, 2020
  12. Christian CouderJan 21, 2020
  13. Miriam R.Jan 21, 2020
  14. 05/29 bisect--helper: introduce new `decide_next()` functionMiriam Rubio, Jan 20, 2020
  15. 10/29 bisect: libify `handle_bad_merge_base` and its dependentsMiriam Rubio, Jan 20, 2020
  16. Johannes SchindelinJan 20, 2020
  17. Christian CouderJan 21, 2020
  18. Miriam R.Jan 21, 2020
  19. 11/29 bisect: libify `bisect_next_all`Miriam Rubio, Jan 20, 2020
  20. Johannes SchindelinJan 20, 2020
  21. Christian CouderJan 21, 2020
  22. Johannes SchindelinJan 30, 2020
  23. 12/29 bisect--helper: reimplement `bisect_next` and `bisect_auto_next` shell functions in CMiriam Rubio, Jan 20, 2020
  24. Johannes SchindelinJan 30, 2020
  25. Miriam R.Jan 31, 2020
  26. Christian CouderFeb 17, 2020
  27. Johannes SchindelinFeb 17, 2020
  28. 13/29 bisect--helper: finish porting `bisect_start()` to CMiriam Rubio, Jan 20, 2020
  29. 06/29 bisect: libify `exit_if_skipped_commits` to `error_if_skipped*` and its dependentsMiriam Rubio, Jan 20, 2020
  30. Johannes SchindelinJan 20, 2020
  31. Christian CouderJan 21, 2020
  32. Miriam R.Jan 21, 2020
  33. 14/29 bisect--helper: retire `--bisect-clean-state` subcommandMiriam Rubio, Jan 20, 2020
  34. 15/29 bisect--helper: retire `--next-all` subcommandMiriam Rubio, Jan 20, 2020
  35. 17/29 bisect--helper: reimplement `bisect_state` & `bisect_head` shell functions in CMiriam Rubio, Jan 20, 2020
  36. 16/29 bisect--helper: reimplement `bisect_autostart` shell function in CMiriam Rubio, Jan 20, 2020
  37. 19/29 bisect--helper: retire `--write-terms` subcommandMiriam Rubio, Jan 20, 2020
  38. 18/29 bisect--helper: retire `--check-expected-revs` subcommandMiriam Rubio, Jan 20, 2020
  39. 20/29 bisect--helper: reimplement `bisect_log` shell function in CMiriam Rubio, Jan 20, 2020
  40. 21/29 bisect--helper: reimplement `bisect_replay` shell function in CMiriam Rubio, Jan 20, 2020
  41. 22/29 bisect--helper: retire `--bisect-write` subcommandMiriam Rubio, Jan 20, 2020
  42. 24/29 bisect--helper: retire `--bisect-autostart` subcommandMiriam Rubio, Jan 20, 2020
  43. 25/29 bisect--helper: retire `--bisect-auto-next` subcommandMiriam Rubio, Jan 20, 2020
  44. 23/29 bisect--helper: use `res` instead of return in BISECT_RESET case optionMiriam Rubio, Jan 20, 2020
  45. 26/29 bisect--helper: reimplement `bisect_skip` shell function in CMiriam Rubio, Jan 20, 2020
  46. 27/29 bisect--helper: retire `--check-and-set-terms` subcommandMiriam Rubio, Jan 20, 2020
  47. 28/29 bisect--helper: reimplement `bisect_visualize()`shell function in CMiriam Rubio, Jan 20, 2020
  48. 29/29 bisect--helper: reimplement `bisect_run` shell function in CMiriam Rubio, Jan 20, 2020
  49. Johannes SchindelinJan 20, 2020
  50. Christian CouderJan 20, 2020
  51. Johannes SchindelinJan 30, 2020
  52. Junio C HamanoJan 30, 2020
  53. Miriam R.Jan 21, 2020
  54. Johannes SchindelinJan 30, 2020

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.