git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Revert "builtin/bundle.c: let parse-options parse subcommands"

From
HJHubert Jasudowicz <hubertj@stmcyber.pl>
Date
Dec 20, 2022, 12:31 UTC
Message-ID
<20221220123142.812965-1-hubertj@stmcyber.pl>
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
Next: Derrick Stolee
Message 1 of 11 in “Revert "builtin/bundle.c: let parse-options parse subcommands"”
  1. Revert "builtin/bundle.c: let parse-options parse subcommands"Hubert Jasudowicz, Dec 20, 2022
  2. Derrick StoleeDec 20, 2022
  3. Ævar Arnfjörð BjarmasonDec 20, 2022
  4. bundle: don't segfault on "git bundle <subcmd>"Ævar Arnfjörð Bjarmason, Dec 20, 2022
  5. Hubert JasudowiczDec 20, 2022
  6. Junio C HamanoDec 25, 2022
  7. Junio C HamanoDec 25, 2022
  8. 0/2 builtin/bundle.c: segfault fix style & error reporting follow-upÆvar Arnfjörð Bjarmason, Dec 27, 2022
  9. 1/2 builtin/bundle.c: remove superfluous "newargc" variableÆvar Arnfjörð Bjarmason, Dec 27, 2022
  10. 2/2 bundle <cmd>: have usage_msg_opt() note the missing "<file>"Ævar Arnfjörð Bjarmason, Dec 27, 2022
  11. Junio C HamanoDec 27, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.