@@ -15,23 +15,38 @@ static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
1515static GIT_PATH_FUNC (git_path_bisect_ancestors_ok , "BISECT_ANCESTORS_OK ")
1616static GIT_PATH_FUNC (git_path_bisect_start , "BISECT_START ")
1717static GIT_PATH_FUNC (git_path_bisect_log , "BISECT_LOG ")
18- static GIT_PATH_FUNC (git_path_head_name , "head - name ")
1918static GIT_PATH_FUNC (git_path_bisect_names , "BISECT_NAMES ")
2019static GIT_PATH_FUNC (git_path_bisect_first_parent , "BISECT_FIRST_PARENT ")
2120static 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 /*
0 commit comments