On 27/10/17 16:06, Pranit Bauva wrote: > 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 but its > implementation 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. > > Mentored-by: Lars Schneider <larsxschneider@xxxxxxxxx> > Mentored-by: Christian Couder <chriscool@xxxxxxxxxxxxx> > Signed-off-by: Pranit Bauva <pranit.bauva@xxxxxxxxx> > --- > builtin/bisect--helper.c | 41 ++++++++++++++++++++++++++++++++++++++++- > git-bisect.sh | 36 ++++-------------------------------- > 2 files changed, 44 insertions(+), 33 deletions(-) > > diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c > index 6295f53c850a8..65abf8a70c6d9 100644 > --- a/builtin/bisect--helper.c > +++ b/builtin/bisect--helper.c > @@ -20,6 +20,7 @@ static const char * const git_bisect_helper_usage[] = { > N_("git bisect--helper --bisect-clean-state"), > N_("git bisect--helper --bisect-reset [<commit>]"), > N_("git bisect--helper --bisect-write <state> <revision> <good_term> <bad_term> [<nolog>]"), > + N_("git bisect--helper --bisect-check-and-set-terms <command> <good_term> <bad_term>"), > NULL > }; > > @@ -234,6 +235,35 @@ static int bisect_write(const char *state, const char *rev, > return retval; > } > > +static int check_and_set_terms(struct bisect_terms *terms, const char *cmd) > +{ > + int has_term_file = !is_empty_or_missing_file(git_path_bisect_terms()); > + > + if (one_of(cmd, "skip", "start", "terms", NULL)) > + return 0; > + > + if (has_term_file && strcmp(cmd, terms->term_bad) && > + strcmp(cmd, terms->term_good)) > + return error(_("Invalid command: you're currently in a " > + "%s/%s bisect"), terms->term_bad, > + terms->term_good); > + > + if (!has_term_file) { > + if (one_of(cmd, "bad", "good", NULL)) { > + free_terms(terms); > + set_terms(terms, "bad", "good"); > + return write_terms(terms->term_bad, terms->term_good); > + } > + else if (one_of(cmd, "new", "old", NULL)) { cuddle the else: '} else if (one_of(....)) {' OR, simply remove the else. ATB, Ramsay Jones