Skip to content

Commit af7ff8e

Browse files
committed
Merge branch 'js/bisect-in-c' into seen
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 Turn `git bisect` into a full built-in bisect: move even the command-line parsing to `bisect--helper` bisect: teach the `bisect--helper` command to show the correct usage strings 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 bisect: verify that a bogus option won't try to start a bisection
2 parents 964cafa + bb4b71f commit af7ff8e

File tree

7 files changed

+110
-207
lines changed

7 files changed

+110
-207
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,6 @@ THIRD_PARTY_SOURCES =
627627
# interactive shell sessions without exporting it.
628628
unexport CDPATH
629629

630-
SCRIPT_SH += git-bisect.sh
631630
SCRIPT_SH += git-difftool--helper.sh
632631
SCRIPT_SH += git-filter-branch.sh
633632
SCRIPT_SH += git-merge-octopus.sh
@@ -1127,7 +1126,7 @@ BUILTIN_OBJS += builtin/am.o
11271126
BUILTIN_OBJS += builtin/annotate.o
11281127
BUILTIN_OBJS += builtin/apply.o
11291128
BUILTIN_OBJS += builtin/archive.o
1130-
BUILTIN_OBJS += builtin/bisect--helper.o
1129+
BUILTIN_OBJS += builtin/bisect.o
11311130
BUILTIN_OBJS += builtin/blame.o
11321131
BUILTIN_OBJS += builtin/branch.o
11331132
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
{
@@ -1181,8 +1180,6 @@ int bisect_clean_state(void)
11811180
unlink_or_warn(git_path_bisect_run());
11821181
unlink_or_warn(git_path_bisect_terms());
11831182
unlink_or_warn(git_path_bisect_first_parent());
1184-
/* Cleanup head-name if it got left by an old version of git-bisect */
1185-
unlink_or_warn(git_path_head_name());
11861183
/*
11871184
* Cleanup BISECT_START last to support the --no-checkout option
11881185
* 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);

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

Lines changed: 87 additions & 115 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"
@@ -15,25 +14,50 @@ static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
1514
static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK")
1615
static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
1716
static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
18-
static GIT_PATH_FUNC(git_path_head_name, "head-name")
1917
static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
2018
static GIT_PATH_FUNC(git_path_bisect_first_parent, "BISECT_FIRST_PARENT")
2119
static GIT_PATH_FUNC(git_path_bisect_run, "BISECT_RUN")
2220

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

3862
struct add_bisect_ref_data {
3963
struct rev_info *revs;
@@ -784,13 +808,6 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, const char **a
784808
strbuf_addstr(&start_head, oid_to_hex(&head_oid));
785809
} else if (!get_oid(head, &head_oid) &&
786810
skip_prefix(head, "refs/heads/", &head)) {
787-
/*
788-
* This error message should only be triggered by
789-
* cogito usage, and cogito users should understand
790-
* it relates to cg-seek.
791-
*/
792-
if (!is_empty_or_missing_file(git_path_head_name()))
793-
return error(_("won't bisect on cg-seek'ed tree"));
794811
strbuf_addstr(&start_head, head);
795812
} else {
796813
return error(_("bad HEAD - strange symbolic ref"));
@@ -900,7 +917,7 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, const char **a
900917
struct oid_array revs = OID_ARRAY_INIT;
901918

902919
if (!argc)
903-
return error(_("Please call `--bisect-state` with at least one argument"));
920+
BUG("bisect_state() called without argument");
904921

905922
if (bisect_autostart(terms))
906923
return BISECT_FAILED;
@@ -1223,7 +1240,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12231240

12241241
if (res < 0 || 128 <= res) {
12251242
error(_("bisect run failed: exit code %d from"
1226-
" '%s' is < 0 or >= 128"), res, command.buf);
1243+
" %s is < 0 or >= 128"), res, command.buf);
12271244
break;
12281245
}
12291246

