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 v3 06/12] bisect--helper: finish porting `bisect_start()` to C
Date: Fri, 22 May 2020 23:08:12 +0200 (CEST) [thread overview]
Message-ID: <nycvar.QRO.7.76.6.2005222256130.56@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <20200423070704.39872-7-mirucam@gmail.com>
Hi Miriam,
On Thu, 23 Apr 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()`.
>
> 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".
I do not see any "handle" in the diff...
> As "trap" is a reference to the shell "trap" builtin, which isn't
> used anymore.
Otherwise, the commit message looks good to me!
>
> 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 | 54 +++++++++++++++++++++++++++++++---------
> git-bisect.sh | 26 ++-----------------
> 2 files changed, 44 insertions(+), 36 deletions(-)
>
> diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
> index c6aaa8eb15..f2ec7f89e4 100644
> --- a/builtin/bisect--helper.c
> +++ b/builtin/bisect--helper.c
> @@ -588,11 +588,12 @@ 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, int no_checkout,
> +static enum bisect_error bisect_start(struct bisect_terms *terms, int no_checkout,
> const char **argv, int argc)
> {
> 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;
> @@ -645,9 +646,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 BISECT_FAILED;
> + }
Makes sense.
>
> string_list_append(&revs, oid_to_hex(&oid));
> free(commit_id);
> @@ -725,12 +729,12 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
> * Get rid of any old bisect state.
> */
> if (bisect_clean_state())
> - return -1;
> + return BISECT_FAILED;
>
> /*
> - * 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".
> */
>
> @@ -746,7 +750,7 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
> }
> if (update_ref(NULL, "BISECT_HEAD", &oid, NULL, 0,
> UPDATE_REFS_MSG_ON_ERR)) {
> - res = -1;
> + res = BISECT_FAILED;
> goto finish;
> }
> }
> @@ -758,25 +762,51 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
> 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, or signals received,
> + * "bisect_auto_next" below may exit or misbehave.
This "below" was true in the shell script version, but now it should be
"above".
> + * We have to handle this to be able to clean up using
> + * "bisect_clean_state".
> + * return code BISECT_INTERNAL_SUCCESS_MERGE_BASE is special code
> + * that indicates special success.
Maybe we should have a helper function and use it here:
static int is_bisect_success(enum bisect_error res)
{
return !res ||
res == BISECT_INTERNAL_1ST_BAD_FOUND ||
res == BISECT_INTERNAL_SUCCESS_MERGE_BASE;
}
(Note that I added the `_1ST_BAD_FOUND` case here.)
> + * -> 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 = BISECT_INTERNAL_SUCCESS_MERGE_BASE
While this might be an interesting tidbit for the commit message, I do not
think that it is a good idea to keep this as a code comment; It is prone
to become stale/incorrect over time.
> + */
> + if (res && res != BISECT_INTERNAL_SUCCESS_MERGE_BASE)
> + bisect_clean_state();
> return res;
> }
>
> diff --git a/git-bisect.sh b/git-bisect.sh
> index 897825b675..049ffacdff 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 "$@"
> @@ -162,8 +141,7 @@ bisect_replay () {
> get_terms
> case "$command" in
> start)
> - cmd="bisect_start $rev"
> - eval "$cmd" ;;
> + eval "git bisect--helper --bisect-start $rev" ;;
The original code _had_ to use `eval` because `bisect_start` could cause
the code to `exit` and we did _not_ want to let that exit the `replay`
process.
However, we are calling `git bisect--helper` here, which runs in its own
process anyway, so the `eval` should be dropped now.
Otherwise, the patch looks fine to me,
Dscho
> "$TERM_GOOD"|"$TERM_BAD"|skip)
> git bisect--helper --bisect-write "$command" "$rev" "$TERM_GOOD" "$TERM_BAD" || exit;;
> terms)
> @@ -262,7 +240,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.25.0
>
>
next prev parent reply other threads:[~2020-05-22 21:08 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-23 7:06 [PATCH v3 00/12] Finish converting git bisect to C part 2 Miriam Rubio
2020-04-23 7:06 ` [PATCH v3 01/12] bisect--helper: fix `cmd_*()` function switch default return Miriam Rubio
2020-05-22 13:14 ` Johannes Schindelin
2020-04-23 7:06 ` [PATCH v3 02/12] bisect--helper: use '-res' in 'cmd_bisect__helper' return Miriam Rubio
2020-05-22 13:16 ` Johannes Schindelin
2020-04-23 7:06 ` [PATCH v3 03/12] bisect--helper: introduce new `write_in_file()` function Miriam Rubio
2020-05-22 13:25 ` Johannes Schindelin
2020-05-23 1:53 ` Đoàn Trần Công Danh
2020-04-23 7:06 ` [PATCH v3 04/12] bisect--helper: reimplement `bisect_autostart` shell function in C Miriam Rubio
2020-05-22 19:27 ` Johannes Schindelin
2020-05-22 20:50 ` Johannes Schindelin
2020-04-23 7:06 ` [PATCH v3 05/12] bisect--helper: reimplement `bisect_next` and `bisect_auto_next` shell functions " Miriam Rubio
2020-05-22 20:47 ` Johannes Schindelin
2020-04-23 7:06 ` [PATCH v3 06/12] bisect--helper: finish porting `bisect_start()` to C Miriam Rubio
2020-05-22 21:08 ` Johannes Schindelin [this message]
2020-04-23 7:06 ` [PATCH v3 07/12] bisect--helper: retire `--bisect-clean-state` subcommand Miriam Rubio
2020-04-23 7:07 ` [PATCH v3 08/12] bisect--helper: retire `--next-all` subcommand Miriam Rubio
2020-04-23 7:07 ` [PATCH v3 09/12] bisect--helper: reimplement `bisect_state` & `bisect_head` shell functions in C Miriam Rubio
2020-05-22 22:06 ` Johannes Schindelin
2020-06-20 8:04 ` Miriam R.
2020-06-19 13:57 ` Johannes Schindelin
2020-04-23 7:07 ` [PATCH v3 10/12] bisect--helper: retire `--check-expected-revs` subcommand Miriam Rubio
2020-04-23 7:07 ` [PATCH v3 11/12] bisect--helper: retire `--write-terms` subcommand Miriam Rubio
2020-04-23 7:07 ` [PATCH v3 12/12] bisect--helper: retire `--bisect-autostart` subcommand Miriam Rubio
2020-04-23 20:01 ` [PATCH v3 00/12] Finish converting git bisect to C part 2 Junio C Hamano
2020-04-25 10:57 ` Miriam R.
2020-05-22 22:09 ` Johannes Schindelin
2020-05-24 21:19 ` 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.2005222256130.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).