diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2016-09-25 06:14:37 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-09-26 02:32:35 +0300 |
commit | 33158701e2cac4244a236cd18d9d336f66e535f3 (patch) | |
tree | fbb5ae9663797e8c3b74afc59801d65e053753f6 | |
parent | fe9aa0b22e18e5cd1ae4a9323edad0d3c8177c90 (diff) |
init: call set_git_dir_init() from within init_db()
The next commit requires that set_git_dir_init() must be called before
init_db(). Let's make sure nobody can do otherwise.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | builtin/clone.c | 15 | ||||
-rw-r--r-- | builtin/init-db.c | 18 | ||||
-rw-r--r-- | cache.h | 5 |
3 files changed, 21 insertions, 17 deletions
diff --git a/builtin/clone.c b/builtin/clone.c index 661639255c..29b18329ee 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -928,23 +928,22 @@ int cmd_clone(int argc, const char **argv, const char *prefix) set_git_work_tree(work_tree); } - junk_git_dir = git_dir; + junk_git_dir = real_git_dir ? real_git_dir : git_dir; if (safe_create_leading_directories_const(git_dir) < 0) die(_("could not create leading directories of '%s'"), git_dir); - set_git_dir_init(git_dir, real_git_dir, 0); - if (real_git_dir) { - git_dir = real_git_dir; - junk_git_dir = real_git_dir; - } - if (0 <= option_verbosity) { if (option_bare) fprintf(stderr, _("Cloning into bare repository '%s'...\n"), dir); else fprintf(stderr, _("Cloning into '%s'...\n"), dir); } - init_db(option_template, INIT_DB_QUIET); + + init_db(git_dir, real_git_dir, option_template, INIT_DB_QUIET); + + if (real_git_dir) + git_dir = real_git_dir; + write_config(&option_config); git_config(git_default_config, NULL); diff --git a/builtin/init-db.c b/builtin/init-db.c index d5d7558c8a..5cb05d9bd9 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -311,8 +311,9 @@ static void create_object_directory(void) strbuf_release(&path); } -int set_git_dir_init(const char *git_dir, const char *real_git_dir, - int exist_ok) +static int set_git_dir_init(const char *git_dir, + const char *real_git_dir, + int exist_ok) { if (real_git_dir) { struct stat st; @@ -359,10 +360,14 @@ static void separate_git_dir(const char *git_dir) write_file(git_link, "gitdir: %s", git_dir); } -int init_db(const char *template_dir, unsigned int flags) +int init_db(const char *git_dir, const char *real_git_dir, + const char *template_dir, unsigned int flags) { int reinit; - const char *git_dir = get_git_dir(); + + set_git_dir_init(git_dir, real_git_dir, flags & INIT_DB_EXIST_OK); + + git_dir = get_git_dir(); if (git_link) separate_git_dir(git_dir); @@ -582,7 +587,6 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) set_git_work_tree(work_tree); } - set_git_dir_init(git_dir, real_git_dir, 1); - - return init_db(template_dir, flags); + flags |= INIT_DB_EXIST_OK; + return init_db(git_dir, real_git_dir, template_dir, flags); } @@ -525,9 +525,10 @@ extern void verify_non_filename(const char *prefix, const char *name); extern int path_inside_repo(const char *prefix, const char *path); #define INIT_DB_QUIET 0x0001 +#define INIT_DB_EXIST_OK 0x0002 -extern int set_git_dir_init(const char *git_dir, const char *real_git_dir, int); -extern int init_db(const char *template_dir, unsigned int flags); +extern int init_db(const char *git_dir, const char *real_git_dir, + const char *template_dir, unsigned int flags); extern void sanitize_stdfds(void); extern int daemonize(void); |