All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Michael J Gruber" <git@drmicha.warpmail.net>,
	"Max Kirillov" <max@max630.net>,
	"Jens Lehmann" <Jens.Lehmann@web.de>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 3/5] setup.c: remove special case of core.worktree and core.bare
Date: Wed,  2 Dec 2015 20:13:44 +0100	[thread overview]
Message-ID: <1449083626-20075-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1449083626-20075-1-git-send-email-pclouds@gmail.com>

core.worktree and core.bare, which are treated specially in 31e26eb [1],
are now moved to info/core.worktree and the special treatment
reverted. The test "$GIT_DIR/common overrides core.worktree" in t1501
from 31e26eb verifies that the behavior is still correct after this
change.

A note about core.bare. On the surface it does not make sense for
core.bare to be worktree specific. It's made so in order to "grow" new
worktrees from a bare repo. In these new linked worktrees, core.bare
will be hidden away and worktree-related commands won't complain about
bare repository.

[1] 31e26eb (setup.c: support multi-checkout repo setup - 2014-11-30)

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/config.txt |  4 ++++
 config.c                 |  8 +++++++
 setup.c                  | 62 ++++++++++++++++++++++--------------------------
 3 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 5c6cd4b..09a8b57 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -454,6 +454,8 @@ linkgit:git-init[1] when the repository was created.  By default a
 repository that ends in "/.git" is assumed to be not bare (bare =
 false), while all other repositories are assumed to be bare (bare
 = true).
++
+This variable is per-worktree in multiple working tree setup.
 
 core.worktree::
 	Set the path to the root of the working tree.
@@ -478,6 +480,8 @@ still use "/different/path" as the root of the work tree and can cause
 confusion unless you know what you are doing (e.g. you are creating a
 read-only snapshot of the same index to a location different from the
 repository's usual working tree).
++
+This variable is per-worktree in multiple working tree setup.
 
 core.logAllRefUpdates::
 	Enable the reflog. Updates to a ref <ref> is logged to the file
diff --git a/config.c b/config.c
index 75c45e1..54a6219 100644
--- a/config.c
+++ b/config.c
@@ -91,6 +91,11 @@ static long config_buf_ftell(struct config_source *conf)
 	return conf->u.buf.pos;
 }
 
