@matheusbsbs / matheus-bagliano / commits / efa7ae36c1
Fork 0

init-db: move writing repo version into a function

When we perform a clone, we won't know the remote side's hash algorithm until we've read the heads. Consequently, we'll need to rewrite the repository format version and hash algorithm once we know what the remote side has. Move the code that does this into its own function so that we can call it from clone in the future. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Feb 22, 2020 at 20:17 UTC efa7ae36c134cc0de6f766c1ab5dfd6b55fab65c
2 files changed +25 -18
builtin/init-db.c
+24 -18
@@ -178,6 +178,29 @@ static int needs_work_tree_config(const char *git_dir, const char *work_tree)
178 return 1;
179 }
180
181 +void initialize_repository_version(int hash_algo)
182 +{
183 + char repo_version_string[10];
184 + int repo_version = GIT_REPO_VERSION;
185 +
186 +#ifndef ENABLE_SHA256
187 + if (hash_algo != GIT_HASH_SHA1)
188 + die(_("The hash algorithm %s is not supported in this build."), hash_algos[hash_algo].name);
189 +#endif
190 +
191 + if (hash_algo != GIT_HASH_SHA1)
192 + repo_version = GIT_REPO_VERSION_READ;
193 +
194 + /* This forces creation of new config file */
195 + xsnprintf(repo_version_string, sizeof(repo_version_string),
196 + "%d", repo_version);
197 + git_config_set("core.repositoryformatversion", repo_version_string);
198 +
199 + if (hash_algo != GIT_HASH_SHA1)
200 + git_config_set("extensions.objectformat",
201 + hash_algos[hash_algo].name);
202 +}
203 +
204 static int create_default_files(const char *template_path,
205 const char *original_git_dir,
206 const struct repository_format *fmt)
@@ -185,12 +208,10 @@ static int create_default_files(const char *template_path,
208 struct stat st1;
209 struct strbuf buf = STRBUF_INIT;
210 char *path;
188 - char repo_version_string[10];
211 char junk[2];
212 int reinit;
213 int filemode;
214 struct strbuf err = STRBUF_INIT;
193 - int repo_version = GIT_REPO_VERSION;
215
216 /* Just look for `init.templatedir` */
217 init_db_template_dir = NULL; /* re-set in case it was set before */
@@ -248,22 +269,7 @@ static int create_default_files(const char *template_path,
269 exit(1);
270 }
271
251 -#ifndef ENABLE_SHA256
252 - if (fmt->hash_algo != GIT_HASH_SHA1)
253 - die(_("The hash algorithm %s is not supported in this build."), hash_algos[fmt->hash_algo].name);
254 -#endif
255 -
256 - if (fmt->hash_algo != GIT_HASH_SHA1)
257 - repo_version = GIT_REPO_VERSION_READ;
258 -
259 - /* This forces creation of new config file */
260 - xsnprintf(repo_version_string, sizeof(repo_version_string),
261 - "%d", repo_version);
262 - git_config_set("core.repositoryformatversion", repo_version_string);
263 -
264 - if (fmt->hash_algo != GIT_HASH_SHA1)
265 - git_config_set("extensions.objectformat",
266 - hash_algos[fmt->hash_algo].name);
272 + initialize_repository_version(fmt->hash_algo);
273
274 /* Check filemode trustability */
275 path = git_path_buf(&buf, "config");
cache.h
+1
@@ -629,6 +629,7 @@ int path_inside_repo(const char *prefix, const char *path);
629 int init_db(const char *git_dir, const char *real_git_dir,
630 const char *template_dir, int hash_algo,
631 unsigned int flags);
632 +void initialize_repository_version(int hash_algo);
633
634 void sanitize_stdfds(void);
635 int daemonize(void);