From: Miriam Rubio <mirucam@gmail.com>
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>
Subject: [PATCH v2 2/7] bisect--helper: reimplement `bisect_replay` shell function in C
Date: Mon, 21 Dec 2020 17:27:38 +0100 [thread overview]
Message-ID: <20201221162743.96056-3-mirucam@gmail.com> (raw)
In-Reply-To: <20201221162743.96056-1-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 | 127 ++++++++++++++++++++++++++++++++++++++-
git-bisect.sh | 34 +----------
2 files changed, 127 insertions(+), 34 deletions(-)
diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
index 1854377fa6..92c783237d 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,121 @@ static enum bisect_error bisect_log(void)
return status ? BISECT_FAILED : BISECT_OK;
}
+static int get_next_word(const char *line, int pos, struct strbuf *word)
+{
+ int i, len = strlen(line), begin = 0;
+
+ strbuf_reset(word);
+ for (i = pos; i < len; i++) {
+ if (line[i] == ' ' && begin)
+ return i + 1;
+
+ if (!begin)
+ begin = 1;
+ strbuf_addch(word, line[i]);
+ }
+
+ return i;
+}
+
+static int process_line(struct bisect_terms *terms, struct strbuf *line, struct strbuf *word)
+{
+ int res = 0;
+ int pos = 0;
+
+ while (pos < line->len) {
+ pos = get_next_word(line->buf, pos, word);
+
+ if (!strcmp(word->buf, "git"))
+ continue;
+ else if (!strcmp(word->buf, "git-bisect"))
+ continue;
+ else if (!strcmp(word->buf, "bisect"))
+ continue;
+ else if (starts_with(word->buf, "#"))
+ break;
+
+ get_terms(terms);
+ if (check_and_set_terms(terms, word->buf))
+ return -1;
+
+ if (!strcmp(word->buf, "start")) {
+ struct strvec argv = STRVEC_INIT;
+ int res;
+ sq_dequote_to_strvec(line->buf+pos, &argv);
+ res = bisect_start(terms, argv.v, argv.nr);
+ strvec_clear(&argv);
+ if (res)
+ return -1;
+ break;
+ }
+
+ if (one_of(word->buf, terms->term_good,
+ terms->term_bad, "skip", NULL)) {
+ if (bisect_write(word->buf, line->buf+pos, terms, 0))
+ return -1;
+ break;
+ }
+
+ if (!strcmp(word->buf, "terms")) {
+ struct strvec argv = STRVEC_INIT;
+ int res;
+ sq_dequote_to_strvec(line->buf+pos, &argv);
+ res = bisect_terms(terms, argv.nr == 1 ? argv.v[0] : NULL);
+ strvec_clear(&argv);
+ if (res)
+ return -1;
+ break;
+ }
+
+ error(_("Replay file contains rubbish (\"%s\")"),
+ word->buf);
+ res = -1;
+ }
+ return res;
+}
+
+static int process_replay_file(FILE *fp, struct bisect_terms *terms)
+{
+ struct strbuf line = STRBUF_INIT;
+ struct strbuf word = STRBUF_INIT;
+ int res = 0;
+
+ while (strbuf_getline(&line, fp) != EOF) {
+ res = process_line(terms, &line, &word);
+ if (res)
+ break;
+ }
+
+ strbuf_release(&line);
+ strbuf_release(&word);
+ return res;
+}
+
+static enum bisect_error bisect_replay(struct bisect_terms *terms, const char *filename)
+{
+ FILE *fp = NULL;
+ enum bisect_error res = BISECT_OK;
+
+ 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;
+
+ res = process_replay_file(fp, terms);
+ 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 +1045,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 +1070,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_("output the contents of BISECT_LOG"), 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 +1139,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 c6149846ff..79bcd31bd7 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
next prev parent reply other threads:[~2020-12-21 18:32 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-21 16:27 [PATCH v2 0/7] Finish converting git bisect to C part 3 Miriam Rubio
2020-12-21 16:27 ` [PATCH v2 1/7] bisect--helper: reimplement `bisect_log` shell function in C Miriam Rubio
2021-01-18 15:02 ` Johannes Schindelin
2020-12-21 16:27 ` Miriam Rubio [this message]
2020-12-22 0:15 ` [PATCH v2 2/7] bisect--helper: reimplement `bisect_replay` " Rafael Silva
2020-12-23 0:23 ` Rafael Silva
2020-12-23 1:36 ` Junio C Hamano
2020-12-23 10:03 ` Rafael Silva
2020-12-23 20:09 ` Junio C Hamano
2021-01-18 15:59 ` Johannes Schindelin
2020-12-21 16:27 ` [PATCH v2 3/7] bisect--helper: retire `--bisect-write` subcommand Miriam Rubio
2020-12-21 16:27 ` [PATCH v2 4/7] bisect--helper: use `res` instead of return in BISECT_RESET case option Miriam Rubio
2020-12-21 16:27 ` [PATCH v2 5/7] bisect--helper: retire `--bisect-auto-next` subcommand Miriam Rubio
2020-12-21 16:27 ` [PATCH v2 6/7] bisect--helper: reimplement `bisect_skip` shell function in C Miriam Rubio
2021-01-18 16:14 ` Johannes Schindelin
2020-12-21 16:27 ` [PATCH v2 7/7] bisect--helper: retire `--check-and-set-terms` subcommand Miriam Rubio
2021-01-18 16:15 ` [PATCH v2 0/7] Finish converting git bisect to C part 3 Johannes Schindelin
2021-01-18 23:53 ` 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
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=20201221162743.96056-3-mirucam@gmail.com \
--to=mirucam@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=larsxschneider@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).