Re: [PATCH v4 0/7] Finish converting git bisect to C part 3

3 messages, 2 authors, 2021-01-26 · open the first message on its own page

Re: [PATCH v4 0/7] Finish converting git bisect to C part 3

From: Junio C Hamano <hidden>
Date: 2021-01-26 22:19:28

Miriam Rubio [off-list ref] 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.

Re: [PATCH v4 0/7] Finish converting git bisect to C part 3

From: Miriam R. <hidden>
Date: 2021-01-26 22:19:27

Hi Junio,

El mar, 26 ene 2021 a las 18:55, Junio C Hamano ([off-list ref]) escribió:
Miriam Rubio [off-list ref] writes:
quoted
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 [off-list ref]
Date: lun, 25 ene 2021 a las 20:17
Subject: [PATCH v4 2/7] bisect--helper: reimplement `bisect_replay`
shell function in C
To: <redacted>
Cc: Pranit Bauva <redacted>, Lars Schneider
[off-list ref], Christian Couder
[off-list ref], Johannes Schindelin
[off-list ref], Tanushree Tumane
[off-list ref], Miriam Rubio [off-list ref]


From: Pranit Bauva <redacted>

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 [off-list ref]
Mentored-by: Christian Couder [off-list ref]
Mentored-by: Johannes Schindelin [off-list ref]
Signed-off-by: Pranit Bauva <redacted>
Signed-off-by: Tanushree Tumane <redacted>
Signed-off-by: Miriam Rubio <redacted>
---
 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.

Re: [PATCH v4 0/7] Finish converting git bisect to C part 3

From: Junio C Hamano <hidden>
Date: 2021-01-26 22:19:56

quoted
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 [off-list ref]
Date: lun, 25 ene 2021 a las 20:17
Subject: [PATCH v4 2/7] bisect--helper: reimplement `bisect_replay`
shell function in C
To: <redacted>
Cc: Pranit Bauva <redacted>, Lars Schneider
[off-list ref], Christian Couder
[off-list ref], Johannes Schindelin
[off-list ref], Tanushree Tumane
[off-list ref], Miriam Rubio [off-list ref]
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 ;-).
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help