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>
This commit is contained in:

committed by
Junio C Hamano

parent
955ee54d92
commit
d404ac1027
@ -31,7 +31,6 @@
|
|||||||
|
|
||||||
#define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
|
#define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
|
||||||
|
|
||||||
static int init_is_bare_repository = 0;
|
|
||||||
static int init_shared_repository = -1;
|
static int init_shared_repository = -1;
|
||||||
|
|
||||||
static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
|
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 *original_git_dir,
|
||||||
const char *initial_branch,
|
const char *initial_branch,
|
||||||
const struct repository_format *fmt,
|
const struct repository_format *fmt,
|
||||||
|
int prev_bare_repository,
|
||||||
int quiet)
|
int quiet)
|
||||||
{
|
{
|
||||||
struct stat st1;
|
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
|
* TODO: heed core.bare from config file in templates if no
|
||||||
* command-line override given
|
* 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):
|
/* TODO (continued):
|
||||||
*
|
*
|
||||||
* Unfortunately, the line above is equivalent to
|
* 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.
|
* command line option was present.
|
||||||
*
|
*
|
||||||
* To see why, note that before this function, there was this call:
|
* 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:
|
* expanding the right hand side:
|
||||||
* = is_bare_repository_cfg && !get_git_work_tree()
|
* = is_bare_repository_cfg && !get_git_work_tree()
|
||||||
* = is_bare_repository_cfg && !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
|
* calls will return the same result each time. So, what we are
|
||||||
* interested in computing is the right hand side of the line of
|
* interested in computing is the right hand side of the line of
|
||||||
* code just above this comment:
|
* code just above this comment:
|
||||||
* init_is_bare_repository || !work_tree
|
* prev_bare_repository || !work_tree
|
||||||
* = is_bare_repository_cfg && !work_tree || !work_tree
|
* = is_bare_repository_cfg && !work_tree || !work_tree
|
||||||
* = !work_tree
|
* = !work_tree
|
||||||
* because "A && !B || !B == !B" for all boolean values of A & B.
|
* 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;
|
int exist_ok = flags & INIT_DB_EXIST_OK;
|
||||||
char *original_git_dir = real_pathdup(git_dir, 1);
|
char *original_git_dir = real_pathdup(git_dir, 1);
|
||||||
struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
|
struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
|
||||||
|
int prev_bare_repository;
|
||||||
|
|
||||||
if (real_git_dir) {
|
if (real_git_dir) {
|
||||||
struct stat st;
|
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);
|
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.
|
/* Check to see if the repository version is right.
|
||||||
* Note that a newly created repository does not have
|
* 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,
|
reinit = create_default_files(template_dir, original_git_dir,
|
||||||
initial_branch, &repo_fmt,
|
initial_branch, &repo_fmt,
|
||||||
|
prev_bare_repository,
|
||||||
flags & INIT_DB_QUIET);
|
flags & INIT_DB_QUIET);
|
||||||
if (reinit && initial_branch)
|
if (reinit && initial_branch)
|
||||||
warning(_("re-init: ignored --initial-branch=%s"),
|
warning(_("re-init: ignored --initial-branch=%s"),
|
||||||
|
Reference in New Issue
Block a user