diff mbox series

[v3,12/15] bisect: teach the `bisect--helper` command to show the correct usage strings

Message ID ac472aefb6af0670cc9fa498e57145aec9ae6c47.1653144546.git.gitgitgadget@gmail.com (mailing list archive)
State New
Headers show
Series Finish converting git bisect into a built-in | expand

Commit Message

Johannes Schindelin May 21, 2022, 2:49 p.m. UTC
From: Johannes Schindelin <johannes.schindelin@gmx.de>

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 <johannes.schindelin@gmx.de>
---
 builtin/bisect--helper.c | 69 ++++++++++++++++++++++++++--------------
 1 file changed, 46 insertions(+), 23 deletions(-)
diff mbox series

Patch

diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
index 89ff688a4a2..a68f2c5a919 100644
--- a/builtin/bisect--helper.c
+++ b/builtin/bisect--helper.c
@@ -1,6 +1,5 @@ 
 #include "builtin.h"
 #include "cache.h"
-#include "parse-options.h"
 #include "bisect.h"
 #include "refs.h"
 #include "dir.h"
@@ -20,20 +19,46 @@  static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
 static GIT_PATH_FUNC(git_path_bisect_first_parent, "BISECT_FIRST_PARENT")
 static GIT_PATH_FUNC(git_path_bisect_run, "BISECT_RUN")
 
-static const char * const git_bisect_helper_usage[] = {
-	N_("git bisect--helper --bisect-reset [<commit>]"),
-	"git bisect--helper --bisect-terms [--term-good | --term-old | --term-bad | --term-new]",
-	N_("git bisect--helper --bisect-start [--term-{new,bad}=<term> --term-{old,good}=<term>]"
-					    " [--no-checkout] [--first-parent] [<bad> [<good>...]] [--] [<paths>...]"),
-	"git bisect--helper --bisect-next",
-	N_("git bisect--helper [--bisect-state] (bad|new) [<rev>]"),
-	N_("git bisect--helper [--bisect-state] (good|old) [<rev>...]"),
-	N_("git bisect--helper --bisect-replay <filename>"),
-	N_("git bisect--helper --bisect-skip [(<rev>|<range>)...]"),
-	"git bisect--helper --bisect-visualize",
-	N_("git bisect--helper --bisect-run <cmd>..."),
-	NULL
-};
+static const char *bisect_usage =
+	N_("git bisect [help|start|bad|good|new|old|terms|skip|next|reset|"
+	   "visualize|view|replay|log|run]");
+
+static const char *bisect_long_usage =
+	N_("git bisect [help|start|bad|good|new|old|terms|skip|next|reset|"
+	   "visualize|view|replay|log|run]\n"
+	   "\n"
+	   "git bisect help\n"
+	   "\tprint this long help message.\n"
+	   "git bisect start [--term-{new,bad}=<term> "
+		"--term-{old,good}=<term>]\n"
+	   "\t	 [--no-checkout] [--first-parent] [<bad> [<good>...]] [--] "
+		"[<pathspec>...]\n"
+	   "\treset bisect state and start bisection.\n"
+	   "git bisect (bad|new) [<rev>]\n"
+	   "\tmark <rev> a known-bad revision/\n"
+	   "\t	a revision after change in a given property.\n"
+	   "git bisect (good|old) [<rev>...]\n"
+	   "\tmark <rev>... known-good revisions/\n"
+	   "\t	revisions before change in a given property.\n"
+	   "git bisect terms [--term-good | --term-bad]\n"
+	   "\tshow the terms used for old and new commits "
+		"(default: bad, good)\n"
+	   "git bisect skip [(<rev>|<range>)...]\n"
+	   "\tmark <rev>... untestable revisions.\n"
+	   "git bisect next\n"
+	   "\tfind next bisection to test and check it out.\n"
+	   "git bisect reset [<commit>]\n"
+	   "\tfinish bisection search and go back to commit.\n"
+	   "git bisect (visualize|view)\n"
+	   "\tshow bisect status in gitk.\n"
+	   "git bisect replay <logfile>\n"
+	   "\treplay bisection log.\n"
+	   "git bisect log\n"
+	   "\tshow bisect log.\n"
+	   "git bisect run <cmd>...\n"
+	   "\tuse <cmd>... to automatically bisect.\n"
+	   "\n"
+	   "Please use \"git help bisect\" to get the full man page.");
 
 struct add_bisect_ref_data {
 	struct rev_info *revs;
@@ -1277,14 +1302,11 @@  static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
 int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
 {
 	int res = 0;
-	struct option options[] = {
-		OPT_END()
-	};
 	struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL };
 	const char *command = argc > 1 ? argv[1] : "help";
 
 	if (!strcmp("-h", command) || !strcmp("help", command))
-		usage_with_options(git_bisect_helper_usage, options);
+		usage(bisect_long_usage);
 
 	argc -= 2;
 	argv += 2;
@@ -1327,12 +1349,13 @@  int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
 		get_terms(&terms);
 		res = bisect_run(&terms, argv, argc);
 	} else {
+		if (!file_is_not_empty(git_path_bisect_start()) &&
+		    !one_of(command, "bad", "good", "new", "old", NULL))
+			usage(bisect_usage);
 		set_terms(&terms, "bad", "good");
 		get_terms(&terms);
-		if (check_and_set_terms(&terms, command)) {
-			char *msg = xstrfmt(_("unknown command: '%s'"), command);
-			usage_msg_opt(msg, git_bisect_helper_usage, options);
-		}
+		if (check_and_set_terms(&terms, command))
+			usage(bisect_usage);
 		/* shift the `command` back in */
 		argc++;
 		argv--;