Skip to content

Commit 2c69ff4

Browse files
KarthikNayakgitster
authored andcommitted
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>
1 parent 67ad421 commit 2c69ff4

3 files changed

Lines changed: 4 additions & 8 deletions

File tree

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ int cmd_clone(int argc,
14421442
hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
14431443
initialize_repository_version(hash_algo, the_repository->ref_storage_format, 1);
14441444
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);
14461446

14471447
/*
14481448
* Before fetching from the remote, download and install bundle

setup.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,14 +2359,12 @@ static int is_reinit(void)
23592359
return ret;
23602360
}
23612361

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)
23642363
{
23652364
struct strbuf err = STRBUF_INIT;
23662365
char *to_free = NULL;
23672366
int reinit = is_reinit();
23682367

2369-
repo_set_ref_storage_format(the_repository, ref_storage_format);
23702368
if (ref_store_create_on_disk(get_main_ref_store(the_repository), 0, &err))
23712369
die("failed to set up refs db: %s", err.buf);
23722370

@@ -2701,8 +2699,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
27012699
&repo_fmt, init_shared_repository);
27022700

27032701
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);
27062703
create_object_directory();
27072704

27082705
if (repo_settings_get_shared_repository(the_repository)) {

setup.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
240240
void initialize_repository_version(int hash_algo,
241241
enum ref_storage_format ref_storage_format,
242242
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);
245244

246245
/*
247246
* NOTE NOTE NOTE!!

0 commit comments

Comments
 (0)