#include "builtin.h"
#include "cache.h"
#include "parse-options.h"
#include "bisect.h"
#include "refs.h"
#include "dir.h"
#include "strvec.h"
#include "run-command.h"
#include "prompt.h"
#include "quote.h"
#include "revision.h"
static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK")
static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
static GIT_PATH_FUNC(git_path_head_name, "head-name")
static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
static GIT_PATH_FUNC(git_path_bisect_first_parent, "BISECT_FIRST_PARENT")
static GIT_PATH_FUNC(git_path_bisect_run, "BISECT_RUN")
static const char * const git_bisect_helper_usage[] = {
N_("git bisect--helper --bisect-reset [<commit>]"),
N_("git bisect--helper --bisect-terms [--term-good | --term-old | --term-bad | --term-new]"),
N_("git bisect--helper --bisect-start [--term-{new,bad}=<term> --term-{old,good}=<term>]"
" [--no-checkout] [--first-parent] [<bad> [<good>...]] [--] [<paths>...]"),
N_("git bisect--helper --bisect-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>"),
N_("git bisect--helper --bisect-skip [(<rev>|<range>)...]"),
N_("git bisect--helper --bisect-visualize"),
N_("git bisect--helper --bisect-run <cmd>..."),
NULL
};
struct add_bisect_ref_data {
struct rev_info *revs;
unsigned int object_flags;
};
struct bisect_terms {
char *term_good;
char *term_bad;
};
static void free_terms(struct bisect_terms *terms)
{
FREE_AND_NULL(terms->term_good);
FREE_AND_NULL(terms->term_bad);
}
static void set_terms(struct bisect_terms *terms, const char *bad,
const char *good)
{
free((void *)terms->term_good);
terms->term_good = xstrdup(good);
free((void *)terms->term_bad);
terms->term_bad = xstrdup(bad);
}
static const char vocab_bad[] = "bad|new";
static const char vocab_good[] = "good|old";
static int bisect_autostart(struct bisect_terms *terms);
/*
* Check whether the string `term` belongs to the set of strings
* included in the variable arguments.
*/
LAST_ARG_MUST_BE_NULL
static int one_of(const char *term, ...)
{
int res = 0;
va_list matches;
const char *match;
va_start(matches, term);
while (!res && (match = va_arg(matches, const char *)))
res = !strcmp(term, match);
va_end(matches);
return res;
}
/*
* return code BISECT_INTERNAL_SUCCESS_MERGE_BASE
* and BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND are codes
* that indicate special success.
*/
static int is_bisect_success(enum bisect_error res)
{
return !res ||
res == BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND ||
res == BISECT_INTERNAL_SUCCESS_MERGE_BASE;
}
static int write_in_file(const char *path, const char *mode, const char *format, va_list args)
{
FILE *fp = NULL;
int res = 0;
if (strcmp(mode, "w") && strcmp(mode, "a"))
BUG("write-in-file does not support '%s' mode", mode);
fp = fopen(path, mode);
if (!fp)
return error_errno(_("cannot
|