rev-list: refactor early option parsing

Before invoking `setup_revisions()`, the `--missing` and `--exclude-promisor-objects` options are parsed early. In a subsequent commit, another option is added that must be parsed early. Refactor the code to parse both options in a single early pass. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Justin Tobler committed Mar 19, 2025 at 13:34 UTC c9907a19169c186da444e22991df7c9f4237ac40
1 file changed +7 -10
builtin/rev-list.c
+7 -10
@@ -16,6 +16,7 @@
16 #include "object-file.h"
17 #include "object-store-ll.h"
18 #include "pack-bitmap.h"
19 +#include "parse-options.h"
20 #include "log-tree.h"
21 #include "graph.h"
22 #include "bisect.h"
@@ -639,19 +640,15 @@ int cmd_rev_list(int argc,
640 if (!strcmp(arg, "--exclude-promisor-objects")) {
641 fetch_if_missing = 0;
642 revs.exclude_promisor_objects = 1;
642 - break;
643 - }
644 - }
645 - for (i = 1; i < argc; i++) {
646 - const char *arg = argv[i];
647 - if (skip_prefix(arg, "--missing=", &arg)) {
648 - if (revs.exclude_promisor_objects)
649 - die(_("options '%s' and '%s' cannot be used together"), "--exclude-promisor-objects", "--missing");
650 - if (parse_missing_action_value(arg))
651 - break;
643 + } else if (skip_prefix(arg, "--missing=", &arg)) {
644 + parse_missing_action_value(arg);
645 }
646 }
647
648 + die_for_incompatible_opt2(revs.exclude_promisor_objects,
649 + "--exclude_promisor_objects",
650 + arg_missing_action, "--missing");
651 +
652 if (arg_missing_action)
653 revs.do_not_die_on_missing_objects = 1;
654