From: Pranit Bauva <pranit.bauva@gmail.com>
To: git@vger.kernel.org
Cc: Pranit Bauva <pranit.bauva@gmail.com>,
Matthie.Moy@grenoble-inp.fr, christian.couder@gmail.com,
chriscool@tuxfamily.org, gitster@pobox.com
Subject: [RFC/PATCH 1/3] bisect--helper: `check_and_set_terms` shell function in C
Date: Mon, 27 Jun 2016 02:14:09 +0530 [thread overview]
Message-ID: <20160626204411.19919-1-pranit.bauva@gmail.com> (raw)
Reimplement the `check_and_set_terms` shell function in C and add
`check-and-set-terms` subcommand to `git bisect--helper` to call it from
git-bisect.sh
Using `--check-and-set-terms` subcommand is a temporary measure to port
shell function in C so as to use the existing test suite. As more
functions are ported, this subcommand will be retired and will be called
by some other methods.
check_and_set_terms() sets and receives two global variables namely
TERM_GOOD and TERM_BAD in the shell script. Luckily the file BISECT_TERMS
also contains the value of those variables so its appropriate to evoke the
method get_terms() after calling the subcommand so that it retrieves the
value of TERM_GOOD and TERM_BAD from the file BISECT_TERMS. The two
global variables are passed as arguments to the subcommand.
Also introduce bisect_terms_reinit() to release the previous memory of
struct bisect_terms and allocate new memory for it thus flushing out the
previous contents.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
---
This series applies on top of my previous patch series[1].
[1]: http://thread.gmane.org/gmane.comp.version-control.git/298263
builtin/bisect--helper.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++-
git-bisect.sh | 36 ++++----------------------------
2 files changed, 56 insertions(+), 33 deletions(-)
diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
index e946ba9..c387697 100644
--- a/builtin/bisect--helper.c
+++ b/builtin/bisect--helper.c
@@ -45,6 +45,13 @@ static int bisect_terms_release(struct bisect_terms *term)
return 0;
}
+static int bisect_terms_reinit(struct bisect_terms *term)
+{
+ bisect_terms_release(term);
+ bisect_terms_init(term);
+ return 0;
+}
+
/*
* Check whether the string `term` belongs to the set of strings
* included in the variable arguments.
@@ -254,6 +261,40 @@ static int bisect_write(const char *state, const char *rev,
return 0;
}
+static int check_and_set_terms(const char *cmd, struct bisect_terms *term)
+{
+ if (one_of(cmd, "skip", "start", "terms", NULL))
+ return 0;
+
+ if (!is_empty_or_missing_file(git_path_bisect_write_terms()) &&
+ strcmp(cmd, term->term_bad.buf) && strcmp(cmd, term->term_good.buf))
+ return error(_("Invalid command: you're currently in a"
+ "'%s' '%s' bisect"), term->term_bad.buf,
+ term->term_good.buf);
+
+ if (one_of(cmd, "bad", "good", NULL)) {
+ if (is_empty_or_missing_file(git_path_bisect_write_terms())) {
+ bisect_terms_reinit(term);
+ strbuf_addstr(&term->term_bad, "bad");
+ strbuf_addstr(&term->term_good, "good");
+ return write_terms(term->term_bad.buf,
+ term->term_good.buf);
+ }
+ }
+
+ if (one_of(cmd, "new", "old", NULL)) {
+ if (is_empty_or_missing_file(git_path_bisect_write_terms())) {
+ bisect_terms_reinit(term);
+ strbuf_addstr(&term->term_bad, "new");
+ strbuf_addstr(&term->term_good, "old");
+ return write_terms(term->term_bad.buf,
+ term->term_good.buf);
+ }
+ }
+
+ return 0;
+}
+
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
{
enum {
@@ -262,7 +303,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
BISECT_CLEAN_STATE,
BISECT_RESET,
CHECK_EXPECTED_REVS,
- BISECT_WRITE
+ BISECT_WRITE,
+ CHECK_AND_SET_TERMS
} cmdmode = 0;
int no_checkout = 0, res = 0;
struct option options[] = {
@@ -278,6 +320,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
N_("check for expected revs"), CHECK_EXPECTED_REVS),
OPT_CMDMODE(0, "bisect-write", &cmdmode,
N_("write out the bisection state in BISECT_LOG"), BISECT_WRITE),
+ OPT_CMDMODE(0, "check-and-set-terms", &cmdmode,
+ N_("check and set terms in a bisection state"), CHECK_AND_SET_TERMS),
OPT_BOOL(0, "no-checkout", &no_checkout,
N_("update BISECT_HEAD instead of checking out the current commit")),
OPT_END()
@@ -321,6 +365,13 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
strbuf_addstr(&state.term_bad, argv[3]);
res = bisect_write(argv[0], argv[1], &state, nolog);
break;
+ case CHECK_AND_SET_TERMS:
+ if (argc != 3)
+ die(_("--check-and-set-terms requires 3 arguments"));
+ strbuf_addstr(&state.term_good, argv[1]);
+ strbuf_addstr(&state.term_bad, argv[2]);
+ res = check_and_set_terms(argv[0], &state);
+ break;
default:
die("BUG: unknown subcommand '%d'", cmdmode);
}
diff --git a/git-bisect.sh b/git-bisect.sh
index b9896a4..63ae742 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -239,7 +239,8 @@ bisect_skip() {
bisect_state() {
bisect_autostart
state=$1
- check_and_set_terms $state
+ git bisect--helper --check-and-set-terms $state $TERM_GOOD $TERM_BAD
+ get_terms
case "$#,$state" in
0,*)
die "$(gettext "Please call 'bisect_state' with at least one argument.")" ;;
@@ -390,7 +391,8 @@ bisect_replay () {
command="$bisect"
fi
get_terms
- check_and_set_terms "$command"
+ git bisect--helper --check-and-set-terms "$command" "$TERM_GOOD" "$TERM_BAD" || exit
+ get_terms
case "$command" in
start)
cmd="bisect_start $rev"
@@ -480,36 +482,6 @@ get_terms () {
fi
}
-check_and_set_terms () {
- cmd="$1"
- case "$cmd" in
- skip|start|terms) ;;
- *)
- if test -s "$GIT_DIR/BISECT_TERMS" && test "$cmd" != "$TERM_BAD" && test "$cmd" != "$TERM_GOOD"
- then
- die "$(eval_gettext "Invalid command: you're currently in a \$TERM_BAD/\$TERM_GOOD bisect.")"
- fi
- case "$cmd" in
- bad|good)
- if ! test -s "$GIT_DIR/BISECT_TERMS"
- then
- TERM_BAD=bad
- TERM_GOOD=good
- git bisect--helper --write-terms "$TERM_BAD" "$TERM_GOOD" || exit
- fi
- ;;
- new|old)
- if ! test -s "$GIT_DIR/BISECT_TERMS"
- then
- TERM_BAD=new
- TERM_GOOD=old
- git bisect--helper --write-terms "$TERM_BAD" "$TERM_GOOD" || exit
- fi
- ;;
- esac ;;
- esac
-}
-
bisect_voc () {
case "$1" in
bad) echo "bad|new" ;;
--
2.9.0
next reply other threads:[~2016-06-26 20:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-26 20:44 Pranit Bauva [this message]
2016-06-26 20:44 ` [RFC/PATCH 2/3] bisect--helper: `bisect_next_check` shell function in C Pranit Bauva
2016-06-26 20:44 ` [RFC/PATCH 3/3] bisect--helper: `get_terms` & `bisect_terms` " Pranit Bauva
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=20160626204411.19919-1-pranit.bauva@gmail.com \
--to=pranit.bauva@gmail.com \
--cc=Matthie.Moy@grenoble-inp.fr \
--cc=chriscool@tuxfamily.org \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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 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 NNTP newsgroup(s).