Skip to content

Commit cb929ed

Browse files
dschogitster
authored andcommitted
bisect: teach the bisect--helper command to show the correct usage strings
In preparation for `bisect--helper` graduating to become the actual `bisect` command, we hereby teach it to print the very same usage strings as the scripted `git-bisect.sh` does. With this patch, the `bisect--helper` command is able to do everything that the `git-bisect.sh` script could, leaving as last step only to retire that script at long last, which we will do in the next commit. Note: Since we cannot use the `parse-options` API to handle the subcommands of `git bisect` anyway, we no longer use it even just to show the usage string anymore, either. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6a723ab commit cb929ed

File tree

1 file changed

+46
-23
lines changed

1 file changed

+46
-23
lines changed

builtin/bisect--helper.c

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "builtin.h"
22
#include "cache.h"
3-
#include "parse-options.h"
43
#include "bisect.h"
54
#include "refs.h"
65
#include "dir.h"
@@ -20,20 +19,46 @@ static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
2019
static GIT_PATH_FUNC(git_path_bisect_first_parent, "BISECT_FIRST_PARENT")
2120
static GIT_PATH_FUNC(git_path_bisect_run, "BISECT_RUN")
2221

23-
static const char * const git_bisect_helper_usage[] = {
24-
N_("git bisect--helper --bisect-reset [<commit>]"),
25-
"git bisect--helper --bisect-terms [--term-good | --term-old | --term-bad | --term-new]",
26-
N_("git bisect--helper --bisect-start [--term-{new,bad}=<term> --term-{old,good}=<term>]"
27-
" [--no-checkout] [--first-parent] [<bad> [<good>...]] [--] [<paths>...]"),
28-
"git bisect--helper --bisect-next",
29-
N_("git bisect--helper [--bisect-state] (bad|new) [<rev>]"),
30-
N_("git bisect--helper [--bisect-state] (good|old) [<rev>...]"),
31-
N_("git bisect--helper --bisect-replay <filename>"),
32-
N_("git bisect--helper --bisect-skip [(<rev>|<range>)...]"),
33-
"git bisect--helper --bisect-visualize",
34-
N_("git bisect--helper --bisect-run <cmd>..."),
35-
NULL
36-
};
22+
static const char *bisect_usage =
23+
N_("git bisect [help|start|bad|good|new|old|terms|skip|next|reset|"
24+
"visualize|view|replay|log|run]");
25+
26+
static const char *bisect_long_usage =
27+
N_("git bisect [help|start|bad|good|new|old|terms|skip|next|reset|"
28+
"visualize|view|replay|log|run]\n"
29+
"\n"
30+
"git bisect help\n"
31+
"\tprint this long help message.\n"
32+
"git bisect start [--term-{new,bad}=<term> "
33+
"--term-{old,good}=<term>]\n"
34+
"\t [--no-checkout] [--first-parent] [<bad> [<good>...]] [--] "
35+
"[<pathspec>...]\n"
36+
"\treset bisect state and start bisection.\n"
37+
"git bisect (bad|new) [<rev>]\n"
38+
"\tmark <rev> a known-bad revision/\n"
39+
"\t a revision after change in a given property.\n"
40+
"git bisect (good|old) [<rev>...]\n"
41+
"\tmark <rev>... known-good revisions/\n"
42+
"\t revisions before change in a given property.\n"
43+
"git bisect terms [--term-good | --term-bad]\n"
44+
"\tshow the terms used for old and new commits "
45+
"(default: bad, good)\n"
46+
"git bisect skip [(<rev>|<range>)...]\n"
47+
"\tmark <rev>... untestable revisions.\n"
48+
"git bisect next\n"
49+
"\tfind next bisection to test and check it out.\n"
50+
"git bisect reset [<commit>]\n"
51+
"\tfinish bisection search and go back to commit.\n"
52+
"git bisect (visualize|view)\n"
53+
"\tshow bisect status in gitk.\n"
54+
"git bisect replay <logfile>\n"
55+
"\treplay bisection log.\n"
56+
"git bisect log\n"
57+
"\tshow bisect log.\n"
58+
"git bisect run <cmd>...\n"
59+
"\tuse <cmd>... to automatically bisect.\n"
60+
"\n"
61+
"Please use \"git help bisect\" to get the full man page.");
3762

3863
struct add_bisect_ref_data {
3964
struct rev_info *revs;
@@ -1277,14 +1302,11 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12771302
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
12781303
{
12791304
int res = 0;
1280-
struct option options[] = {
1281-
OPT_END()
1282-
};
12831305
struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL };
12841306
const char *command = argc > 1 ? argv[1] : "help";
12851307

12861308
if (!strcmp("-h", command) || !strcmp("help", command))
1287-
usage_with_options(git_bisect_helper_usage, options);
1309+
usage(bisect_long_usage);
12881310

12891311
argc -= 2;
12901312
argv += 2;
@@ -1327,12 +1349,13 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
13271349
get_terms(&terms);
13281350
res = bisect_run(&terms, argv, argc);
13291351
} else {
1352+
if (!file_is_not_empty(git_path_bisect_start()) &&
1353+
!one_of(command, "bad", "good", "new", "old", NULL))
1354+
usage(bisect_usage);
13301355
set_terms(&terms, "bad", "good");
13311356
get_terms(&terms);
1332-
if (check_and_set_terms(&terms, command)) {
1333-
char *msg = xstrfmt(_("unknown command: '%s'"), command);
1334-
usage_msg_opt(msg, git_bisect_helper_usage, options);
1335-
}
1357+
if (check_and_set_terms(&terms, command))
1358+
usage(bisect_usage);
13361359
/* shift the `command` back in */
13371360
argc++;
13381361
argv--;

0 commit comments

Comments
 (0)