setup: don't modify repo in `create_reference_database()`

The `create_reference_database()` function is used to create the reference database during initialization of a repository. The function calls `repo_set_ref_storage_format()` to set the repositories reference format. This is an unexpected side-effect of the function. More so because the function is only called in two locations: 1. During git-init(1) where the value is propagated from the `struct repository_format repo_fmt` value. 2. During git-clone(1) where the value is propagated from the `the_repository` value. The former is valid, however the flow already calls `repo_set_ref_storage_format()`, so this effort is simply duplicated. The latter sets the existing value in `the_repository` back to itself. While this is okay for now, introduction of more fields in `repo_set_ref_storage_format()` would cause issues, especially dynamically allocated strings, where we would free/allocate the same string back into `the_repostiory`. To avoid all this confusion, clean up the function to no longer take in and set the repo's reference storage format. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karthik Nayak committed Feb 25, 2026 at 10:40 UTC 2c69ff481938a10660c2078cf83235db26773254
3 files changed +4 -8
builtin/clone.c
+1 -1
@@ -1442,7 +1442,7 @@ int cmd_clone(int argc,
1442 hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
1443 initialize_repository_version(hash_algo, the_repository->ref_storage_format, 1);
1444 repo_set_hash_algo(the_repository, hash_algo);
1445 - create_reference_database(the_repository->ref_storage_format, NULL, 1);
1445 + create_reference_database(NULL, 1);
1446
1447 /*
1448 * Before fetching from the remote, download and install bundle
setup.c
+2 -5
@@ -2359,14 +2359,12 @@ static int is_reinit(void)
2359 return ret;
2360 }
2361
2362 -void create_reference_database(enum ref_storage_format ref_storage_format,
2363 - const char *initial_branch, int quiet)
2362 +void create_reference_database(const char *initial_branch, int quiet)
2363 {
2364 struct strbuf err = STRBUF_INIT;
2365 char *to_free = NULL;
2366 int reinit = is_reinit();
2367
2369 - repo_set_ref_storage_format(the_repository, ref_storage_format);
2368 if (ref_store_create_on_disk(get_main_ref_store(the_repository), 0, &err))
2369 die("failed to set up refs db: %s", err.buf);
2370
@@ -2701,8 +2699,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
2699 &repo_fmt, init_shared_repository);
2700
2701 if (!(flags & INIT_DB_SKIP_REFDB))
2704 - create_reference_database(repo_fmt.ref_storage_format,
2705 - initial_branch, flags & INIT_DB_QUIET);
2702 + create_reference_database(initial_branch, flags & INIT_DB_QUIET);
2703 create_object_directory();
2704
2705 if (repo_settings_get_shared_repository(the_repository)) {
setup.h
+1 -2
@@ -240,8 +240,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
240 void initialize_repository_version(int hash_algo,
241 enum ref_storage_format ref_storage_format,
242 int reinit);
243 -void create_reference_database(enum ref_storage_format ref_storage_format,
244 - const char *initial_branch, int quiet);
243 +void create_reference_database(const char *initial_branch, int quiet);
244
245 /*
246 * NOTE NOTE NOTE!!