git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Miriam Rubio <mirucam@gmail.com>
Cc: git@vger.kernel.org, Pranit Bauva <pranit.bauva@gmail.com>,
	Christian Couder <chriscool@tuxfamily.org>,
	Tanushree Tumane <tanushreetumane@gmail.com>
Subject: Re: [PATCH v7 07/13] bisect--helper: finish porting `bisect_start()` to C
Date: Thu, 3 Sep 2020 11:56:50 +0200 (CEST)	[thread overview]
Message-ID: <nycvar.QRO.7.76.6.2009031151500.56@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <20200831105043.97665-8-mirucam@gmail.com>

Hi Miriam,

On Mon, 31 Aug 2020, Miriam Rubio wrote:

> 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()`.
>
> 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 | 56 ++++++++++++++++++++++++++++------------
>  git-bisect.sh            | 26 ++-----------------
>  2 files changed, 41 insertions(+), 41 deletions(-)
>
> diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
> index e29e86142a..b40369e8aa 100644
> --- a/builtin/bisect--helper.c
> +++ b/builtin/bisect--helper.c
> @@ -85,6 +85,19 @@ static int one_of(const char *term, ...)
>  	return res;
>  }
>
> +/*
> + * return code BISECT_INTERNAL_SUCCESS_MERGE_BASE
> + * and BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND are codes
> + * that indicate special success.
> + */
> +
> +static int is_bisect_success(enum bisect_error res)
> +{
> +	return !res ||
> +		res == BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND ||
> +		res == BISECT_INTERNAL_SUCCESS_MERGE_BASE;
> +}
> +
>  static int write_in_file(const char *path, const char *mode, const char *format, va_list args)
>  {
>  	FILE *fp = NULL;
> @@ -607,12 +620,13 @@ static enum bisect_error bisect_auto_next(struct bisect_terms *terms, const char
>  	return bisect_next(terms, prefix);
>  }
>
> -static int bisect_start(struct bisect_terms *terms, const char **argv, int argc)
> +static enum bisect_error bisect_start(struct bisect_terms *terms, const char **argv, int argc)
>  {
>  	int no_checkout = 0;
>  	int first_parent_only = 0;
>  	int i, has_double_dash = 0, must_write_terms = 0, bad_seen = 0;
> -	int flags, pathspec_pos, res = 0;
> +	int flags, pathspec_pos;
> +	enum bisect_error res = BISECT_OK;
>  	struct string_list revs = STRING_LIST_INIT_DUP;
>  	struct string_list states = STRING_LIST_INIT_DUP;
>  	struct strbuf start_head = STRBUF_INIT;
> @@ -672,9 +686,12 @@ static int bisect_start(struct bisect_terms *terms, const char **argv, int argc)
>  			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 BISECT_FAILED;
> +			}
>
>  			string_list_append(&revs, oid_to_hex(&oid));
>  			free(commit_id);
> @@ -752,14 +769,7 @@ static int bisect_start(struct bisect_terms *terms, const char **argv, int argc)
>  	 * Get rid of any old bisect state.
>  	 */
>  	if (bisect_clean_state())
> -		return -1;
> -
> -	/*
> -	 * 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".
> -	 */
> +		return BISECT_FAILED;
>
>  	/*
>  	 * Write new start state
> @@ -776,7 +786,7 @@ static int bisect_start(struct bisect_terms *terms, const char **argv, int argc)
>  		}
>  		if (update_ref(NULL, "BISECT_HEAD", &oid, NULL, 0,
>  			       UPDATE_REFS_MSG_ON_ERR)) {
> -			res = -1;
> +			res = BISECT_FAILED;
>  			goto finish;
>  		}
>  	}
> @@ -788,25 +798,37 @@ static int bisect_start(struct bisect_terms *terms, const char **argv, int argc)
>  	for (i = 0; i < states.nr; i++)
>  		if (bisect_write(states.items[i].string,
>  				 revs.items[i].string, terms, 1)) {
> -			res = -1;
> +			res = BISECT_FAILED;
>  			goto finish;
>  		}
>
>  	if (must_write_terms && write_terms(terms->term_bad,
>  					    terms->term_good)) {
> -		res = -1;
> +		res = BISECT_FAILED;
>  		goto finish;
>  	}
>
>  	res = bisect_append_log_quoted(argv);
>  	if (res)
> -		res = -1;
> +		res = BISECT_FAILED;
>
>  finish:
>  	string_list_clear(&revs, 0);
>  	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,
> +	 * "bisect_auto_next" above may exit or misbehave.
> +	 * We have to handle this to be able to clean up using
> +	 * "bisect_clean_state".
> +	 */

Is this comment still correct in the C version? I thought we had succeeded
in removing that shell scripting wart by turning all the `exit`s into
`return`s...

> +	if (!is_bisect_success(res))
> +		bisect_clean_state();
>  	return res;
>  }
>
> diff --git a/git-bisect.sh b/git-bisect.sh
> index 59424f5b37..356264caf0 100755
> --- a/git-bisect.sh
> +++ b/git-bisect.sh
> @@ -49,27 +49,6 @@ bisect_head()
>  	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.
> -	#
> -	git bisect--helper --bisect-auto-next || exit
> -
> -	trap '-' 0
> -}
> -
>  bisect_skip() {
>  	all=''
>  	for arg in "$@"
> @@ -163,8 +142,7 @@ bisect_replay () {
>  		get_terms
>  		case "$command" in
>  		start)
> -			cmd="bisect_start $rev $tail"
> -			eval "$cmd" ;;
> +			eval "git bisect--helper --bisect-start $rev $tail" ;;

I think we need to append something like `test 0 = $? || exit $?` here, as
the `eval`ed command can no longer exit.

In fact, I think that the `eval` here no longer makes sense, as the only
reason we did that before was that `bisect_start` could `exit` and we did
not want that here.

>  		"$TERM_GOOD"|"$TERM_BAD"|skip)
>  			git bisect--helper --bisect-write "$command" "$rev" "$TERM_GOOD" "$TERM_BAD" || exit;;
>  		terms)
> @@ -264,7 +242,7 @@ case "$#" in
>  	help)
>  		git bisect -h ;;
>  	start)
> -		bisect_start "$@" ;;
> +		git bisect--helper --bisect-start "$@" ;;

I guess we do not need to append `|| exit` here because this will be the
last command in the script to be executed anyway, therefore its exit
status will become the exit status of the script.

Thank you,
Johannes

>  	bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD")
>  		bisect_state "$cmd" "$@" ;;
>  	skip)
> --
> 2.25.0
>
>

  reply	other threads:[~2020-09-03 18:21 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-31 10:50 [PATCH v7 00/13] Finish converting git bisect to C part 2 Miriam Rubio
2020-08-31 10:50 ` [PATCH v7 01/13] bisect--helper: BUG() in cmd_*() on invalid subcommand Miriam Rubio
2020-08-31 10:50 ` [PATCH v7 02/13] bisect--helper: use '-res' in 'cmd_bisect__helper' return Miriam Rubio
2020-08-31 10:50 ` [PATCH v7 03/13] bisect--helper: introduce new `write_in_file()` function Miriam Rubio
2020-08-31 10:50 ` [PATCH v7 04/13] bisect--helper: reimplement `bisect_autostart` shell function in C Miriam Rubio
2020-09-03  5:50   ` Johannes Schindelin
2020-08-31 10:50 ` [PATCH v7 05/13] bisect: call 'clear_commit_marks_all()' in 'bisect_next_all()' Miriam Rubio
2020-08-31 10:50 ` [PATCH v7 06/13] bisect--helper: reimplement `bisect_next` and `bisect_auto_next` shell functions in C Miriam Rubio
2020-09-03  9:48   ` Johannes Schindelin
2020-08-31 10:50 ` [PATCH v7 07/13] bisect--helper: finish porting `bisect_start()` to C Miriam Rubio
2020-09-03  9:56   ` Johannes Schindelin [this message]
2020-08-31 10:50 ` [PATCH v7 08/13] bisect--helper: retire `--bisect-clean-state` subcommand Miriam Rubio
2020-08-31 10:50 ` [PATCH v7 09/13] bisect--helper: retire `--next-all` subcommand Miriam Rubio
2020-08-31 10:50 ` [PATCH v7 10/13] bisect--helper: reimplement `bisect_state` & `bisect_head` shell functions in C Miriam Rubio
2020-09-03 12:03   ` Johannes Schindelin
2020-08-31 10:50 ` [PATCH v7 11/13] bisect--helper: retire `--check-expected-revs` subcommand Miriam Rubio
2020-08-31 10:50 ` [PATCH v7 12/13] bisect--helper: retire `--write-terms` subcommand Miriam Rubio
2020-08-31 10:50 ` [PATCH v7 13/13] bisect--helper: retire `--bisect-autostart` subcommand Miriam Rubio
2020-09-03 12:04 ` [PATCH v7 00/13] Finish converting git bisect to C part 2 Johannes Schindelin
2020-09-23  7:26   ` Miriam R.
2020-09-23 14:48     ` Johannes Schindelin
2020-09-23 21:23       ` Johannes Schindelin
2020-09-24  5:33         ` Christian Couder
2020-09-24  7:56           ` Johannes Schindelin
2020-09-24 10:46             ` Christian Couder
2020-09-24 12:53               ` Miriam R.
2020-09-24 12:56         ` Miriam R.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=nycvar.QRO.7.76.6.2009031151500.56@tvgsbejvaqbjf.bet \
    --to=johannes.schindelin@gmx.de \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=mirucam@gmail.com \
    --cc=pranit.bauva@gmail.com \
    --cc=tanushreetumane@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).