+static const char* default_config_worktree[] = {
+	"core/bare",
+	"core/worktree"
+};
+
 static void load_info_config_worktree(void)
 {
 	struct exclude_list *el = &config_local;
@@ -101,6 +106,9 @@ static void load_info_config_worktree(void)
 
 	clear_exclude_list(el);
 
+	for (i = 0; i < ARRAY_SIZE(default_config_worktree); i++)
+		add_exclude(default_config_worktree[i], "", 0, el, 0);
+
 	if (strbuf_read_file(&sb,
 			     git_path("info/config.worktree"),
 			     128) <= 0) {
diff --git a/setup.c b/setup.c
index 0047d40..c088d45 100644
--- a/setup.c
+++ b/setup.c
@@ -355,43 +355,20 @@ void setup_work_tree(void)
 	initialized = 1;
 }
 
-static int check_repo_format(const char *var, const char *value, void *cb)
-{
-	const char *ext;
-
-	if (strcmp(var, "core.repositoryformatversion") == 0)
-		repository_format_version = git_config_int(var, value);
-	else if (strcmp(var, "core.sharedrepository") == 0)
-		shared_repository = git_config_perm(var, value);
-	else if (skip_prefix(var, "extensions.", &ext)) {
-		/*
-		 * record any known extensions here; otherwise,
-		 * we fall through to recording it as unknown, and
-		 * check_repository_format will complain
-		 */
-		if (!strcmp(ext, "noop"))
-			;
-		else if (!strcmp(ext, "preciousobjects"))
-			repository_format_precious_objects = git_config_bool(var, value);
-		else
-			string_list_append(&unknown_extensions, ext);
-	}
-	return 0;
-}
-
 static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
 {
 	struct strbuf sb = STRBUF_INIT;
+	struct strbuf sb2 = STRBUF_INIT;
 	const char *repo_config;
-	config_fn_t fn;
+	const char *worktree_config = NULL;
 	int ret = 0;
 
 	string_list_clear(&unknown_extensions, 0);
 
-	if (get_common_dir(&sb, gitdir))
-		fn = check_repo_format;
-	else
-		fn = check_repository_format_version;
+	if (get_common_dir(&sb, gitdir)) {
+		strbuf_addf(&sb2, "%s/config.worktree", gitdir);
+		worktree_config = sb2.buf;
+	}
 	strbuf_addstr(&sb, "/config");
 	repo_config = sb.buf;
 
@@ -404,7 +381,8 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
 	 * Use a gentler version of git_config() to check if this repo
 	 * is a good one.
 	 */
-	git_config_early(fn, NULL, repo_config, NULL);
+	git_config_early(check_repository_format_version, NULL,
+			 repo_config, worktree_config);
 	if (GIT_REPO_VERSION_READ < repository_format_version) {
 		if (!nongit_ok)
 			die ("Expected git repo version <= %d, found %d",
@@ -431,6 +409,7 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
 	}
 
 	strbuf_release(&sb);
+	strbuf_release(&sb2);
 	return ret;
 }
 
@@ -963,10 +942,25 @@ int git_config_perm(const char *var, const char *value)
 
 int check_repository_format_version(const char *var, const char *value, void *cb)
 {
-	int ret = check_repo_format(var, value, cb);
-	if (ret)
-		return ret;
-	if (strcmp(var, "core.bare") == 0) {
+	const char *ext;
+
+	if (strcmp(var, "core.repositoryformatversion") == 0)
+		repository_format_version = git_config_int(var, value);
+	else if (strcmp(var, "core.sharedrepository") == 0)
+		shared_repository = git_config_perm(var, value);
+	else if (skip_prefix(var, "extensions.", &ext)) {
+		/*
+		 * record any known extensions here; otherwise,
+		 * we fall through to recording it as unknown, and
+		 * check_repository_format will complain
+		 */
+		if (!strcmp(ext, "noop"))
+			;
+		else if (!strcmp(ext, "preciousobjects"))
+			repository_format_precious_objects = git_config_bool(var, value);
+		else
+			string_list_append(&unknown_extensions, ext);
+	} else if (strcmp(var, "core.bare") == 0) {
 		is_bare_repository_cfg = git_config_bool(var, value);
 		if (is_bare_repository_cfg == 1)
 			inside_work_tree = -1;
-- 
2.2.0.513.g477eb31

  parent reply	other threads:[~2015-12-02 19:14 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-02 19:13 [PATCH 0/5] Split .git/config in multiple worktree setup Nguyễn Thái Ngọc Duy
2015-12-02 19:13 ` [PATCH 1/5] dir.c: clean the entire struct in clear_exclude_list() Nguyễn Thái Ngọc Duy
2015-12-02 19:13 ` [PATCH 2/5] config.c: move worktree-specific variables to .git/worktrees/ Nguyễn Thái Ngọc Duy
2015-12-06  7:47   ` Eric Sunshine
2015-12-06 10:22     ` Duy Nguyen
2015-12-02 19:13 ` Nguyễn Thái Ngọc Duy [this message]
2015-12-02 19:13 ` [PATCH 4/5] worktree: make core.sparseCheckout and core.ignoreStat per-worktree Nguyễn Thái Ngọc Duy
2015-12-02 19:13 ` [PATCH 5/5] git-worktree.txt: mention about the config file split Nguyễn Thái Ngọc Duy
2015-12-06  8:02   ` Eric Sunshine
2015-12-03  6:15 ` [PATCH 0/5] Split .git/config in multiple worktree setup Max Kirillov
2015-12-03  8:07   ` Duy Nguyen
2015-12-03 19:52     ` Junio C Hamano
2015-12-03 21:00       ` Max Kirillov
2015-12-03 20:53     ` Max Kirillov
2015-12-04 15:57       ` Duy Nguyen
2015-12-27  3:14 ` [PATCH v2 0/6] " Nguyễn Thái Ngọc Duy
2015-12-27  3:14   ` [PATCH v2 1/6] Define new repo extension to manage multiple worktree behaviors Nguyễn Thái Ngọc Duy
2015-12-27  3:14   ` [PATCH v2 2/6] config.c: move worktree-specific variables to .git/worktrees/ Nguyễn Thái Ngọc Duy
2015-12-27  3:14   ` [PATCH v2 3/6] setup.c: remove special case of core.worktree and core.bare Nguyễn Thái Ngọc Duy
2015-12-27  3:14   ` [PATCH v2 4/6] worktree: make core.sparseCheckout and core.ignoreStat per-worktree Nguyễn Thái Ngọc Duy
2015-12-27  3:14   ` [PATCH v2 5/6] config.c: allow to un-share certain config in multi-worktree setup Nguyễn Thái Ngọc Duy
2015-12-27  3:14   ` [PATCH v2 6/6] worktree: bump worktree version to 1 on "worktree add" Nguyễn Thái Ngọc Duy
2016-01-11 22:43   ` [PATCH v2 0/6] Split .git/config in multiple worktree setup Max Kirillov
2016-01-26 11:44   ` [PATCH v3 " Nguyễn Thái Ngọc Duy
2016-01-26 11:44     ` [PATCH v3 1/6] worktree: new repo extension to manage worktree behaviors Nguyễn Thái Ngọc Duy
2016-01-27 22:12       ` Junio C Hamano
2016-01-28 12:11         ` Duy Nguyen
2016-01-30 14:20         ` Max Kirillov
2016-01-31 16:42           ` Junio C Hamano
2016-02-01  2:41             ` Stefan Monnier
2016-02-01  2:47               ` Stefan Monnier
2016-02-01  5:23               ` Duy Nguyen
2016-02-01 18:19                 ` Junio C Hamano
2016-02-04 18:12                 ` git worktree (was: [PATCH v3 1/6] worktree: new repo extension to manage worktree behaviors) Stefan Monnier
2016-02-01 18:39         ` [PATCH v3 1/6] worktree: new repo extension to manage worktree behaviors Dennis Kaarsemaker
2016-01-30 13:59       ` Max Kirillov
2016-01-26 11:44     ` [PATCH v3 2/6] path.c: new (identical) list for worktree v1 Nguyễn Thái Ngọc Duy
2016-01-27 22:18       ` Junio C Hamano
2016-01-30 14:45       ` Max Kirillov
2016-01-26 11:44     ` [PATCH v3 3/6] worktree: share .git/common in v1 Nguyễn Thái Ngọc Duy
2016-01-26 11:44     ` [PATCH v3 4/6] worktree: new config file hierarchy Nguyễn Thái Ngọc Duy
2016-01-27 22:22       ` Junio C Hamano
2016-01-28 12:03         ` Duy Nguyen
2016-01-28 18:45           ` Junio C Hamano
2016-02-01  5:09             ` Duy Nguyen
2016-01-26 11:44     ` [PATCH v3 5/6] config: select .git/common/config with --repo Nguyễn Thái Ngọc Duy
2016-01-30 22:10       ` Max Kirillov
2016-02-01  5:15         ` Duy Nguyen
2016-01-26 11:44     ` [PATCH v3 6/6] worktree add: switch to worktree version 1 Nguyễn Thái Ngọc Duy
2016-02-01  5:33       ` Max Kirillov
2016-02-01  6:05         ` Duy Nguyen
2016-02-02  5:35           ` Max Kirillov
2016-01-27 22:23     ` [PATCH v3 0/6] Split .git/config in multiple worktree setup 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=1449083626-20075-4-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@drmicha.warpmail.net \
    --cc=git@vger.kernel.org \
    --cc=max@max630.net \
    /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.