Skip to content

Commit e199128

Browse files
committed
Merge branch 'js/bisect-in-c' into jch
Final bits of "git bisect.sh" have been rewritten in C. * js/bisect-in-c: bisect: no longer try to clean up left-over `.git/head-name` files bisect: remove Cogito-related code bisect: turn `git bisect` into a full built-in bisect: move even the option parsing to `bisect--helper` bisect--helper: return only correct exit codes in `cmd_*()` bisect--helper: move the `BISECT_STATE` case to the end bisect--helper: make `--bisect-state` optional bisect--helper: align the sub-command order with git-bisect.sh bisect--helper: using `--bisect-state` without an argument is a bug bisect--helper: really retire `--bisect-autostart` bisect--helper: really retire --bisect-next-check bisect--helper: retire the --no-log option bisect: avoid double-quoting when printing the failed command bisect run: fix the error message
2 parents c6c2314 + ad2f799 commit e199128

File tree

7 files changed

+88
-201
lines changed

7 files changed

+88
-201
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,6 @@ THIRD_PARTY_SOURCES =
611611
# interactive shell sessions without exporting it.
612612
unexport CDPATH
613613

614-
SCRIPT_SH += git-bisect.sh
615614
SCRIPT_SH += git-difftool--helper.sh
616615
SCRIPT_SH += git-filter-branch.sh
617616
SCRIPT_SH += git-merge-octopus.sh
@@ -1107,7 +1106,7 @@ BUILTIN_OBJS += builtin/am.o
11071106
BUILTIN_OBJS += builtin/annotate.o
11081107
BUILTIN_OBJS += builtin/apply.o
11091108
BUILTIN_OBJS += builtin/archive.o
1110-
BUILTIN_OBJS += builtin/bisect--helper.o
1109+
BUILTIN_OBJS += builtin/bisect.o
11111110
BUILTIN_OBJS += builtin/blame.o
11121111
BUILTIN_OBJS += builtin/branch.o
11131112
BUILTIN_OBJS += builtin/bugreport.o

bisect.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
474474
static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
475475
static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
476476
static GIT_PATH_FUNC(git_path_bisect_first_parent, "BISECT_FIRST_PARENT")
477-
static GIT_PATH_FUNC(git_path_head_name, "head-name")
478477

