From: Junio C Hamano Date: Thu, 19 Nov 2026 18:53:05 GMT Subject: Re: [PATCH] fast-import: do not show the path when "feature export-marks" is forbidden Message-ID: In-Reply-To: <20261117-ks-fast-import-consistent-check-unsafe-v1-1-fc1ed53c79b2@gmail.com> Kaartic Sivaraam writes: > diff --git a/builtin/fast-import.c b/builtin/fast-import.c > index ab5d2a2344..998167794c 100644 > --- a/builtin/fast-import.c > +++ b/builtin/fast-import.c > @@ -3918,7 +3918,7 @@ static int parse_one_feature(struct fast_import_state *state, > check_unsafe_feature(state, "import-marks-if-exists"); > option_import_marks(state, arg, 1, 1); > } else if (skip_prefix(feature, "export-marks=", &arg)) { > - check_unsafe_feature(state, feature); > + check_unsafe_feature(state, "export-marks"); > option_export_marks(state, arg); > } else if (!strcmp(feature, "alias")) { > ; /* Don't die - this feature is supported */ This is an obviously correct change, but doesn't this bug caused by forced repetition annoy anybody? This if/else if/else cascade is an obvious trap waiting for another similar bug to be added. Wouldn't it be much nicer if the above hunk can be rewritten like so, option_import_marks(state, arg, 1, 1); - } else if (skip_prefix(feature, "export-marks=", &arg)) { + } else if (check_unsafe(state, feature, "export-marks", &arg)) { - check_unsafe_feature(state, feature); option_export_marks(state, arg); } else if (!strcmp(feature, "alias")) { ; /* Don't die - this feature is supported */ so a separate call to check_unsafe_feature() can be lost, and we no longer have to repeat "export-marks=" and "export-marks" for all these "unsafe" features? If we plan to ever add an argument-less unsafe feature, the helper needs to be updated to require NUL (instead of '=') after we find the end of the feature name with skip_prefix() when the feature is an argument-less one (perhaps signaled by arg==NULL or something), but you get the idea. builtin/fast-import.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git i/builtin/fast-import.c w/builtin/fast-import.c index ab5d2a2344..673d3f2289 100644 --- i/builtin/fast-import.c +++ w/builtin/fast-import.c @@ -3896,12 +3896,20 @@ static int parse_one_option(struct fast_import_state *state, const char *option) return 1; } -static void check_unsafe_feature(struct fast_import_state *state, - const char *feature) +static int check_unsafe(struct fast_import_state *state, + const char *feature, const char *prefix, + const char **arg) { - if (!state->allow_unsafe_features) - die(_("feature '%s' forbidden in input without --allow-unsafe-features"), - feature); + const char *arg_; + + if (skip_prefix(feature, prefix, &arg_) && *arg_ == '=') { + if (!state->allow_unsafe_features) + die(_("feature '%s' forbidden in input " + "without --allow-unsafe-features"), prefix); + *arg = arg_ + 1; + return 1; + } + return 0; } static int parse_one_feature(struct fast_import_state *state,