init-db, clone: change unnecessary global into passed parameter
Much like the parent commit, this commit was prompted by a desire to move the functions which builtin/init-db.c and builtin/clone.c share out of the former file and into setup.c. A secondary issue that made it difficult was the init_shared_repository global variable; replace it with a simple parameter that is passed to the relevant functions. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
May 16, 2023 at 06:33 UTC
fc8173505703a08bea5c648f1ab286013c3fd730
3 files changed
+9
-6
builtin/clone.c
+2
-1
@@ -930,6 +930,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
930
int submodule_progress;
931
int filter_submodules = 0;
932
int hash_algo;
933
+ const int do_not_override_repo_unix_permissions = -1;
934
935
struct transport_ls_refs_options transport_ls_refs_options =
936
TRANSPORT_LS_REFS_OPTIONS_INIT;
@@ -1097,7 +1098,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1098
}
1099
1100
init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,
1100
- INIT_DB_QUIET);
1101
+ do_not_override_repo_unix_permissions, INIT_DB_QUIET);
1102
1103
if (real_git_dir) {
1104
free((char *)git_dir);
builtin/init-db.c
+5
-4
@@ -31,8 +31,6 @@
31
32
#define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
33
34
-static int init_shared_repository = -1;
35
-
34
static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
35
DIR *dir)
36
{
@@ -199,6 +197,7 @@ static int create_default_files(const char *template_path,
197
const char *initial_branch,
198
const struct repository_format *fmt,
199
int prev_bare_repository,
200
+ int init_shared_repository,
201
int quiet)
202
{
203
struct stat st1;
@@ -418,7 +417,7 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash
417
418
int init_db(const char *git_dir, const char *real_git_dir,
419
const char *template_dir, int hash, const char *initial_branch,
421
- unsigned int flags)
420
+ int init_shared_repository, unsigned int flags)
421
{
422
int reinit;
423
int exist_ok = flags & INIT_DB_EXIST_OK;
@@ -464,6 +463,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
463
reinit = create_default_files(template_dir, original_git_dir,
464
initial_branch, &repo_fmt,
465
prev_bare_repository,
466
+ init_shared_repository,
467
flags & INIT_DB_QUIET);
468
if (reinit && initial_branch)
469
warning(_("re-init: ignored --initial-branch=%s"),
@@ -575,6 +575,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
575
const char *object_format = NULL;
576
const char *initial_branch = NULL;
577
int hash_algo = GIT_HASH_UNKNOWN;
578
+ int init_shared_repository = -1;
579
const struct option init_db_options[] = {
580
OPT_STRING(0, "template", &template_dir, N_("template-directory"),
581
N_("directory from which templates will be used")),
@@ -732,5 +733,5 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
733
734
flags |= INIT_DB_EXIST_OK;
735
return init_db(git_dir, real_git_dir, template_dir, hash_algo,
735
- initial_branch, flags);
736
+ initial_branch, init_shared_repository, flags);
737
}
cache.h
+2
-1
@@ -327,7 +327,8 @@ extern struct index_state the_index;
327
328
int init_db(const char *git_dir, const char *real_git_dir,
329
const char *template_dir, int hash_algo,
330
- const char *initial_branch, unsigned int flags);
330
+ const char *initial_branch, int init_shared_repository,
331
+ unsigned int flags);
332
void initialize_repository_version(int hash_algo, int reinit);
333
334
/* Initialize and use the cache information */