Skip to content

Commit 58be32f

Browse files
pks-tgitster
authored andcommitted
setup: set repository's formats on init
The proper hash algorithm and ref storage format that will be used for a newly initialized repository will be figured out in `init_db()` via `validate_hash_algorithm()` and `validate_ref_storage_format()`. Until now though, we never set up the hash algorithm or ref storage format of `the_repository` accordingly. There are only two callsites of `init_db()`, one in git-init(1) and one in git-clone(1). The former function doesn't care for the formats to be set up properly because it never access the repository after calling the function in the first place. For git-clone(1) it's a different story though, as we call `init_db()` before listing remote refs. While we do indeed have the wrong hash function in `the_repository` when `init_db()` sets up a non-default object format for the repository, it never mattered because we adjust the hash after learning about the remote's hash function via the listed refs. So the current state is correct for the hash algo, but it's not for the ref storage format because git-clone(1) wouldn't know to set it up properly. But instead of adjusting only the `ref_storage_format`, set both the hash algo and the ref storage format so that `the_repository` is in the correct state when `init_db()` exits. This is fine as we will adjust the hash later on anyway and makes it easier to reason about the end state of `the_repository`. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 173761e commit 58be32f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

setup.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,6 +2207,13 @@ int init_db(const char *git_dir, const char *real_git_dir,
22072207
&repo_fmt, prev_bare_repository,
22082208
init_shared_repository);
22092209

2210+
/*
2211+
* Now that we have set up both the hash algorithm and the ref storage
2212+
* format we can update the repository's settings accordingly.
2213+
*/
2214+
repo_set_hash_algo(the_repository, repo_fmt.hash_algo);
2215+
repo_set_ref_storage_format(the_repository, repo_fmt.ref_storage_format);
2216+
22102217
if (!(flags & INIT_DB_SKIP_REFDB))
22112218
create_reference_database(repo_fmt.ref_storage_format,
22122219
initial_branch, flags & INIT_DB_QUIET);

0 commit comments

Comments
 (0)