Skip to content

Commit bee6e7a

Browse files
committed
Merge branch 'dd/git-bisect-builtin'
`git bisect` becomes a builtin. * dd/git-bisect-builtin: bisect; remove unused "git-bisect.sh" and ".gitignore" entry Turn `git bisect` into a full built-in bisect--helper: log: allow arbitrary number of arguments bisect--helper: handle states directly bisect--helper: emit usage for "git bisect" bisect test: test exit codes on bad usage bisect--helper: identify as bisect when report error bisect-run: verify_good: account for non-negative exit status bisect run: keep some of the post-v2.30.0 output bisect: fix output regressions in v2.30.0 bisect: refactor bisect_run() to match CodingGuidelines bisect tests: test for v2.30.0 "bisect run" regressions
2 parents c48035d + 049141d commit bee6e7a

File tree

7 files changed

+225
-124
lines changed

7 files changed

+225
-124
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
/git-archimport
2222
/git-archive
2323
/git-bisect
24-
/git-bisect--helper
2524
/git-blame
2625
/git-branch
2726
/git-bugreport

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,6 @@ THIRD_PARTY_SOURCES =
691691
# interactive shell sessions without exporting it.
692692
unexport CDPATH
693693

694-
SCRIPT_SH += git-bisect.sh
695694
SCRIPT_SH += git-difftool--helper.sh
696695
SCRIPT_SH += git-filter-branch.sh
697696
SCRIPT_SH += git-merge-octopus.sh
@@ -1202,7 +1201,7 @@ BUILTIN_OBJS += builtin/am.o
12021201
BUILTIN_OBJS += builtin/annotate.o
12031202
BUILTIN_OBJS += builtin/apply.o
12041203
BUILTIN_OBJS += builtin/archive.o
1205-
BUILTIN_OBJS += builtin/bisect--helper.o
1204+
BUILTIN_OBJS += builtin/bisect.o
12061205
BUILTIN_OBJS += builtin/blame.o
12071206
BUILTIN_OBJS += builtin/branch.o
12081207
BUILTIN_OBJS += builtin/bugreport.o

builtin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ int cmd_am(int argc, const char **argv, const char *prefix);
116116
int cmd_annotate(int argc, const char **argv, const char *prefix);
117117
int cmd_apply(int argc, const char **argv, const char *prefix);
118118
int cmd_archive(int argc, const char **argv, const char *prefix);
119-
int cmd_bisect__helper(int argc, const char **argv, const char *prefix);
119+
int cmd_bisect(int argc, const char **argv, const char *prefix);
120120
int cmd_blame(int argc, const char **argv, const char *prefix);
121121
int cmd_branch(int argc, const char **argv, const char *prefix);
122122
int cmd_bugreport(int argc, const char **argv, const char *prefix);

builtin/bisect--helper.c renamed to builtin/bisect.c

Lines changed: 74 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,40 @@ static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
2020
static GIT_PATH_FUNC(git_path_bisect_first_parent, "BISECT_FIRST_PARENT")
2121
static GIT_PATH_FUNC(git_path_bisect_run, "BISECT_RUN")
2222

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>..."),
23+
#define BUILTIN_GIT_BISECT_START_USAGE \
24+
N_("git bisect start [--term-{new,bad}=<term> --term-{old,good}=<term>]" \
25+
" [--no-checkout] [--first-parent] [<bad> [<good>...]] [--]" \
26+
" [<pathspec>...]")
27+
#define BUILTIN_GIT_BISECT_STATE_USAGE \
28+
N_("git bisect (good|bad) [<rev>...]")
29+
#define BUILTIN_GIT_BISECT_TERMS_USAGE \
30+
"git bisect terms [--term-good | --term-bad]"
31+
#define BUILTIN_GIT_BISECT_SKIP_USAGE \
32+
N_("git bisect skip [(<rev>|<range>)...]")
33+
#define BUILTIN_GIT_BISECT_NEXT_USAGE \
34+
"git bisect next"
35+
#define BUILTIN_GIT_BISECT_RESET_USAGE \
36+
N_("git bisect reset [<commit>]")
37+
#define BUILTIN_GIT_BISECT_VISUALIZE_USAGE \
38+
"git bisect visualize"
39+
#define BUILTIN_GIT_BISECT_REPLAY_USAGE \
40+
N_("git bisect replay <logfile>")
41+
#define BUILTIN_GIT_BISECT_LOG_USAGE \
42+
"git bisect log"
43+
#define BUILTIN_GIT_BISECT_RUN_USAGE \
44+
N_("git bisect run <cmd>...")
45+
46+
static const char * const git_bisect_usage[] = {
47+
BUILTIN_GIT_BISECT_START_USAGE,
48+
BUILTIN_GIT_BISECT_STATE_USAGE,
49+
BUILTIN_GIT_BISECT_TERMS_USAGE,
50+
BUILTIN_GIT_BISECT_SKIP_USAGE,
51+
BUILTIN_GIT_BISECT_NEXT_USAGE,
52+
BUILTIN_GIT_BISECT_RESET_USAGE,
53+
BUILTIN_GIT_BISECT_VISUALIZE_USAGE,
54+
BUILTIN_GIT_BISECT_REPLAY_USAGE,
55+
BUILTIN_GIT_BISECT_LOG_USAGE,
56+
BUILTIN_GIT_BISECT_RUN_USAGE,
3557
NULL
3658
};
3759

@@ -1191,13 +1213,13 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
11911213
if (bisect_next_check(terms, NULL))
11921214
return BISECT_FAILED;
11931215

1194-
if (argc)
1195-
sq_quote_argv(&command, argv);
1196-
else {
1216+
if (!argc) {
11971217
error(_("bisect run failed: no command provided."));
11981218
return BISECT_FAILED;
11991219
}
12001220

1221+
sq_quote_argv(&command, argv);
1222+
strbuf_ltrim(&command);
12011223
while (1) {
12021224
res = do_bisect_run(command.buf);
12031225

@@ -1211,8 +1233,8 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12111233
if (is_first_run && (res == 126 || res == 127)) {
12121234
int rc = verify_good(terms, command.buf);
12131235
is_first_run = 0;
1214-
if (rc < 0) {
1215-
error(_("unable to verify '%s' on good"
1236+
if (rc < 0 || 128 <= rc) {
1237+
error(_("unable to verify %s on good"
12161238
" revision"), command.buf);
12171239
res = BISECT_FAILED;
12181240
break;
@@ -1227,7 +1249,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12271249

12281250
if (res < 0 || 128 <= res) {
12291251
error(_("bisect run failed: exit code %d from"
1230-
" '%s' is < 0 or >= 128"), res, command.buf);
1252+
" %s is < 0 or >= 128"), res, command.buf);
12311253
break;
12321254
}
12331255

@@ -1261,14 +1283,14 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12611283
if (res == BISECT_ONLY_SKIPPED_LEFT)
12621284
error(_("bisect run cannot continue any more"));
12631285
else if (res == BISECT_INTERNAL_SUCCESS_MERGE_BASE) {
1264-
printf(_("bisect run success"));
1286+
puts(_("bisect run success"));
12651287
res = BISECT_OK;
12661288
} else if (res == BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND) {
1267-
printf(_("bisect found first bad commit"));
1289+
puts(_("bisect found first bad commit"));
12681290
res = BISECT_OK;
12691291
} else if (res) {
1270-
error(_("bisect run failed: 'git bisect--helper --bisect-state"
1271-
" %s' exited with error code %d"), new_state, res);
1292+
error(_("bisect run failed: 'bisect-state %s'"
1293+
" exited with error code %d"), new_state, res);
12721294
} else {
12731295
continue;
12741296
}
@@ -1282,7 +1304,8 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12821304
static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNUSED)
12831305
{
12841306
if (argc > 1)
1285-
return error(_("--bisect-reset requires either no argument or a commit"));
1307+
return error(_("'%s' requires either no argument or a commit"),
1308+
"git bisect reset");
12861309
return bisect_reset(argc ? argv[0] : NULL);
12871310
}
12881311

@@ -1292,7 +1315,8 @@ static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNU
12921315
struct bisect_terms terms = { 0 };
12931316

12941317
if (argc > 1)
1295-
return error(_("--bisect-terms requires 0 or 1 argument"));
1318+
return error(_("'%s' requires 0 or 1 argument"),
1319+
"git bisect terms");
12961320
res = bisect_terms(&terms, argc == 1 ? argv[0] : NULL);
12971321
free_terms(&terms);
12981322
return res;
@@ -1315,29 +1339,16 @@ static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *pref
13151339
struct bisect_terms terms = { 0 };
13161340

13171341
if (argc)
1318-
return error(_("--bisect-next requires 0 arguments"));
1342+
return error(_("'%s' requires 0 arguments"),
1343+
"git bisect next");
13191344
get_terms(&terms);
13201345
res = bisect_next(&terms, prefix);
13211346
free_terms(&terms);
13221347
return res;
13231348
}
13241349

1325-
static int cmd_bisect__state(int argc, const char **argv, const char *prefix UNUSED)
1350+
static int cmd_bisect__log(int argc UNUSED, const char **argv UNUSED, const char *prefix UNUSED)
13261351
{
1327-
int res;
1328-
struct bisect_terms terms = { 0 };
1329-
1330-
set_terms(&terms, "bad", "good");
1331-
get_terms(&terms);
1332-
res = bisect_state(&terms, argv, argc);
1333-
free_terms(&terms);
1334-
return res;
1335-
}
1336-
1337-
static int cmd_bisect__log(int argc, const char **argv UNUSED, const char *prefix UNUSED)
1338-
{
1339-
if (argc)
1340-
return error(_("--bisect-log requires 0 arguments"));
13411352
return bisect_log();
13421353
}
13431354

@@ -1383,14 +1394,14 @@ static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSE
13831394
struct bisect_terms terms = { 0 };
13841395

13851396
if (!argc)
1386-
return error(_("bisect run failed: no command provided."));
1397+
return error(_("'%s' failed: no command provided."), "git bisect run");
13871398
get_terms(&terms);
13881399
res = bisect_run(&terms, argv, argc);
13891400
free_terms(&terms);
13901401
return res;
13911402
}
13921403

1393-
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1404+
int cmd_bisect(int argc, const char **argv, const char *prefix)
13941405
{
13951406
int res = 0;
13961407
parse_opt_subcommand_fn *fn = NULL;
@@ -1399,7 +1410,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
13991410
OPT_SUBCOMMAND("terms", &fn, cmd_bisect__terms),
14001411
OPT_SUBCOMMAND("start", &fn, cmd_bisect__start),
14011412
OPT_SUBCOMMAND("next", &fn, cmd_bisect__next),
1402-
OPT_SUBCOMMAND("state", &fn, cmd_bisect__state),
14031413
OPT_SUBCOMMAND("log", &fn, cmd_bisect__log),
14041414
OPT_SUBCOMMAND("replay", &fn, cmd_bisect__replay),
14051415
OPT_SUBCOMMAND("skip", &fn, cmd_bisect__skip),
@@ -1408,15 +1418,27 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
14081418
OPT_SUBCOMMAND("run", &fn, cmd_bisect__run),
14091419
OPT_END()
14101420
};
1411-
argc = parse_options(argc, argv, prefix, options,
1412-
git_bisect_helper_usage, 0);
1413-
1414-
if (!fn)
1415-
usage_with_options(git_bisect_helper_usage, options);
1416-
argc--;
1417-
argv++;
1418-
1419-
res = fn(argc, argv, prefix);
1421+
argc = parse_options(argc, argv, prefix, options, git_bisect_usage,
1422+
PARSE_OPT_SUBCOMMAND_OPTIONAL);
1423+
1424+
if (!fn) {
1425+
struct bisect_terms terms = { 0 };
1426+
1427+
if (!argc)
1428+
usage_msg_opt(_("need a command"), git_bisect_usage, options);
1429+
1430+
set_terms(&terms, "bad", "good");
1431+
get_terms(&terms);
1432+
if (check_and_set_terms(&terms, argv[0]))
1433+
usage_msg_optf(_("unknown command: '%s'"), git_bisect_usage,
1434+
options, argv[0]);
1435+
res = bisect_state(&terms, argv, argc);
1436+
free_terms(&terms);
1437+
} else {
1438+
argc--;
1439+
argv++;
1440+
res = fn(argc, argv, prefix);
1441+
}
14201442

14211443
/*
14221444
* Handle early success

git-bisect.sh

Lines changed: 0 additions & 67 deletions
This file was deleted.

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ static struct cmd_struct commands[] = {
492492
{ "annotate", cmd_annotate, RUN_SETUP },
493493
{ "apply", cmd_apply, RUN_SETUP_GENTLY },
494494
{ "archive", cmd_archive, RUN_SETUP_GENTLY },
495-
{ "bisect--helper", cmd_bisect__helper, RUN_SETUP },
495+
{ "bisect", cmd_bisect, RUN_SETUP },
496496
{ "blame", cmd_blame, RUN_SETUP },
497497
{ "branch", cmd_branch, RUN_SETUP | DELAY_PAGER_CONFIG },
498498
{ "bugreport", cmd_bugreport, RUN_SETUP_GENTLY },

0 commit comments

Comments
 (0)