Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2023-05-16 09:33:42 +0300
committerJunio C Hamano <gitster@pobox.com>2023-06-21 21:14:34 +0300
commitc2f76965d0202a894c9491e0647b7834b58cd168 (patch)
tree09c5d3e31213d73b66056857f13b0c49f3c31fec
parent0f7443bdc7284ad36e5d0cd8b2526e2123b8aa4f (diff)
init-db: remove unnecessary global variable
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. One issue that made it difficult was the init_is_bare_repository global variable. init_is_bare_repository's sole use in life it to cache a value in init_db(), and then be used in create_default_files(). This is a bit odd since init_db() directly calls create_default_files(), and is the only caller of that function. Convert the global to a simple function parameter instead. (Of course, this doesn't fix the fact that this value is then ignored by create_default_files(), as noted in a big TODO comment in that function, but it at least includes no behavioral change other than getting rid of a very questionable global variable.) Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/init-db.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 87a7021c3c..32ab0a13e0 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -31,7 +31,6 @@
#define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
-static int init_is_bare_repository = 0;
static int init_shared_repository = -1;
static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
@@ -199,6 +198,7 @@ static int create_default_files(const char *template_path,
const char *original_git_dir,
const char *initial_branch,
const struct repository_format *fmt,
+ int prev_bare_repository,
int quiet)
{
struct stat st1;
@@ -237,7 +237,7 @@ static int create_default_files(const char *template_path,
* TODO: heed core.bare from config file in templates if no
* command-line override given
*/
- is_bare_repository_cfg = init_is_bare_repository || !work_tree;
+ is_bare_repository_cfg = prev_bare_repository || !work_tree;
/* TODO (continued):
*
* Unfortunately, the line above is equivalent to
@@ -246,7 +246,7 @@ static int create_default_files(const char *template_path,
* command line option was present.
*
* To see why, note that before this function, there was this call:
- * init_is_bare_repository = is_bare_repository()
+ * prev_bare_repository = is_bare_repository()
* expanding the right hand side:
* = is_bare_repository_cfg && !get_git_work_tree()
* = is_bare_repository_cfg && !work_tree
@@ -256,7 +256,7 @@ static int create_default_files(const char *template_path,
* calls will return the same result each time. So, what we are
* interested in computing is the right hand side of the line of
* code just above this comment:
- * init_is_bare_repository || !work_tree
+ * prev_bare_repository || !work_tree
* = is_bare_repository_cfg && !work_tree || !work_tree
* = !work_tree
* because "A && !B || !B == !B" for all boolean values of A & B.
@@ -424,6 +424,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
int exist_ok = flags & INIT_DB_EXIST_OK;
char *original_git_dir = real_pathdup(git_dir, 1);
struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
+ int prev_bare_repository;
if (real_git_dir) {
struct stat st;
@@ -449,7 +450,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
safe_create_dir(git_dir, 0);
- init_is_bare_repository = is_bare_repository();
+ prev_bare_repository = is_bare_repository();
/* Check to see if the repository version is right.
* Note that a newly created repository does not have
@@ -462,6 +463,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
reinit = create_default_files(template_dir, original_git_dir,
initial_branch, &repo_fmt,
+ prev_bare_repository,
flags & INIT_DB_QUIET);
if (reinit && initial_branch)
warning(_("re-init: ignored --initial-branch=%s"),