git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] fast-import: do not show the path when "feature export-marks" is forbidden

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 19, 2026, 18:53 UTC
Message-ID
<xmqqbj7ky7ou.fsf@gitster.g>
In-Reply-To
<20261117-ks-fast-import-consistent-check-unsafe-v1-1-fc1ed53c79b2@gmail.com>
Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:
Show 13 quoted lines
> 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,
Previous: Karthik Nayak
Message 3 of 3 in “fast-import: do not show the path when "feature export-marks" is forbidden”
  1. fast-import: do not show the path when "feature export-marks" is forbiddenKaartic Sivaraam, Nov 17, 2026
  2. Karthik NayakNov 18, 2026
  3. Junio C HamanoNov 19, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.