From: Junio C Hamano <gitster@pobox.com>
To: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Cc: Git mailing list <git@vger.kernel.org>
Subject: Re: [PATCH] fast-import: do not show the path when "feature export-marks" is forbidden
Date: Thu, 19 Nov 2026 10:53:05 -0800 [thread overview]
Message-ID: <xmqqbj7ky7ou.fsf@gitster.g> (raw)
In-Reply-To: <20261117-ks-fast-import-consistent-check-unsafe-v1-1-fc1ed53c79b2@gmail.com> (Kaartic Sivaraam's message of "Tue, 17 Nov 2026 21:33:05 +0530")
Kaartic Sivaraam <kaartic.sivaraam@gmail.com> 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,
prev parent reply other threads:[~2026-11-19 18:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 16:03 [PATCH] fast-import: do not show the path when "feature export-marks" is forbidden Kaartic Sivaraam
2026-11-18 11:21 ` Karthik Nayak
2026-11-19 18:53 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqbj7ky7ou.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=kaartic.sivaraam@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox