Skip to content

Commit 947d234

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 325c017 commit 947d234

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

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
@@ -2775,7 +2775,8 @@ static void repository_format_configure(struct repository *repo,
27752775
repo_fmt->ref_storage_payload);
27762776
}
27772777

2778-
int init_db(const char *git_dir, const char *real_git_dir,
2778+
int init_db(struct repository *repo,
2779+
const char *git_dir, const char *real_git_dir,
27792780
const char *template_dir, int hash,
27802781
enum ref_storage_format ref_storage_format,
27812782
const char *initial_branch,
@@ -2795,13 +2796,13 @@ int init_db(const char *git_dir, const char *real_git_dir,
27952796
if (!exist_ok && !stat(real_git_dir, &st))
27962797
die(_("%s already exists"), real_git_dir);
27972798

2798-
set_git_dir(the_repository, real_git_dir, 1);
2799-
git_dir = repo_get_git_dir(the_repository);
2799+
set_git_dir(repo, real_git_dir, 1);
2800+
git_dir = repo_get_git_dir(repo);
28002801
separate_git_dir(git_dir, original_git_dir);
28012802
}
28022803
else {
2803-
set_git_dir(the_repository, git_dir, 1);
2804-
git_dir = repo_get_git_dir(the_repository);
2804+
set_git_dir(repo, git_dir, 1);
2805+
git_dir = repo_get_git_dir(repo);
28052806
}
28062807
startup_info->have_repository = 1;
28072808

@@ -2811,57 +2812,57 @@ int init_db(const char *git_dir, const char *real_git_dir,
28112812
* config file, so this will not fail. What we are catching
28122813
* is an attempt to reinitialize new repository with an old tool.
28132814
*/
2814-
check_repository_format(the_repository, &repo_fmt);
2815+
check_repository_format(repo, &repo_fmt);
28152816

2816-
repository_format_configure(the_repository, &repo_fmt, hash, ref_storage_format);
2817+
repository_format_configure(repo, &repo_fmt, hash, ref_storage_format);
28172818

28182819
/*
28192820
* Ensure `core.hidedotfiles` is processed. This must happen after we
28202821
* have set up the repository format such that we can evaluate
28212822
* includeIf conditions correctly in the case of re-initialization.
28222823
*/
2823-
repo_config(the_repository, git_default_core_config, NULL);
2824+
repo_config(repo, git_default_core_config, NULL);
28242825

2825-
safe_create_dir(the_repository, git_dir, 0);
2826+
safe_create_dir(repo, git_dir, 0);
28262827

2827-
reinit = create_default_files(the_repository, template_dir, original_git_dir,
2828+
reinit = create_default_files(repo, template_dir, original_git_dir,
28282829
&repo_fmt, init_shared_repository);
28292830

28302831
if (!(flags & INIT_DB_SKIP_REFDB))
2831-
create_reference_database(the_repository, initial_branch, flags & INIT_DB_QUIET);
2832-
create_object_directory(the_repository);
2832+
create_reference_database(repo, initial_branch, flags & INIT_DB_QUIET);
2833+
create_object_directory(repo);
28332834

2834-
if (repo_settings_get_shared_repository(the_repository)) {
2835+
if (repo_settings_get_shared_repository(repo)) {
28352836
char buf[10];
28362837
/* We do not spell "group" and such, so that
28372838
* the configuration can be read by older version
28382839
* of git. Note, we use octal numbers for new share modes,
28392840
* and compatibility values for PERM_GROUP and
28402841
* PERM_EVERYBODY.
28412842
*/
2842-
if (repo_settings_get_shared_repository(the_repository) < 0)
2843+
if (repo_settings_get_shared_repository(repo) < 0)
28432844
/* force to the mode value */
2844-
xsnprintf(buf, sizeof(buf), "0%o", -repo_settings_get_shared_repository(the_repository));
2845-
else if (repo_settings_get_shared_repository(the_repository) == PERM_GROUP)
2845+
xsnprintf(buf, sizeof(buf), "0%o", -repo_settings_get_shared_repository(repo));
2846+
else if (repo_settings_get_shared_repository(repo) == PERM_GROUP)
28462847
xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
2847-
else if (repo_settings_get_shared_repository(the_repository) == PERM_EVERYBODY)
2848+
else if (repo_settings_get_shared_repository(repo) == PERM_EVERYBODY)
28482849
xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
28492850
else
28502851
BUG("invalid value for shared_repository");
2851-
repo_config_set(the_repository, "core.sharedrepository", buf);
2852-
repo_config_set(the_repository, "receive.denyNonFastforwards", "true");
2852+
repo_config_set(repo, "core.sharedrepository", buf);
2853+
repo_config_set(repo, "receive.denyNonFastforwards", "true");
28532854
}
28542855

28552856
if (!(flags & INIT_DB_QUIET)) {
28562857
int len = strlen(git_dir);
28572858

28582859
if (reinit)
2859-
printf(repo_settings_get_shared_repository(the_repository)
2860+
printf(repo_settings_get_shared_repository(repo)
28602861
? _("Reinitialized existing shared Git repository in %s%s\n")
28612862
: _("Reinitialized existing Git repository in %s%s\n"),
28622863
git_dir, len && git_dir[len-1] != '/' ? "/" : "");
28632864
else
2864-
printf(repo_settings_get_shared_repository(the_repository)
2865+
printf(repo_settings_get_shared_repository(repo)
28652866
? _("Initialized empty shared Git repository in %s%s\n")
28662867
: _("Initialized empty Git repository in %s%s\n"),
28672868
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)