[PATCH v3 01/13] parse-options: allow for hidden aliases
From: Patrick Steinhardt <hidden>
Date: 2026-09-09 11:12:59
Subsystem:
the rest · Maintainer:
Linus Torvalds
The `OPT_ALIAS()` option can be used to create an exact alias that maps one option name to the same semantics as another option name. This option type is especially useful when deprecating an old name in favor of a new one. But curiously enough, we don't have the infrastructure in place to properly support this use case because we don't expose the ability to hide the alias via `PARSE_OPT_HIDDEN`. Introduce a new `OPT_ALIAS_F()` function that allows the user to pass flags and propagate these flags when rewriting aliases to match their respective source options. Signed-off-by: Patrick Steinhardt <redacted> --- parse-options.c | 4 +++- parse-options.h | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index 4519ead9dc..51a49792d1 100644
--- a/parse-options.c
+++ b/parse-options.c@@ -925,6 +925,7 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx, const char *long_name; const char *source; struct strbuf help = STRBUF_INIT; + enum parse_opt_option_flags flags; int j; if (newopt[i].type != OPTION_ALIAS)
@@ -933,6 +934,7 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx, short_name = newopt[i].short_name; long_name = newopt[i].long_name; source = newopt[i].value; + flags = newopt[i].flags; if (!long_name) BUG("An alias must have long option name");
@@ -951,7 +953,7 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx, newopt[i].short_name = short_name; newopt[i].long_name = long_name; newopt[i].help = strbuf_detach(&help, NULL); - newopt[i].flags |= PARSE_OPT_FROM_ALIAS; + newopt[i].flags |= flags | PARSE_OPT_FROM_ALIAS; break; }
diff --git a/parse-options.h b/parse-options.h
index d7f896a933..a0b30f3c04 100644
--- a/parse-options.h
+++ b/parse-options.h@@ -386,13 +386,16 @@ static char *parse_options_noop_ignored_value MAYBE_UNUSED; .callback = parse_opt_noop_cb, \ } -#define OPT_ALIAS(s, l, source_long_name) { \ +#define OPT_ALIAS_F(s, l, source_long_name, f) { \ .type = OPTION_ALIAS, \ .short_name = (s), \ .long_name = (l), \ .value = (char *)(source_long_name), \ + .flags = (f), \ } +#define OPT_ALIAS(s, l, source_long_name) OPT_ALIAS_F(s, l, source_long_name, 0) + #define OPT_SUBCOMMAND_F(l, v, fn, f) { \ .type = OPTION_SUBCOMMAND, \ .long_name = (l), \
--
2.55.0.1074.ge7621b4bad.dirty