479478
static void read_bisect_paths(struct strvec *array)
480479
{
@@ -1173,8 +1172,6 @@ int bisect_clean_state(void)
11731172
unlink_or_warn(git_path_bisect_run());
11741173
unlink_or_warn(git_path_bisect_terms());
11751174
unlink_or_warn(git_path_bisect_first_parent());
1176-
/* Cleanup head-name if it got left by an old version of git-bisect */
1177-
unlink_or_warn(git_path_head_name());
11781175
/*
11791176
* Cleanup BISECT_START last to support the --no-checkout option
11801177
* introduced in the commit 4796e823a.

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);
Lines changed: 75 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,38 @@ static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
1515
static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK")
1616
static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
1717
static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
18-
static GIT_PATH_FUNC(git_path_head_name, "head-name")
1918
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>..."),
22+
static const char * const builtin_bisect_usage[] = {
23+
N_("git bisect help\n"
24+
"\tprint this long help message."),
25+
N_("git bisect start [--term-{new,bad}=<term> --term-{old,good}=<term>]\n"
26+
"\t\t [--no-checkout] [--first-parent] [<bad> [<good>...]] [--] [<pathspec>...]\n"
27+
"\treset bisect state and start bisection."),
28+
N_("git bisect (bad|new) [<rev>]\n"
29+
"\tmark <rev> a known-bad revision/\n"
30+
"\t\ta revision after change in a given property."),
31+
N_("git bisect (good|old) [<rev>...]\n"
32+
"\tmark <rev>... known-good revisions/\n"
33+
"\t\trevisions before change in a given property."),
34+
N_("git bisect terms [--term-good | --term-bad]\n"
35+
"\tshow the terms used for old and new commits (default: bad, good)"),
36+
N_("git bisect skip [(<rev>|<range>)...]\n"
37+
"\tmark <rev>... untestable revisions."),
38+
N_("git bisect next\n"
39+
"\tfind next bisection to test and check it out."),
40+
N_("git bisect reset [<commit>]\n"
41+
"\tfinish bisection search and go back to commit."),
42+
N_("git bisect (visualize|view)\n"
43+
"\tshow bisect status in gitk."),
44+
N_("git bisect replay <logfile>\n"
45+
"\treplay bisection log."),
46+
N_("git bisect log\n"
47+
"\tshow bisect log."),
48+
N_("git bisect run <cmd>...\n"
49+
"\tuse <cmd>... to automatically bisect."),
3550
NULL
3651
};
3752

@@ -740,13 +755,6 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, const char **a
740755
strbuf_addstr(&start_head, oid_to_hex(&head_oid));
741756
} else if (!get_oid(head, &head_oid) &&
742757
skip_prefix(head, "refs/heads/", &head)) {
743-
/*
744-
* This error message should only be triggered by
745-
* cogito usage, and cogito users should understand
746-
* it relates to cg-seek.
747-
*/
748-
if (!is_empty_or_missing_file(git_path_head_name()))
749-
return error(_("won't bisect on cg-seek'ed tree"));
750758
strbuf_addstr(&start_head, head);
751759
} else {
752760
return error(_("bad HEAD - strange symbolic ref"));
@@ -856,7 +864,7 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, const char **a
856864
struct oid_array revs = OID_ARRAY_INIT;
857865

858866
if (!argc)
859-
return error(_("Please call `--bisect-state` with at least one argument"));
867+
BUG("bisect_state() called without argument");
860868

861869
if (bisect_autostart(terms))
862870
return BISECT_FAILED;
@@ -1179,7 +1187,8 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
11791187
if (res < 0 || 128 <= res) {
11801188
error(_("bisect run failed: exit code %d from"
11811189
" '%s' is < 0 or >= 128"), res, command.buf);
1182-
break;
1190+
strbuf_release(&command);
1191+
return res;
11831192
}
11841193

11851194
if (res == 125)
@@ -1218,7 +1227,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12181227
printf(_("bisect found first bad commit"));
12191228
res = BISECT_OK;
12201229
} else if (res) {
1221-
error(_("bisect run failed: 'git bisect--helper --bisect-state"
1230+
error(_("bisect run failed: 'git bisect"
12221231
" %s' exited with error code %d"), new_state, res);
12231232
} else {
12241233
continue;
@@ -1231,114 +1240,71 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12311240
return res;
12321241
}
12331242

1234-
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1243+
int cmd_bisect(int argc, const char **argv, const char *prefix)
12351244
{
1236-
enum {
1237-
BISECT_RESET = 1,
1238-
BISECT_NEXT_CHECK,
1239-
BISECT_TERMS,
1240-
BISECT_START,
1241-
BISECT_AUTOSTART,
1242-
BISECT_NEXT,
1243-
BISECT_STATE,
1244-
BISECT_LOG,
1245-
BISECT_REPLAY,
1246-
BISECT_SKIP,
1247-
BISECT_VISUALIZE,
1248-
BISECT_RUN,
1249-
} cmdmode = 0;
1250-
int res = 0, nolog = 0;
1245+
int res = 0;
12511246
struct option options[] = {
1252-
OPT_CMDMODE(0, "bisect-reset", &cmdmode,
1253-
N_("reset the bisection state"), BISECT_RESET),
1254-
OPT_CMDMODE(0, "bisect-next-check", &cmdmode,
1255-
N_("check whether bad or good terms exist"), BISECT_NEXT_CHECK),
1256-
OPT_CMDMODE(0, "bisect-terms", &cmdmode,
1257-
N_("print out the bisect terms"), BISECT_TERMS),
1258-
OPT_CMDMODE(0, "bisect-start", &cmdmode,
1259-
N_("start the bisect session"), BISECT_START),
1260-
OPT_CMDMODE(0, "bisect-next", &cmdmode,
1261-
N_("find the next bisection commit"), BISECT_NEXT),
1262-
OPT_CMDMODE(0, "bisect-state", &cmdmode,
1263-
N_("mark the state of ref (or refs)"), BISECT_STATE),
1264-
OPT_CMDMODE(0, "bisect-log", &cmdmode,
1265-
N_("list the bisection steps so far"), BISECT_LOG),
1266-
OPT_CMDMODE(0, "bisect-replay", &cmdmode,
1267-
N_("replay the bisection process from the given file"), BISECT_REPLAY),
1268-
OPT_CMDMODE(0, "bisect-skip", &cmdmode,
1269-
N_("skip some commits for checkout"), BISECT_SKIP),
1270-
OPT_CMDMODE(0, "bisect-visualize", &cmdmode,
1271-
N_("visualize the bisection"), BISECT_VISUALIZE),
1272-
OPT_CMDMODE(0, "bisect-run", &cmdmode,
1273-
N_("use <cmd>... to automatically bisect"), BISECT_RUN),
1274-
OPT_BOOL(0, "no-log", &nolog,
1275-
N_("no log for BISECT_WRITE")),
12761247
OPT_END()
12771248
};
12781249
struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL };
1250+
const char *command = argc > 1 ? argv[1] : "help";
12791251

1280-
argc = parse_options(argc, argv, prefix, options,
1281-
git_bisect_helper_usage,
1282-
PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_UNKNOWN);
1252+
if (!strcmp("-h", command) || !strcmp("help", command))
1253+
usage_with_options(builtin_bisect_usage, options);
12831254

1284-
if (!cmdmode)
1285-
usage_with_options(git_bisect_helper_usage, options);
1255+
argc -= 2;
1256+
argv += 2;
12861257

1287-
switch (cmdmode) {
1288-
case BISECT_RESET:
1289-
if (argc > 1)
1290-
return error(_("--bisect-reset requires either no argument or a commit"));
1291-
res = bisect_reset(argc ? argv[0] : NULL);
1292-
break;
1293-
case BISECT_TERMS:
1258+
if (!strcmp("start", command)) {
1259+
set_terms(&terms, "bad", "good");
1260+
res = bisect_start(&terms, argv, argc);
1261+
} else if (!strcmp("terms", command)) {
12941262
if (argc > 1)
1295-
return error(_("--bisect-terms requires 0 or 1 argument"));
1263+
die(_("'terms' requires 0 or 1 argument"));
12961264
res = bisect_terms(&terms, argc == 1 ? argv[0] : NULL);
1297-
break;
1298-
case BISECT_START:
1265+
} else if (!strcmp("skip", command)) {
12991266
set_terms(&terms, "bad", "good");
1300-
res = bisect_start(&terms, argv, argc);
1301-
break;
1302-
case BISECT_NEXT:
1267+
get_terms(&terms);
1268+
res = bisect_skip(&terms, argv, argc);
1269+
} else if (!strcmp("next", command)) {
13031270
if (argc)
1304-
return error(_("--bisect-next requires 0 arguments"));
1271+
die(_("'next' requires 0 arguments"));
13051272
get_terms(&terms);
13061273
res = bisect_next(&terms, prefix);
1307-
break;
1308-
case BISECT_STATE:
1309-
set_terms(&terms, "bad", "good");
1274+
} else if (!strcmp("reset", command)) {
1275+
if (argc > 1)
1276+
die(_("'reset' requires either no argument or a commit"));
1277+
res = bisect_reset(argc ? argv[0] : NULL);
1278+
} else if (one_of(command, "visualize", "view", NULL)) {
13101279
get_terms(&terms);
1311-
res = bisect_state(&terms, argv, argc);
1312-
break;
1313-
case BISECT_LOG:
1314-
if (argc)
1315-
return error(_("--bisect-log requires 0 arguments"));
1316-
res = bisect_log();
1317-
break;
1318-
case BISECT_REPLAY:
1280+
res = bisect_visualize(&terms, argv, argc);
1281+
} else if (!strcmp("replay", command)) {
13191282
if (argc != 1)
1320-
return error(_("no logfile given"));
1283+
die(_("no logfile given"));
13211284
set_terms(&terms, "bad", "good");
13221285
res = bisect_replay(&terms, argv[0]);
1323-
break;
1324-
case BISECT_SKIP:
1325-
set_terms(&terms, "bad", "good");
1326-
get_terms(&terms);
1327-
res = bisect_skip(&terms, argv, argc);
1328-
break;
1329-
case BISECT_VISUALIZE:
1330-
get_terms(&terms);
1331-
res = bisect_visualize(&terms, argv, argc);
1332-
break;
1333-
case BISECT_RUN:
1286+
} else if (!strcmp("log", command)) {
1287+
if (argc)
1288+
die(_("'log' requires 0 arguments"));
1289+
res = bisect_log();
1290+
} else if (!strcmp("run", command)) {
13341291
if (!argc)
1335-
return error(_("bisect run failed: no command provided."));
1292+
die(_("bisect run failed: no command provided."));
13361293
get_terms(&terms);
13371294
res = bisect_run(&terms, argv, argc);
1338-
break;
1339-
default:
1340-
BUG("unknown subcommand %d", cmdmode);
1295+
} else {
1296+
set_terms(&terms, "bad", "good");
1297+
get_terms(&terms);
1298+
if (check_and_set_terms(&terms, command)) {
1299+
char *msg = xstrfmt(_("unknown command: '%s'"), command);
1300+
usage_msg_opt(msg, builtin_bisect_usage, options);
1301+
}
1302+
/* shift the `command` back in */
1303+
argc++;
1304+
argv--;
1305+
res = bisect_state(&terms, argv, argc);
13411306
}
1307+
13421308
free_terms(&terms);
13431309

13441310
/*

git-bisect.sh

Lines changed: 0 additions & 84 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 | NO_PARSEOPT },
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)