[31/38] setup: add support for reading extensions.objectformat
diff mbox series

Message ID 20200710024728.3100527-32-sandals@crustytoothpaste.net
State New
Headers show
Series
  • SHA-256, part 3/3
Related show

Commit Message

brian m. carlson July 10, 2020, 2:47 a.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 don't use the value of the extension if the repository
format version is 0.

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

Patch
diff mbox series

diff --git a/setup.c b/setup.c
index dbac2eabe8..4dbfe34c03 100644
--- a/setup.c
+++ b/setup.c
@@ -471,7 +471,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);
 	}
 
@@ -515,6 +524,7 @@  static int check_repository_format_gently(const char *gitdir, struct repository_
 		repository_format_precious_objects = 0;
 		set_repository_format_partial_clone(NULL);
 		repository_format_worktree_config = 0;
+		candidate->hash_algo = GIT_HASH_SHA1;
 	}
 	string_list_clear(&candidate->unknown_extensions, 0);