mbox series

[v4,0/7] Finish converting git bisect to C part 3

Message ID 20210125191710.45161-1-mirucam@gmail.com (mailing list archive)
Headers show
Series Finish converting git bisect to C part 3 | expand

Message

Miriam R. Jan. 25, 2021, 7:17 p.m. UTC
These patches correspond to a third part of patch series 
of Outreachy project "Finish converting `git bisect` from shell to C" 
started by Pranit Bauva and Tanushree Tumane
(https://public-inbox.org/git/pull.117.git.gitgitgadget@gmail.com) and
continued by me.

This third part is formed by reimplementations of some `git bisect` 
subcommands and removal of some temporary subcommands.

These patch series emails were generated from:
https://gitlab.com/mirucam/git/commits/git-bisect-work-part3_v3.

I would like to thank Rafael Silva and Junio Hamano for their
reviews and suggestions.

Specific changes
----------------

[1/7] bisect--helper: reimplement `bisect_log` shell function in C
* Add a missing space.
---

[2/7] bisect--helper: reimplement `bisect_replay` shell function in C
* Fix declaration after statement warning.


Pranit Bauva (7):
  bisect--helper: reimplement `bisect_log` shell function in C
  bisect--helper: reimplement `bisect_replay` shell function in C
  bisect--helper: retire `--bisect-write` subcommand
  bisect--helper: use `res` instead of return in BISECT_RESET case
    option
  bisect--helper: retire `--bisect-auto-next` subcommand
  bisect--helper: reimplement `bisect_skip` shell function in C
  bisect--helper: retire `--check-and-set-terms` subcommand

 builtin/bisect--helper.c | 179 ++++++++++++++++++++++++++++++++-------
 git-bisect.sh            |  58 +------------
 2 files changed, 151 insertions(+), 86 deletions(-)

Comments

Junio C Hamano Jan. 26, 2021, 5:55 p.m. UTC | #1
Miriam Rubio <mirucam@gmail.com> writes:

> These patches correspond to a third part of patch series 
> of Outreachy project "Finish converting `git bisect` from shell to C" 
> started by Pranit Bauva and Tanushree Tumane
> (https://public-inbox.org/git/pull.117.git.gitgitgadget@gmail.com) and
> continued by me.

Did we lose [2/7] somewhere in the mailing list?  I see the same
thing as what is shown in

https://lore.kernel.org/git/20210125191710.45161-1-mirucam@gmail.com/

i.e. a 7-patch series that lack its second part.

Thanks.
Miriam R. Jan. 26, 2021, 6:27 p.m. UTC | #2
Hi Junio,

El mar, 26 ene 2021 a las 18:55, Junio C Hamano (<gitster@pobox.com>) escribió:
>
> Miriam Rubio <mirucam@gmail.com> writes:
>
> > These patches correspond to a third part of patch series
> > of Outreachy project "Finish converting `git bisect` from shell to C"
> > started by Pranit Bauva and Tanushree Tumane
> > (https://public-inbox.org/git/pull.117.git.gitgitgadget@gmail.com) and
> > continued by me.
>
> Did we lose [2/7] somewhere in the mailing list?  I see the same
> thing as what is shown in
>
> https://lore.kernel.org/git/20210125191710.45161-1-mirucam@gmail.com/
>
> i.e. a 7-patch series that lack its second part.

I received the [2/7] patch:

-------------------------------------------
De: Miriam Rubio <mirucam@gmail.com>
Date: lun, 25 ene 2021 a las 20:17
Subject: [PATCH v4 2/7] bisect--helper: reimplement `bisect_replay`
shell function in C
To: <git@vger.kernel.org>
Cc: Pranit Bauva <pranit.bauva@gmail.com>, Lars Schneider
<larsxschneider@gmail.com>, Christian Couder
<chriscool@tuxfamily.org>, Johannes Schindelin
<Johannes.Schindelin@gmx.de>, Tanushree Tumane
<tanushreetumane@gmail.com>, Miriam Rubio <mirucam@gmail.com>


From: Pranit Bauva <pranit.bauva@gmail.com>

Reimplement the `bisect_replay` shell function in C and also add
`--bisect-replay` subcommand to `git bisect--helper` to call it from
git-bisect.sh

Using `--bisect-replay` subcommand is a temporary measure to port shell
function to C so as to use the existing test suite.

Mentored-by: Lars Schneider <larsxschneider@gmail.com>
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 | 85 +++++++++++++++++++++++++++++++++++++++-
 git-bisect.sh            | 34 +---------------
 2 files changed, 85 insertions(+), 34 deletions(-)

diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
index a65244a0f5..d65b2f44c6 100644
--- a/builtin/bisect--helper.c
+++ b/builtin/bisect--helper.c
@@ -31,6 +31,7 @@ static const char * const git_bisect_helper_usage[] = {
        N_("git bisect--helper --bisect-auto-next"),
        N_("git bisect--helper --bisect-state (bad|new) [<rev>]"),
        N_("git bisect--helper --bisect-state (good|old) [<rev>...]"),
+       N_("git bisect--helper --bisect-replay <filename>"),
        NULL
 };

@@ -916,6 +917,79 @@ static enum bisect_error bisect_log(void)
        return status ? BISECT_FAILED : BISECT_OK;
 }

+static int process_replay_line(struct bisect_terms *terms, struct strbuf *line)
+{
+       const char *p = line->buf + strspn(line->buf, " \t");
+       char *word_end, *rev;
+
+       if ((!skip_prefix(p, "git bisect", &p) &&
+       !skip_prefix(p, "git-bisect", &p)) || !isspace(*p))
+               return 0;
+       p += strspn(p, " \t");
+
+       word_end = (char *)p + strcspn(p, " \t");
+       rev = word_end + strspn(word_end, " \t");
+       *word_end = '\0'; /* NUL-terminate the word */
+
+       get_terms(terms);
+       if (check_and_set_terms(terms, p))
+               return -1;
+
+       if (!strcmp(p, "start")) {
+               struct strvec argv = STRVEC_INIT;
+               int res;
+               sq_dequote_to_strvec(rev, &argv);
+               res = bisect_start(terms, argv.v, argv.nr);
+               strvec_clear(&argv);
+               return res;
+       }
+
+       if (one_of(p, terms->term_good,
+          terms->term_bad, "skip", NULL))
+               return bisect_write(p, rev, terms, 0);
+
+       if (!strcmp(p, "terms")) {
+               struct strvec argv = STRVEC_INIT;
+               int res;
+               sq_dequote_to_strvec(rev, &argv);
+               res = bisect_terms(terms, argv.nr == 1 ? argv.v[0] : NULL);
+               strvec_clear(&argv);
+               return res;
+       }
+       error(_("'%s'?? what are you talking about?"), p);
+
+       return -1;
+}
+
+static enum bisect_error bisect_replay(struct bisect_terms *terms,
const char *filename)
+{
+       FILE *fp = NULL;
+       enum bisect_error res = BISECT_OK;
+       struct strbuf line = STRBUF_INIT;
+
+       if (is_empty_or_missing_file(filename))
+               return error(_("cannot read file '%s' for replaying"),
filename);
+
+       if (bisect_reset(NULL))
+               return BISECT_FAILED;
+
+       fp = fopen(filename, "r");
+       if (!fp)
+               return BISECT_FAILED;
+
+       while ((strbuf_getline(&line, fp) != EOF) && !res){
+               res = process_replay_line(terms, &line);
+       }
+
+       strbuf_release(&line);
+       fclose(fp);
+
+       if (res)
+               return BISECT_FAILED;
+
+       return bisect_auto_next(terms, NULL);
+}
+
 int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
 {
        enum {
@@ -929,7 +1003,8 @@ int cmd_bisect__helper(int argc, const char
**argv, const char *prefix)
                BISECT_NEXT,
                BISECT_AUTO_NEXT,
                BISECT_STATE,
-               BISECT_LOG
+               BISECT_LOG,
+               BISECT_REPLAY
        } cmdmode = 0;
        int res = 0, nolog = 0;
        struct option options[] = {
@@ -953,6 +1028,8 @@ int cmd_bisect__helper(int argc, const char
**argv, const char *prefix)
                         N_("mark the state of ref (or refs)"), BISECT_STATE),
                OPT_CMDMODE(0, "bisect-log", &cmdmode,
                         N_("list the bisection steps so far"), BISECT_LOG),
+               OPT_CMDMODE(0, "bisect-replay", &cmdmode,
+                        N_("replay the bisection process from the
given file"), BISECT_REPLAY),
                OPT_BOOL(0, "no-log", &nolog,
                         N_("no log for BISECT_WRITE")),
                OPT_END()
@@ -1020,6 +1097,12 @@ int cmd_bisect__helper(int argc, const char
**argv, const char *prefix)
                        return error(_("--bisect-log requires 0 arguments"));
                res = bisect_log();
                break;
+       case BISECT_REPLAY:
+               if (argc != 1)
+                       return error(_("no logfile given"));
+               set_terms(&terms, "bad", "good");
+               res = bisect_replay(&terms, argv[0]);
+               break;
        default:
                BUG("unknown subcommand %d", cmdmode);
        }
diff --git a/git-bisect.sh b/git-bisect.sh
index 05863cc142..e834154e29 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -77,38 +77,6 @@ bisect_visualize() {
        eval '"$@"' --bisect -- $(cat "$GIT_DIR/BISECT_NAMES")
 }

-bisect_replay () {
-       file="$1"
-       test "$#" -eq 1 || die "$(gettext "No logfile given")"
-       test -r "$file" || die "$(eval_gettext "cannot read \$file for
replaying")"
-       git bisect--helper --bisect-reset || exit
-       oIFS="$IFS" IFS="$IFS$(printf '\015')"
-       while read git bisect command rev tail
-       do
-               test "$git $bisect" = "git bisect" || test "$git" =
"git-bisect" || continue
-               if test "$git" = "git-bisect"
-               then
-                       rev="$command"
-                       command="$bisect"
-               fi
-               get_terms
-               git bisect--helper --check-and-set-terms "$command"
"$TERM_GOOD" "$TERM_BAD" || exit
-               get_terms
-               case "$command" in
-               start)
-                       eval "git bisect--helper --bisect-start $rev $tail" ;;
-               "$TERM_GOOD"|"$TERM_BAD"|skip)
-                       git bisect--helper --bisect-write "$command"
"$rev" "$TERM_GOOD" "$TERM_BAD" || exit;;
-               terms)
-                       git bisect--helper --bisect-terms $rev || exit;;
-               *)
-                       die "$(gettext "?? what are you talking about?")" ;;
-               esac
-       done <"$file"
-       IFS="$oIFS"
-       git bisect--helper --bisect-auto-next || exit
-}
-
 bisect_run () {
        git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit

@@ -203,7 +171,7 @@ case "$#" in
        reset)
                git bisect--helper --bisect-reset "$@" ;;
        replay)
