parse-options: introduce die_for_incompatible_opt2()

The functions die_for_incompatible_opt3() and
die_for_incompatible_opt4() already exist to die whenever a user
specifies three or four options respectively that are not compatible.

Introduce die_for_incompatible_opt2() which dies when two options that
are incompatible are set.

Signed-off-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Toon Claes
2025-02-06 07:33:34 +01:00
committed by Junio C Hamano
parent 7a52a8c7d8
commit 9144b9362b
2 changed files with 13 additions and 3 deletions

View File

@ -163,9 +163,10 @@ static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
get_ref_information(cmd_info, &rinfo); get_ref_information(cmd_info, &rinfo);
if (!rinfo.positive_refexprs) if (!rinfo.positive_refexprs)
die(_("need some commits to replay")); die(_("need some commits to replay"));
if (onto_name && *advance_name)
die(_("--onto and --advance are incompatible")); die_for_incompatible_opt2(!!onto_name, "--onto",
else if (onto_name) { !!*advance_name, "--advance");
if (onto_name) {
*onto = peel_committish(onto_name); *onto = peel_committish(onto_name);
if (rinfo.positive_refexprs < if (rinfo.positive_refexprs <
strset_get_size(&rinfo.positive_refs)) strset_get_size(&rinfo.positive_refs))

View File

@ -436,6 +436,15 @@ static inline void die_for_incompatible_opt3(int opt1, const char *opt1_name,
0, ""); 0, "");
} }
static inline void die_for_incompatible_opt2(int opt1, const char *opt1_name,
int opt2, const char *opt2_name)
{
die_for_incompatible_opt4(opt1, opt1_name,
opt2, opt2_name,
0, "",
0, "");
}
/* /*
* Use these assertions for callbacks that expect to be called with NONEG and * Use these assertions for callbacks that expect to be called with NONEG and
* NOARG respectively, and do not otherwise handle the "unset" and "arg" * NOARG respectively, and do not otherwise handle the "unset" and "arg"