4
#include "bisect.h"
5
#include "refs.h"
6
7
+static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
8
+
9
static const char * const git_bisect_helper_usage[] = {
10
N_("git bisect--helper --next-all [--no-checkout]"),
9
- N_("git bisect--helper --check-term-format <term> <orig_term>"),
11
+ N_("git bisect--helper --write-terms <bad_term> <good_term>"),
12
NULL
13
};
14
59
return 0;
60
}
61
62
+static int write_terms(const char *bad, const char *good)
63
+{
64
+ FILE *fp = NULL;
65
+ int res;
66
+
67
+ if (!strcmp(bad, good))
68
+ return error(_("please use two different terms"));
69
+
70
+ if (check_term_format(bad, "bad") || check_term_format(good, "good"))
71
+ return -1;
72
+
73
+ fp = fopen(git_path_bisect_terms(), "w");
74
+ if (!fp)
75
+ return error_errno(_("could not open the file BISECT_TERMS"));
76
+
77
+ res = fprintf(fp, "%s\n%s\n", bad, good);
78
+ res |= fclose(fp);
79
+ return (res < 0) ? -1 : 0;
80
+}
81
+
82
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
83
{
84
enum {
85
NEXT_ALL = 1,
64
- CHECK_TERM_FMT
86
+ WRITE_TERMS
87
} cmdmode = 0;
88
int no_checkout = 0;
89
struct option options[] = {
90
OPT_CMDMODE(0, "next-all", &cmdmode,
91
N_("perform 'git bisect next'"), NEXT_ALL),
70
- OPT_CMDMODE(0, "check-term-format", &cmdmode,
71
- N_("check format of the term"), CHECK_TERM_FMT),
92
+ OPT_CMDMODE(0, "write-terms", &cmdmode,
93
+ N_("write the terms to .git/BISECT_TERMS"), WRITE_TERMS),
94
OPT_BOOL(0, "no-checkout", &no_checkout,
95
N_("update BISECT_HEAD instead of checking out the current commit")),
96
OPT_END()
105
switch (cmdmode) {
106
case NEXT_ALL:
107
return bisect_next_all(prefix, no_checkout);
86
- case CHECK_TERM_FMT:
108
+ case WRITE_TERMS:
109
if (argc != 2)
88
- return error(_("--check-term-format requires two arguments"));
89
- return check_term_format(argv[0], argv[1]);
110
+ return error(_("--write-terms requires two arguments"));
111
+ return write_terms(argv[0], argv[1]);
112
default:
113
return error("BUG: unknown subcommand '%d'", cmdmode);
114
}