-               bisect_replay "$@" ;;
+               git bisect--helper --bisect-replay "$@" || exit;;
        log)
                git bisect--helper --bisect-log || exit ;;
        run)
--
2.29.2
>
I have to resend only this patch to the mailing list? or what I have to do?
Thank you.
Miriam.
> Thanks.
Junio C Hamano Jan. 26, 2021, 8:05 p.m. UTC | #3
> > Did we lose [2/7] somewhere in the mailing list?  I see the same
> > thing as what is shown in
> >
> > https://lore.kernel.org/git/20210125191710.45161-1-mirucam@gmail.com/
> >
> > i.e. a 7-patch series that lack its second part.
>
> I received the [2/7] patch:
>
> -------------------------------------------
> De: Miriam Rubio <mirucam@gmail.com>
> Date: lun, 25 ene 2021 a las 20:17
> Subject: [PATCH v4 2/7] bisect--helper: reimplement `bisect_replay`
> shell function in C
> To: <git@vger.kernel.org>
> Cc: Pranit Bauva <pranit.bauva@gmail.com>, Lars Schneider
> <larsxschneider@gmail.com>, Christian Couder
> <chriscool@tuxfamily.org>, Johannes Schindelin
> <Johannes.Schindelin@gmx.de>, Tanushree Tumane
> <tanushreetumane@gmail.com>, Miriam Rubio <mirucam@gmail.com>

