builtin/multi-pack-index.c: display usage on unrecognized command

When given a sub-command that it doesn't understand, 'git multi-pack-index' dies with the following message: $ git multi-pack-index bogus fatal: unrecognized subcommand: bogus Instead of 'die()'-ing, we can display the usage text, which is much more helpful: $ git.compile multi-pack-index bogus error: unrecognized subcommand: bogus usage: git multi-pack-index [<options>] write or: git multi-pack-index [<options>] verify or: git multi-pack-index [<options>] expire or: git multi-pack-index [<options>] repack [--batch-size=<size>] --object-dir <file> object directory containing set of packfile and pack-index pairs --progress force progress reporting While we're at it, clean up some duplication between the "no sub-command" and "unrecognized sub-command" conditionals. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Mar 30, 2021 at 11:04 UTC cd57bc41bbcc8d260040243946d19075eff0bfaf
1 file changed +7 -4
builtin/multi-pack-index.c
+7 -4
@@ -152,8 +152,7 @@ int cmd_multi_pack_index(int argc, const char **argv,
152 opts.object_dir = get_object_directory();
153
154 if (argc == 0)
155 - usage_with_options(builtin_multi_pack_index_usage,
156 - builtin_multi_pack_index_options);
155 + goto usage;
156
157 if (!strcmp(argv[0], "repack"))
158 return cmd_multi_pack_index_repack(argc, argv);
@@ -163,6 +162,10 @@ int cmd_multi_pack_index(int argc, const char **argv,
162 return cmd_multi_pack_index_verify(argc, argv);
163 else if (!strcmp(argv[0], "expire"))
164 return cmd_multi_pack_index_expire(argc, argv);
166 - else
167 - die(_("unrecognized subcommand: %s"), argv[0]);
165 + else {
166 +usage:
167 + error(_("unrecognized subcommand: %s"), argv[0]);
168 + usage_with_options(builtin_multi_pack_index_usage,
169 + builtin_multi_pack_index_options);
170 + }
171 }