From: Junio C Hamano <gitster@pobox.com>
To: Miriam Rubio <mirucam@gmail.com>
Cc: git@vger.kernel.org, Pranit Bauva <pranit.bauva@gmail.com>,
Christian Couder <chriscool@tuxfamily.org>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Tanushree Tumane <tanushreetumane@gmail.com>
Subject: Re: [PATCH v6 4/6] bisect--helper: reimplement `bisect_visualize()`shell function in C
Date: Thu, 02 Sep 2021 15:28:39 -0700 [thread overview]
Message-ID: <xmqqfsumipd4.fsf@gitster.g> (raw)
In-Reply-To: <20210902090421.93113-5-mirucam@gmail.com> (Miriam Rubio's message of "Thu, 2 Sep 2021 11:04:19 +0200")
Miriam Rubio <mirucam@gmail.com> writes:
> From: Pranit Bauva <pranit.bauva@gmail.com>
Need a SP before "shell" on the title line.
> Reimplement the `bisect_visualize()` shell function
> in C and also add `--bisect-visualize` subcommand to
> `git bisect--helper` to call it from git-bisect.sh.
Nice.
> +static int bisect_visualize(struct bisect_terms *terms, const char **argv, int argc)
> +{
> + struct strvec args = STRVEC_INIT;
> + int flags = RUN_COMMAND_NO_STDIN, res = 0;
> + struct strbuf sb = STRBUF_INIT;
> +
> + if (bisect_next_check(terms, NULL) != 0)
> + return BISECT_FAILED;
> +
> + if (!argc) {
> + if ((getenv("DISPLAY") || getenv("SESSIONNAME") || getenv("MSYSTEM") ||
> + getenv("SECURITYSESSIONID")) && exists_in_PATH("gitk"))
> + strvec_push(&args, "gitk");
> + else {
> + strvec_push(&args, "log");
> + flags |= RUN_GIT_CMD;
> + }
Let's have {} on the if() side, even though it only has one
statement and does not require one, because the else side needs one.
> + } else {
> + if (argv[0][0] == '-') {
> + strvec_push(&args, "log");
> + flags |= RUN_GIT_CMD;
OK, any -option makes it "git log -option ..." invocation.
> + } else if (strcmp(argv[0], "tig") && !starts_with(argv[0], "git"))
> + flags |= RUN_GIT_CMD;
OK, when the first token is "tig", or it begins with "git", the
scripted version just leaves the command line intact. Everything
else is taken as a subcommand to git. And this conditional is a
faithful translation of that logic.
> + strvec_pushv(&args, argv);
> + }
> +
> + strvec_pushl(&args, "--bisect", "--", NULL);
> +
> + strbuf_read_file(&sb, git_path_bisect_names(), 0);
> + sq_dequote_to_strvec(sb.buf, &args);
> + strbuf_release(&sb);
> +
> + res = run_command_v_opt(args.v, flags);
> + strvec_clear(&args);
> + return res;
OK.
The code is quite easy to follow, thanks to many helpers that have
been invented for this exact purpose, like sq_dequote_to_strvec().
> diff --git a/git-bisect.sh b/git-bisect.sh
> index 6a7afaea8d..95f7f3fb8c 100755
> --- a/git-bisect.sh
> +++ b/git-bisect.sh
> @@ -39,29 +39,6 @@ _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
> TERM_BAD=bad
> TERM_GOOD=good
>
> -bisect_visualize() {
> ...
> -}
> -
> bisect_run () {
> git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit
>
> @@ -152,7 +129,7 @@ case "$#" in
> # Not sure we want "next" at the UI level anymore.
> git bisect--helper --bisect-next "$@" || exit ;;
> visualize|view)
> - bisect_visualize "$@" ;;
> + git bisect--helper --bisect-visualize "$@" || exit;;
Nice.
Thanks.
next prev parent reply other threads:[~2021-09-02 22:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-02 9:04 [PATCH v6 0/6] Finish converting git bisect to C part 4 Miriam Rubio
2021-09-02 9:04 ` [PATCH v6 1/6] t6030-bisect-porcelain: add tests to control bisect run exit cases Miriam Rubio
2021-09-02 21:44 ` Junio C Hamano
2021-09-02 9:04 ` [PATCH v6 2/6] t6030-bisect-porcelain: add test for bisect visualize Miriam Rubio
2021-09-02 22:05 ` Junio C Hamano
2021-09-02 9:04 ` [PATCH v6 3/6] run-command: make `exists_in_PATH()` non-static Miriam Rubio
2021-09-02 22:19 ` Junio C Hamano
2021-09-02 9:04 ` [PATCH v6 4/6] bisect--helper: reimplement `bisect_visualize()`shell function in C Miriam Rubio
2021-09-02 22:28 ` Junio C Hamano [this message]
2021-09-02 9:04 ` [PATCH v6 5/6] bisect--helper: reimplement `bisect_run` shell Miriam Rubio
2021-09-02 23:43 ` Junio C Hamano
2021-09-06 7:33 ` Johannes Schindelin
2021-09-06 8:34 ` Miriam R.
2021-09-07 18:32 ` Junio C Hamano
2021-09-09 7:51 ` Johannes Schindelin
2021-09-02 9:04 ` [PATCH v6 6/6] bisect--helper: retire `--bisect-next-check` subcommand Miriam Rubio
2021-09-02 23:43 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqfsumipd4.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.