@@ -1263,7 +1280,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12631280
printf(_("bisect found first bad commit"));
12641281
res = BISECT_OK;
12651282
} else if (res) {
1266-
error(_("bisect run failed: 'git bisect--helper --bisect-state"
1283+
error(_("bisect run failed: 'git bisect"
12671284
" %s' exited with error code %d"), new_state, res);
12681285
} else {
12691286
continue;
@@ -1276,114 +1293,69 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12761293
return res;
12771294
}
12781295

1279-
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1296+
int cmd_bisect(int argc, const char **argv, const char *prefix)
12801297
{
1281-
enum {
1282-
BISECT_RESET = 1,
1283-
BISECT_NEXT_CHECK,
1284-
BISECT_TERMS,
1285-
BISECT_START,
1286-
BISECT_AUTOSTART,
1287-
BISECT_NEXT,
1288-
BISECT_STATE,
1289-
BISECT_LOG,
1290-
BISECT_REPLAY,
1291-
BISECT_SKIP,
1292-
BISECT_VISUALIZE,
1293-
BISECT_RUN,
1294-
} cmdmode = 0;
1295-
int res = 0, nolog = 0;
1296-
struct option options[] = {
1297-
OPT_CMDMODE(0, "bisect-reset", &cmdmode,
1298-
N_("reset the bisection state"), BISECT_RESET),
1299-
OPT_CMDMODE(0, "bisect-next-check", &cmdmode,
1300-
N_("check whether bad or good terms exist"), BISECT_NEXT_CHECK),
1301-
OPT_CMDMODE(0, "bisect-terms", &cmdmode,
1302-
N_("print out the bisect terms"), BISECT_TERMS),
1303-
OPT_CMDMODE(0, "bisect-start", &cmdmode,
1304-
N_("start the bisect session"), BISECT_START),
1305-
OPT_CMDMODE(0, "bisect-next", &cmdmode,
1306-
N_("find the next bisection commit"), BISECT_NEXT),
1307-
OPT_CMDMODE(0, "bisect-state", &cmdmode,
1308-
N_("mark the state of ref (or refs)"), BISECT_STATE),
1309-
OPT_CMDMODE(0, "bisect-log", &cmdmode,
1310-
N_("list the bisection steps so far"), BISECT_LOG),
1311-
OPT_CMDMODE(0, "bisect-replay", &cmdmode,
1312-
N_("replay the bisection process from the given file"), BISECT_REPLAY),
1313-
OPT_CMDMODE(0, "bisect-skip", &cmdmode,
1314-
N_("skip some commits for checkout"), BISECT_SKIP),
1315-
OPT_CMDMODE(0, "bisect-visualize", &cmdmode,
1316-
N_("visualize the bisection"), BISECT_VISUALIZE),
1317-
OPT_CMDMODE(0, "bisect-run", &cmdmode,
1318-
N_("use <cmd>... to automatically bisect"), BISECT_RUN),
1319-
OPT_BOOL(0, "no-log", &nolog,
1320-
N_("no log for BISECT_WRITE")),
1321-
OPT_END()
1322-
};
1298+
int res = 0;
13231299
struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL };
1300+
const char *command = argc > 1 ? argv[1] : "help";
13241301

1325-
argc = parse_options(argc, argv, prefix, options,
1326-
git_bisect_helper_usage,
1327-
PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_UNKNOWN);
1302+
if (!strcmp("-h", command) || !strcmp("help", command))
1303+
usage(bisect_long_usage);
13281304

1329-
if (!cmdmode)
1330-
usage_with_options(git_bisect_helper_usage, options);
1305+
argc -= 2;
1306+
argv += 2;
13311307

1332-
switch (cmdmode) {
1333-
case BISECT_RESET:
1334-
if (argc > 1)
1335-
return error(_("--bisect-reset requires either no argument or a commit"));
1336-
res = bisect_reset(argc ? argv[0] : NULL);
1337-
break;
1338-
case BISECT_TERMS:
1308+
if (!strcmp("start", command)) {
1309+
set_terms(&terms, "bad", "good");
1310+
res = bisect_start(&terms, argv, argc);
1311+
} else if (!strcmp("terms", command)) {
13391312
if (argc > 1)
1340-
return error(_("--bisect-terms requires 0 or 1 argument"));
1313+
die(_("'terms' requires 0 or 1 argument"));
13411314
res = bisect_terms(&terms, argc == 1 ? argv[0] : NULL);
1342-
break;
1343-
case BISECT_START:
1315+
} else if (!strcmp("skip", command)) {
13441316
set_terms(&terms, "bad", "good");
1345-
res = bisect_start(&terms, argv, argc);
1346-
break;
1347-
case BISECT_NEXT:
1317+
get_terms(&terms);
1318+
res = bisect_skip(&terms, argv, argc);
1319+
} else if (!strcmp("next", command)) {
13481320
if (argc)
1349-
return error(_("--bisect-next requires 0 arguments"));
1321+
die(_("'next' requires 0 arguments"));
13501322
get_terms(&terms);
13511323
res = bisect_next(&terms, prefix);
1352-
break;
1353-
case BISECT_STATE:
1354-
set_terms(&terms, "bad", "good");
1324+
} else if (!strcmp("reset", command)) {
1325+
if (argc > 1)
1326+
die(_("'reset' requires either no argument or a commit"));
1327+
res = bisect_reset(argc ? argv[0] : NULL);
1328+
} else if (one_of(command, "visualize", "view", NULL)) {
13551329
get_terms(&terms);
1356-
res = bisect_state(&terms, argv, argc);
1357-
break;
1358-
case BISECT_LOG:
1359-
if (argc)
1360-
return error(_("--bisect-log requires 0 arguments"));
1361-
res = bisect_log();
1362-
break;
1363-
case BISECT_REPLAY:
1330+
res = bisect_visualize(&terms, argv, argc);
1331+
} else if (!strcmp("replay", command)) {
13641332
if (argc != 1)
1365-
return error(_("no logfile given"));
1333+
die(_("no logfile given"));
13661334
set_terms(&terms, "bad", "good");
13671335
res = bisect_replay(&terms, argv[0]);
1368-
break;
1369-
case BISECT_SKIP:
1370-
set_terms(&terms, "bad", "good");
1371-
get_terms(&terms);
1372-
res = bisect_skip(&terms, argv, argc);
1373-
break;
1374-
case BISECT_VISUALIZE:
1375-
get_terms(&terms);
1376-
res = bisect_visualize(&terms, argv, argc);
1377-
break;
1378-
case BISECT_RUN:
1336+
} else if (!strcmp("log", command)) {
1337+
if (argc)
1338+
die(_("'log' requires 0 arguments"));
1339+
res = bisect_log();
1340+
} else if (!strcmp("run", command)) {
13791341
if (!argc)
1380-
return error(_("bisect run failed: no command provided."));
1342+
die(_("bisect run failed: no command provided."));
13811343
get_terms(&terms);
13821344
res = bisect_run(&terms, argv, argc);
1383-
break;
1384-
default:
1385-
BUG("unknown subcommand %d", cmdmode);
1345+
} else {
1346+
if (!file_is_not_empty(git_path_bisect_start()) &&
1347+
!one_of(command, "bad", "good", "new", "old", NULL))
1348+
usage(bisect_usage);
1349+
set_terms(&terms, "bad", "good");
1350+
get_terms(&terms);
1351+
if (check_and_set_terms(&terms, command))
1352+
usage(bisect_usage);
1353+
/* shift the `command` back in */
1354+
argc++;
1355+
argv--;
1356+
res = bisect_state(&terms, argv, argc);
13861357
}
1358+
13871359
free_terms(&terms);
13881360

13891361
/*

0 commit comments

Comments
 (0)