git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] Revert "builtin/bundle.c: let parse-options parse subcommands"
@ 2022-12-20 12:31 Hubert Jasudowicz
  2022-12-20 13:30 ` Derrick Stolee
  2022-12-20 13:40 ` [PATCH] bundle: don't segfault on "git bundle <subcmd>" Ævar Arnfjörð Bjarmason
  0 siblings, 2 replies; 11+ messages in thread
From: Hubert Jasudowicz @ 2022-12-20 12:31 UTC (permalink / raw)
  To: git; +Cc: Hubert Jasudowicz, Junio C Hamano, SZEDER Gábor

This reverts commit aef7d75e5809eda765bbe407c7f8e0f8617f0fd0.

The change breaks git bundle command. Running any subcommand
results with:

$ git bundle create
Segmentation fault (core dumped)

After reverting the change, everything works correctly.
---
 builtin/bundle.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/builtin/bundle.c b/builtin/bundle.c
index c12c09f854..d9b46f8e03 100644
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -206,19 +206,30 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
 
 int cmd_bundle(int argc, const char **argv, const char *prefix)
 {
-	parse_opt_subcommand_fn *fn = NULL;
 	struct option options[] = {
-		OPT_SUBCOMMAND("create", &fn, cmd_bundle_create),
-		OPT_SUBCOMMAND("verify", &fn, cmd_bundle_verify),
-		OPT_SUBCOMMAND("list-heads", &fn, cmd_bundle_list_heads),
-		OPT_SUBCOMMAND("unbundle", &fn, cmd_bundle_unbundle),
 		OPT_END()
 	};
+	int result;
 
 	argc = parse_options(argc, argv, prefix, options, builtin_bundle_usage,
-			     0);
+		PARSE_OPT_STOP_AT_NON_OPTION);
 
 	packet_trace_identity("bundle");
 
-	return !!fn(argc, argv, prefix);
+	if (argc < 2)
+		usage_with_options(builtin_bundle_usage, options);
+
+	else if (!strcmp(argv[0], "create"))
+		result = cmd_bundle_create(argc, argv, prefix);
+	else if (!strcmp(argv[0], "verify"))
+		result = cmd_bundle_verify(argc, argv, prefix);
+	else if (!strcmp(argv[0], "list-heads"))
+		result = cmd_bundle_list_heads(argc, argv, prefix);
+	else if (!strcmp(argv[0], "unbundle"))
+		result = cmd_bundle_unbundle(argc, argv, prefix);
+	else {
+		error(_("Unknown subcommand: %s"), argv[0]);
+		usage_with_options(builtin_bundle_usage, options);
+	}
+	return result ? 1 : 0;
 }
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-12-27 23:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-20 12:31 [PATCH] Revert "builtin/bundle.c: let parse-options parse subcommands" Hubert Jasudowicz
2022-12-20 13:30 ` Derrick Stolee
2022-12-20 13:42   ` Ævar Arnfjörð Bjarmason
2022-12-20 13:40 ` [PATCH] bundle: don't segfault on "git bundle <subcmd>" Ævar Arnfjörð Bjarmason
2022-12-20 13:50   ` Hubert Jasudowicz
2022-12-25 11:06     ` Junio C Hamano
2022-12-25 11:05   ` Junio C Hamano
2022-12-27 18:39     ` [PATCH 0/2] builtin/bundle.c: segfault fix style & error reporting follow-up Ævar Arnfjörð Bjarmason
2022-12-27 18:39       ` [PATCH 1/2] builtin/bundle.c: remove superfluous "newargc" variable Ævar Arnfjörð Bjarmason
2022-12-27 18:39       ` [PATCH 2/2] bundle <cmd>: have usage_msg_opt() note the missing "<file>" Ævar Arnfjörð Bjarmason
2022-12-27 23:32       ` [PATCH 0/2] builtin/bundle.c: segfault fix style & error reporting follow-up Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).