]> git.ipfire.org Git - thirdparty/git.git/commitdiff
setup: don't modify repo in `create_reference_database()`
authorKarthik Nayak <karthik.188@gmail.com>
Wed, 25 Feb 2026 09:40:41 +0000 (10:40 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Feb 2026 17:27:11 +0000 (09:27 -0800)
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>
builtin/clone.c
setup.c
setup.h

index b40cee596804f5547e73f38a36521cf889debce6..cd43bb5aa22a7661cab3e432a37edb574b477b64 100644 (file)
@@ -1442,7 +1442,7 @@ int cmd_clone(int argc,
        hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
        initialize_repository_version(hash_algo, the_repository->ref_storage_format, 1);
        repo_set_hash_algo(the_repository, hash_algo);
-       create_reference_database(the_repository->ref_storage_format, NULL, 1);
+       create_reference_database(NULL, 1);
 
        /*
         * Before fetching from the remote, download and install bundle
diff --git a/setup.c b/setup.c
index b723f8b33931bd22246d4120afed3b7bef59c8ae..1fc9ae3872809cfa973514fb9dc40c4c107a6ea0 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -2359,14 +2359,12 @@ static int is_reinit(void)
        return ret;
 }
 
-void create_reference_database(enum ref_storage_format ref_storage_format,
-                              const char *initial_branch, int quiet)
+void create_reference_database(const char *initial_branch, int quiet)
 {
        struct strbuf err = STRBUF_INIT;
        char *to_free = NULL;
        int reinit = is_reinit();
 
-       repo_set_ref_storage_format(the_repository, ref_storage_format);
        if (ref_store_create_on_disk(get_main_ref_store(the_repository), 0, &err))
                die("failed to set up refs db: %s", err.buf);
 
@@ -2701,8 +2699,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
                                      &repo_fmt, init_shared_repository);
 
        if (!(flags & INIT_DB_SKIP_REFDB))
-               create_reference_database(repo_fmt.ref_storage_format,
-                                         initial_branch, flags & INIT_DB_QUIET);
+               create_reference_database(initial_branch, flags & INIT_DB_QUIET);
        create_object_directory();
 
        if (repo_settings_get_shared_repository(the_repository)) {
diff --git a/setup.h b/setup.h
index d55dcc66086308b31d86f28bcbb84f5d01e4453f..ddb9f6701c2df76d00f7d76a6fdff4c9e48670ce 100644 (file)
--- a/setup.h
+++ b/setup.h
@@ -240,8 +240,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
 void initialize_repository_version(int hash_algo,
                                   enum ref_storage_format ref_storage_format,
                                   int reinit);
-void create_reference_database(enum ref_storage_format ref_storage_format,
-                              const char *initial_branch, int quiet);
+void create_reference_database(const char *initial_branch, int quiet);
 
 /*
  * NOTE NOTE NOTE!!