Skip to content

Commit df69f40

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 1505389 commit df69f40

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
@@ -1186,7 +1186,7 @@ int cmd_clone(int argc,
11861186
* repository, and reference backends may persist that information into
11871187
* their on-disk data structures.
11881188
*/
1189-
init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN,
1189+
init_db(the_repository, git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN,
11901190
ref_storage_format, NULL,
11911191
do_not_override_repo_unix_permissions, INIT_DB_QUIET | INIT_DB_SKIP_REFDB);
11921192

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
@@ -2778,7 +2778,8 @@ static void repository_format_configure(struct repository *repo,
27782778
repo_fmt->ref_storage_payload);
27792779
}
27802780

2781-
int init_db(const char *git_dir, const char *real_git_dir,
2781+
int init_db(struct repository *repo,
2782+
const char *git_dir, const char *real_git_dir,
27822783
const char *template_dir, int hash,
27832784
enum ref_storage_format ref_storage_format,
27842785
const char *initial_branch,
@@ -2798,13 +2799,13 @@ int init_db(const char *git_dir, const char *real_git_dir,
27982799
if (!exist_ok && !stat(real_git_dir, &st))
27992800
die(_("%s already exists"), real_git_dir);
28002801

2801-
set_git_dir(the_repository, real_git_dir, 1);
2802-
git_dir = repo_get_git_dir(the_repository);
2802+
set_git_dir(repo, real_git_dir, 1);
2803+
git_dir = repo_get_git_dir(repo);
28032804
separate_git_dir(git_dir, original_git_dir);
28042805
}
28052806
else {
2806-
set_git_dir(the_repository, git_dir, 1);
2807-
git_dir = repo_get_git_dir(the_repository);
2807+
set_git_dir(repo, git_dir, 1);
2808+
git_dir = repo_get_git_dir(repo);
28082809
}
28092810
startup_info->have_repository = 1;
28102811

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

2819-
repository_format_configure(the_repository, &repo_fmt, hash, ref_storage_format);
2820+
repository_format_configure(repo, &repo_fmt, hash, ref_storage_format);
28202821

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

2828-
safe_create_dir(the_repository, git_dir, 0);
2829+
safe_create_dir(repo, git_dir, 0);
28292830

2830-
reinit = create_default_files(the_repository, template_dir, original_git_dir,
2831+
reinit = create_default_files(repo, template_dir, original_git_dir,
28312832
&repo_fmt, init_shared_repository);
28322833

28332834
if (!(flags & INIT_DB_SKIP_REFDB))
2834-
create_reference_database(the_repository, initial_branch, flags & INIT_DB_QUIET);
2835-
create_object_directory(the_repository);
2835+
create_reference_database(repo, initial_branch, flags & INIT_DB_QUIET);
2836+
create_object_directory(repo);
28362837

2837-
if (repo_settings_get_shared_repository(the_repository)) {
2838+
if (repo_settings_get_shared_repository(repo)) {
28382839
char buf[10];
28392840
/* We do not spell "group" and such, so that
28402841
* the configuration can be read by older version
28412842
* of git. Note, we use octal numbers for new share modes,
28422843
* and compatibility values for PERM_GROUP and
28432844
* PERM_EVERYBODY.
28442845
*/
2845-
if (repo_settings_get_shared_repository(the_repository) < 0)
2846+
if (repo_settings_get_shared_repository(repo) < 0)
28462847
/* force to the mode value */
2847-
xsnprintf(buf, sizeof(buf), "0%o", -repo_settings_get_shared_repository(the_repository));
2848-
else if (repo_settings_get_shared_repository(the_repository) == PERM_GROUP)
2848+
xsnprintf(buf, sizeof(buf), "0%o", -repo_settings_get_shared_repository(repo));
2849+
else if (repo_settings_get_shared_repository(repo) == PERM_GROUP)
28492850
xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
2850-
else if (repo_settings_get_shared_repository(the_repository) == PERM_EVERYBODY)
2851+
else if (repo_settings_get_shared_repository(repo) == PERM_EVERYBODY)
28512852
xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
28522853
else
28532854
BUG("invalid value for shared_repository");
2854-
repo_config_set(the_repository, "core.sharedrepository", buf);
2855-
repo_config_set(the_repository, "receive.denyNonFastforwards", "true");
2855+
repo_config_set(repo, "core.sharedrepository", buf);
2856+
repo_config_set(repo, "receive.denyNonFastforwards", "true");
28562857
}
28572858

28582859
if (!(flags & INIT_DB_QUIET)) {
28592860
int len = strlen(git_dir);
28602861

28612862
if (reinit)
2862-
printf(repo_settings_get_shared_repository(the_repository)
2863+
printf(repo_settings_get_shared_repository(repo)
28632864
? _("Reinitialized existing shared Git repository in %s%s\n")
28642865
: _("Reinitialized existing Git repository in %s%s\n"),
28652866
git_dir, len && git_dir[len-1] != '/' ? "/" : "");
28662867
else
2867-
printf(repo_settings_get_shared_repository(the_repository)
2868+
printf(repo_settings_get_shared_repository(repo)
28682869
? _("Initialized empty shared Git repository in %s%s\n")
28692870
: _("Initialized empty Git repository in %s%s\n"),
28702871
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)