It does not count---you are on the direct path of the message
and are not relying on the list to relay it back to you.

It seems that today's one of those days that the mailing list is
hiccupping. The message I am responding to, which is sent both
to the list and directly to me, hasn't appeared either on the public-inbox
or the lore list archive, either.

Hopefully we'll see all 7 messages eventually ;-).
Junio C Hamano Jan. 26, 2021, 10:32 p.m. UTC | #4
Junio C Hamano <gitster@pobox.com> writes:

>> > Did we lose [2/7] somewhere in the mailing list?  I see the same
>> > thing as what is shown in
>> >
>> > https://lore.kernel.org/git/20210125191710.45161-1-mirucam@gmail.com/
>> >
>> > i.e. a 7-patch series that lack its second part.
>>
>> I received the [2/7] patch:
>>
>> -------------------------------------------
>> De: Miriam Rubio <mirucam@gmail.com>
>> Date: lun, 25 ene 2021 a las 20:17
>> Subject: [PATCH v4 2/7] bisect--helper: reimplement `bisect_replay`
>> shell function in C
>> To: <git@vger.kernel.org>
>> Cc: Pranit Bauva <pranit.bauva@gmail.com>, Lars Schneider
>> <larsxschneider@gmail.com>, Christian Couder
>> <chriscool@tuxfamily.org>, Johannes Schindelin
>> <Johannes.Schindelin@gmx.de>, Tanushree Tumane
>> <tanushreetumane@gmail.com>, Miriam Rubio <mirucam@gmail.com>
>
> It does not count---you are on the direct path of the message
> and are not relying on the list to relay it back to you.
>
> It seems that today's one of those days that the mailing list is
> hiccupping. The message I am responding to, which is sent both
> to the list and directly to me, hasn't appeared either on the public-inbox
> or the lore list archive, either.
>
> Hopefully we'll see all 7 messages eventually ;-).

