Skip to content

Commit efa7ae3

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c9331a commit efa7ae3

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

builtin/init-db.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,40 @@ static int needs_work_tree_config(const char *git_dir, const char *work_tree)
178178
return 1;
179179
}
180180

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+
181204
static int create_default_files(const char *template_path,
182205
const char *original_git_dir,
183206
const struct repository_format *fmt)
184207
{
185208
struct stat st1;
186209
struct strbuf buf = STRBUF_INIT;
187210
char *path;
188-
char repo_version_string[10];
189211
char junk[2];
190212
int reinit;
191213
int filemode;
192214
struct strbuf err = STRBUF_INIT;
193-
int repo_version = GIT_REPO_VERSION;
194215

195216
/* Just look for `init.templatedir` */
196217
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,
248269
exit(1);
249270
}
250271

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);
267273

268274
/* Check filemode trustability */
269275
path = git_path_buf(&buf, "config");

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ int path_inside_repo(const char *prefix, const char *path);
629629
int init_db(const char *git_dir, const char *real_git_dir,
630630
const char *template_dir, int hash_algo,
631631
unsigned int flags);
632+
void initialize_repository_version(int hash_algo);
632633

633634
void sanitize_stdfds(void);
634635
int daemonize(void);

0 commit comments

Comments
 (0)