pack-objects: use standard option incompatibility functions

pack-objects has a handful of explicit checks for pairs of command-line options which are mutually incompatible. Many of these pre-date a699367bb8 (i18n: factorize more 'incompatible options' messages, 2022-01-31). Convert the explicit checks into die_for_incompatible_opt2() calls, which simplifies the implementation and standardizes pack-objects' output when given incompatible options (e.g., --stdin-packs with --filter gives different output than --keep-unreachable with --unpack-unreachable). There is one minor piece of test fallout in t5331 that expects the old format, which has been corrected. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Jun 23, 2025 at 18:32 UTC 798ddd947ffe9d608d9aa5803dc7c409834e7159
2 files changed +12 -10
builtin/pack-objects.c
+11 -9
@@ -5010,9 +5010,10 @@ int cmd_pack_objects(int argc,
5010 strvec_push(&rp, "--unpacked");
5011 }
5012
5013 - if (exclude_promisor_objects && exclude_promisor_objects_best_effort)
5014 - die(_("options '%s' and '%s' cannot be used together"),
5015 - "--exclude-promisor-objects", "--exclude-promisor-objects-best-effort");
5013 + die_for_incompatible_opt2(exclude_promisor_objects,
5014 + "--exclude-promisor-objects",
5015 + exclude_promisor_objects_best_effort,
5016 + "--exclude-promisor-objects-best-effort");
5017 if (exclude_promisor_objects) {
5018 use_internal_rev_list = 1;
5019 fetch_if_missing = 0;
@@ -5050,13 +5051,14 @@ int cmd_pack_objects(int argc,
5051 if (!pack_to_stdout && thin)
5052 die(_("--thin cannot be used to build an indexable pack"));
5053
5053 - if (keep_unreachable && unpack_unreachable)
5054 - die(_("options '%s' and '%s' cannot be used together"), "--keep-unreachable", "--unpack-unreachable");
5054 + die_for_incompatible_opt2(keep_unreachable, "--keep-unreachable",
5055 + unpack_unreachable, "--unpack-unreachable");
5056 if (!rev_list_all || !rev_list_reflog || !rev_list_index)
5057 unpack_unreachable_expiration = 0;
5058
5058 - if (stdin_packs && filter_options.choice)
5059 - die(_("cannot use --filter with --stdin-packs"));
5059 + die_for_incompatible_opt2(stdin_packs, "--stdin-packs",
5060 + filter_options.choice, "--filter");
5061 +
5062
5063 if (stdin_packs && use_internal_rev_list)
5064 die(_("cannot use internal rev list with --stdin-packs"));
@@ -5064,8 +5066,8 @@ int cmd_pack_objects(int argc,
5066 if (cruft) {
5067 if (use_internal_rev_list)
5068 die(_("cannot use internal rev list with --cruft"));
5067 - if (stdin_packs)
5068 - die(_("cannot use --stdin-packs with --cruft"));
5069 + die_for_incompatible_opt2(stdin_packs, "--stdin-packs",
5070 + cruft, "--cruft");
5071 }
5072
5073 /*
t/t5331-pack-objects-stdin.sh
+1 -1
@@ -64,7 +64,7 @@ test_expect_success '--stdin-packs is incompatible with --filter' '
64 cd stdin-packs &&
65 test_must_fail git pack-objects --stdin-packs --stdout \
66 --filter=blob:none </dev/null 2>err &&
67 - test_grep "cannot use --filter with --stdin-packs" err
67 + test_grep "options .--stdin-packs. and .--filter. cannot be used together" err
68 )
69 '
70