Now I am seeing it on the lore NNTP server (so presumably it has
been relayed to list subscribers).
Miriam R. Jan. 27, 2021, 2:12 p.m. UTC | #5
Hi Junio,

El mar, 26 ene 2021 a las 23:32, Junio C Hamano (<gitster@pobox.com>) escribió:
>
> Junio C Hamano <gitster@pobox.com> writes:
>
> >> > Did we lose [2/7] somewhere in the mailing list?  I see the same
> >> > thing as what is shown in
> >> >
> >> > https://lore.kernel.org/git/20210125191710.45161-1-mirucam@gmail.com/
> >> >
> >> > i.e. a 7-patch series that lack its second part.
> >>
> >> I received the [2/7] patch:
> >>
> >> -------------------------------------------
> >> De: Miriam Rubio <mirucam@gmail.com>
> >> Date: lun, 25 ene 2021 a las 20:17
> >> Subject: [PATCH v4 2/7] bisect--helper: reimplement `bisect_replay`
> >> shell function in C
> >> To: <git@vger.kernel.org>
> >> Cc: Pranit Bauva <pranit.bauva@gmail.com>, Lars Schneider
> >> <larsxschneider@gmail.com>, Christian Couder
> >> <chriscool@tuxfamily.org>, Johannes Schindelin
> >> <Johannes.Schindelin@gmx.de>, Tanushree Tumane
> >> <tanushreetumane@gmail.com>, Miriam Rubio <mirucam@gmail.com>
> >
> > It does not count---you are on the direct path of the message
> > and are not relying on the list to relay it back to you.
> >
> > It seems that today's one of those days that the mailing list is
> > hiccupping. The message I am responding to, which is sent both
> > to the list and directly to me, hasn't appeared either on the public-inbox
> > or the lore list archive, either.
> >
> > Hopefully we'll see all 7 messages eventually ;-).
>
> Now I am seeing it on the lore NNTP server (so presumably it has
> been relayed to list subscribers).
Ok, perfect!
Best,
Miriam
>