From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
git@drmicha.warpmail.net, max.nordlund@sqore.com,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 4/3] init: combine set_git_dir_init() and init_db() into one
Date: Fri, 23 Sep 2016 18:12:06 +0700 [thread overview]
Message-ID: <20160923111206.8596-1-pclouds@gmail.com> (raw)
In-Reply-To: <xmqqbmzf6e0r.fsf@gitster.mtv.corp.google.com>
Commit "init: do not set core.worktree more often than necessary" adds a
subtle dependency between set_git_dir_init() and init_db(). The former
_must_ be called before init_db() so that original_git_dir can be set
properly. If something else, like enter_repo() or setup_git_directory(),
is used instead, the trick in that commit breaks down.
To eliminate the possibility that init_db() in future may be called
without set_git_dir_init(), init_db() now calls that function internally
(and does not allow anybody else to use it).
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
I think a separate commit for this is better than combining back to
2/3 so we can explain the problem properly (without making 2/3 commit
message even longer)
Not sure if you want to s/contains/contain/ in 2/3 by yourself or I
should resend the whole series. Let me know.
builtin/clone.c | 15 +++++++--------
builtin/init-db.c | 18 +++++++++++-------
cache.h | 5 +++--
3 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index 6616392..29b1832 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 d70fc45..ee7942f 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -312,8 +312,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)
{
original_git_dir = xstrdup(real_path(git_dir));
@@ -362,10 +363,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);
@@ -585,7 +590,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);
}
diff --git a/cache.h b/cache.h
index b2d77f3..7fc875f 100644
--- a/cache.h
+++ b/cache.h
@@ -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);
--
2.8.2.524.g6ff3d78
next prev parent reply other threads:[~2016-09-23 11:13 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-23 12:35 Bug with git worktrees and git init Max Nordlund
2016-08-23 15:21 ` Michael J Gruber
2016-08-24 9:35 ` Duy Nguyen
2016-09-08 13:47 ` [PATCH 0/3] Fix git-init in linked worktrees Nguyễn Thái Ngọc Duy
2016-09-08 13:47 ` [PATCH 1/3] init: correct re-initialization from a linked worktree Nguyễn Thái Ngọc Duy
2016-09-08 19:37 ` Junio C Hamano
2016-09-09 10:36 ` Duy Nguyen
2016-09-08 13:47 ` [PATCH 2/3] t0001: work around the bug that reads config file before repo setup Nguyễn Thái Ngọc Duy
2016-09-08 19:44 ` Junio C Hamano
2016-09-08 20:02 ` Jeff King
2016-09-09 10:32 ` Duy Nguyen
2016-09-09 11:22 ` Jeff King
2016-09-09 17:45 ` Jacob Keller
2016-09-08 13:47 ` [PATCH 3/3] init: do not set core.worktree more often than necessary Nguyễn Thái Ngọc Duy
2016-09-08 19:54 ` Junio C Hamano
2016-09-09 10:33 ` Duy Nguyen
2016-09-21 11:29 ` [PATCH v2 0/3] Fix git-init in linked worktrees Nguyễn Thái Ngọc Duy
2016-09-21 11:29 ` [PATCH v2 1/3] init: correct re-initialization from a linked worktree Nguyễn Thái Ngọc Duy
2016-09-21 11:29 ` [PATCH v2 2/3] init: do not set core.worktree more often than necessary Nguyễn Thái Ngọc Duy
2016-09-21 18:44 ` Junio C Hamano
2016-09-22 10:06 ` Duy Nguyen
2016-09-22 17:27 ` Junio C Hamano
2016-09-23 11:12 ` Nguyễn Thái Ngọc Duy [this message]
2016-09-23 15:18 ` [PATCH v2 4/3] init: combine set_git_dir_init() and init_db() into one Junio C Hamano
2016-09-23 22:53 ` Junio C Hamano
2016-09-24 18:55 ` Junio C Hamano
2016-09-25 3:13 ` Duy Nguyen
2016-09-25 3:14 ` [PATCH v3 1/5] init: correct re-initialization from a linked worktree Nguyễn Thái Ngọc Duy
2016-09-25 3:14 ` [PATCH v3 2/5] init: call set_git_dir_init() from within init_db() Nguyễn Thái Ngọc Duy
2016-09-25 3:14 ` [PATCH v3 3/5] init: kill set_git_dir_init() Nguyễn Thái Ngọc Duy
2016-09-25 3:14 ` [PATCH v3 4/5] init: do not set unnecessary core.worktree Nguyễn Thái Ngọc Duy
2016-09-25 3:14 ` [PATCH v3 5/5] init: kill git_link variable Nguyễn Thái Ngọc Duy
2016-09-21 11:29 ` [PATCH v2 3/3] init: reuse original_git_dir in set_git_dir_init() Nguyễn Thái Ngọc Duy
2016-09-21 18:18 ` [PATCH v2 0/3] Fix git-init in linked worktrees Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160923111206.8596-1-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=max.nordlund@sqore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.