diff mbox series

[v4,32/39] setup: add support for reading extensions.objectformat

Message ID 20200726195424.626969-33-sandals@crustytoothpaste.net (mailing list archive)
State New, archived
Headers show
Series [v4,01/39] t: make test-bloom initialize repository | expand

Commit Message

brian m. carlson July 26, 2020, 7:54 p.m. UTC
The transition plan specifies extensions.objectFormat as the indication
that we're using a given hash in a certain repo.  Read this as one of
the extensions we support.  If the user has specified an invalid value,
fail.

Ensure that we reject the extension if the repository format version is
0.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 setup.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

Eric Sunshine July 26, 2020, 11:34 p.m. UTC | #1
On Sun, Jul 26, 2020 at 3:56 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
> The transition plan specifies extensions.objectFormat as the indication
> that we're using a given hash in a certain repo.  Read this as one of
> the extensions we support.  If the user has specified an invalid value,
> fail.
>
> Ensure that we reject the extension if the repository format version is
> 0.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> diff --git a/setup.c b/setup.c
> @@ -470,7 +470,16 @@ static int check_repo_format(const char *var, const char *value, void *vdata)
> +               else if (!strcmp(ext, "objectformat")) {
> +                       int format;
> +
> +                       if (!value)
> +                               return config_error_nonbool(var);
> +                       format = hash_algo_by_name(value);
> +                       if (format == GIT_HASH_UNKNOWN)
> +                               return error("invalid value for 'extensions.objectformat'");

Not necessarily worth a re-roll, but this error message could be more
helpful by providing additional context:

    return error("invalid value for extensions.objectFormat: %s", value);

Notice I also capitalized "Format" since this is a user-facing message.

Also, should this message be localizable _(...)?
brian m. carlson July 26, 2020, 11:41 p.m. UTC | #2
On 2020-07-26 at 23:34:23, Eric Sunshine wrote:
> Not necessarily worth a re-roll, but this error message could be more
> helpful by providing additional context:
> 
>     return error("invalid value for extensions.objectFormat: %s", value);
> 
> Notice I also capitalized "Format" since this is a user-facing message.
> 
> Also, should this message be localizable _(...)?

This message is actually going away and Junio's merge into seen removes
it entirely in favor of Peff's solution.  So I'm going to leave it as it
is to improve conflict resolution since it won't live much longer than
this specific series, and may not even live that long depending on the
release and when Peff's series gets merged in.
diff mbox series

Patch

diff --git a/setup.c b/setup.c
index 3a81307602..94e68bb4f4 100644
--- a/setup.c
+++ b/setup.c
@@ -470,7 +470,16 @@  static int check_repo_format(const char *var, const char *value, void *vdata)
 			data->partial_clone = xstrdup(value);
 		} else if (!strcmp(ext, "worktreeconfig"))
 			data->worktree_config = git_config_bool(var, value);
-		else
+		else if (!strcmp(ext, "objectformat")) {
+			int format;
+
+			if (!value)
+				return config_error_nonbool(var);
+			format = hash_algo_by_name(value);
+			if (format == GIT_HASH_UNKNOWN)
+				return error("invalid value for 'extensions.objectformat'");
+			data->hash_algo = format;
+		} else
 			string_list_append(&data->unknown_extensions, ext);
 	}
 
@@ -613,6 +622,11 @@  int verify_repository_format(const struct repository_format *format,
 		return -1;
 	}
 
+	if (format->version <= 0 && format->hash_algo != GIT_HASH_SHA1) {
+		strbuf_addstr(err, _("extensions.objectFormat is not valid in repo v0"));
+		return -1;
+	}
+
 	return 0;
 }