Skip to content

Commit cafcb2b

Browse files
pks-tgitster
authored andcommitted
setup: stop using the_repository in init_db()
Stop using `the_repository` in `init_db()` and instead accept the repository as a parameter. The injection of `the_repository` is thus bumped one level higher, where callers now pass it in explicitly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 02527e5 commit cafcb2b

4 files changed

Lines changed: 26 additions & 24 deletions

File tree

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ int cmd_clone(int argc,
11841184
* repository, and reference backends may persist that information into
11851185
* their on-disk data structures.
11861186
*/
1187-
init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN,
1187+
init_db(the_repository, git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN,
11881188
ref_storage_format, NULL,
11891189
do_not_override_repo_unix_permissions, INIT_DB_QUIET | INIT_DB_SKIP_REFDB);
11901190

builtin/init-db.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ int cmd_init_db(int argc,
252252
}
253253

254254
flags |= INIT_DB_EXIST_OK;
255-
ret = init_db(git_dir, real_git_dir, template_dir, hash_algo,
255+
ret = init_db(the_repository, git_dir, real_git_dir, template_dir, hash_algo,
256256
ref_storage_format, initial_branch,
257257
init_shared_repository, flags);
258258

setup.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,7 +2769,8 @@ static void repository_format_configure(struct repository *repo,
27692769
repo_fmt->ref_storage_payload);
27702770
}
27712771

2772-
int init_db(const char *git_dir, const char *real_git_dir,
2772+
int init_db(struct repository *repo,
2773+
const char *git_dir, const char *real_git_dir,
27732774
const char *template_dir, int hash,
27742775
enum ref_storage_format ref_storage_format,
27752776
const char *initial_branch,
@@ -2789,13 +2790,13 @@ int init_db(const char *git_dir, const char *real_git_dir,
27892790
if (!exist_ok && !stat(real_git_dir, &st))
27902791
die(_("%s already exists"), real_git_dir);
27912792

2792-
set_git_dir(the_repository, real_git_dir, 1);
2793-
git_dir = repo_get_git_dir(the_repository);
2793+
set_git_dir(repo, real_git_dir, 1);
2794+
git_dir = repo_get_git_dir(repo);
27942795
separate_git_dir(git_dir, original_git_dir);
27952796
}
27962797
else {
2797-
set_git_dir(the_repository, git_dir, 1);
2798-
git_dir = repo_get_git_dir(the_repository);
2798+
set_git_dir(repo, git_dir, 1);
2799+
git_dir = repo_get_git_dir(repo);
27992800
}
28002801
startup_info->have_repository = 1;
28012802

@@ -2805,57 +2806,57 @@ int init_db(const char *git_dir, const char *real_git_dir,
28052806
* config file, so this will not fail. What we are catching
28062807
* is an attempt to reinitialize new repository with an old tool.
28072808
*/
2808-
check_repository_format(the_repository, &repo_fmt);
2809+
check_repository_format(repo, &repo_fmt);
28092810

2810-
repository_format_configure(the_repository, &repo_fmt, hash, ref_storage_format);
2811+
repository_format_configure(repo, &repo_fmt, hash, ref_storage_format);
28112812

28122813
/*
28132814
* Ensure `core.hidedotfiles` is processed. This must happen after we
28142815
* have set up the repository format such that we can evaluate
28152816
* includeIf conditions correctly in the case of re-initialization.
28162817
*/
2817-
repo_config(the_repository, git_default_core_config, NULL);
2818+
repo_config(repo, git_default_core_config, NULL);
28182819

2819-
safe_create_dir(the_repository, git_dir, 0);
2820+
safe_create_dir(repo, git_dir, 0);
28202821

2821-
reinit = create_default_files(the_repository, template_dir, original_git_dir,
2822+
reinit = create_default_files(repo, template_dir, original_git_dir,
28222823
&repo_fmt, init_shared_repository);
28232824

28242825
if (!(flags & INIT_DB_SKIP_REFDB))
2825-
create_reference_database(the_repository, initial_branch, flags & INIT_DB_QUIET);
2826-
create_object_directory(the_repository);
2826+
create_reference_database(repo, initial_branch, flags & INIT_DB_QUIET);
2827+
create_object_directory(repo);
28272828

2828-
if (repo_settings_get_shared_repository(the_repository)) {
2829+
if (repo_settings_get_shared_repository(repo)) {
28292830
char buf[10];
28302831
/* We do not spell "group" and such, so that
28312832
* the configuration can be read by older version
28322833
* of git. Note, we use octal numbers for new share modes,
28332834
* and compatibility values for PERM_GROUP and
28342835
* PERM_EVERYBODY.
28352836
*/
2836-
if (repo_settings_get_shared_repository(the_repository) < 0)
2837+
if (repo_settings_get_shared_repository(repo) < 0)
28372838
/* force to the mode value */
2838-
xsnprintf(buf, sizeof(buf), "0%o", -repo_settings_get_shared_repository(the_repository));
2839-
else if (repo_settings_get_shared_repository(the_repository) == PERM_GROUP)
2839+
xsnprintf(buf, sizeof(buf), "0%o", -repo_settings_get_shared_repository(repo));
2840+
else if (repo_settings_get_shared_repository(repo) == PERM_GROUP)
28402841
xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
2841-
else if (repo_settings_get_shared_repository(the_repository) == PERM_EVERYBODY)
2842+
else if (repo_settings_get_shared_repository(repo) == PERM_EVERYBODY)
28422843
xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
28432844
else
28442845
BUG("invalid value for shared_repository");
2845-
repo_config_set(the_repository, "core.sharedrepository", buf);
2846-
repo_config_set(the_repository, "receive.denyNonFastforwards", "true");
2846+
repo_config_set(repo, "core.sharedrepository", buf);
2847+
repo_config_set(repo, "receive.denyNonFastforwards", "true");
28472848
}
28482849

28492850
if (!(flags & INIT_DB_QUIET)) {
28502851
int len = strlen(git_dir);
28512852

28522853
if (reinit)
2853-
printf(repo_settings_get_shared_repository(the_repository)
2854+
printf(repo_settings_get_shared_repository(repo)
28542855
? _("Reinitialized existing shared Git repository in %s%s\n")
28552856
: _("Reinitialized existing Git repository in %s%s\n"),
28562857
git_dir, len && git_dir[len-1] != '/' ? "/" : "");
28572858
else
2858-
printf(repo_settings_get_shared_repository(the_repository)
2859+
printf(repo_settings_get_shared_repository(repo)
28592860
? _("Initialized empty shared Git repository in %s%s\n")
28602861
: _("Initialized empty Git repository in %s%s\n"),
28612862
git_dir, len && git_dir[len-1] != '/' ? "/" : "");

setup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ const char *get_template_dir(const char *option_template);
227227
#define INIT_DB_EXIST_OK (1 << 1)
228228
#define INIT_DB_SKIP_REFDB (1 << 2)
229229

230-
int init_db(const char *git_dir, const char *real_git_dir,
230+
int init_db(struct repository *repo,
231+
const char *git_dir, const char *real_git_dir,
231232
const char *template_dir, int hash_algo,
232233
enum ref_storage_format ref_storage_format,
233234
const char *initial_branch, int init_shared_repository,

0 commit comments

Comments
 (0)