[PATCH v2 3/6] setup.c: remove special case of core.worktree and core.bare

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



core.worktree and core.bare, which are treated specially in 31e26eb [1],
are now defined per-worktree with repo extension worktree=1 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@xxxxxxxxx>
---
 Documentation/git-worktree.txt                 |  1 +
 Documentation/technical/repository-version.txt |  3 ++
 config.c                                       |  2 +
 setup.c                                        | 68 ++++++++++++--------------
 4 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
index bc0734c..087b35e 100644
--- a/Documentation/git-worktree.txt
+++ b/Documentation/git-worktree.txt
@@ -157,6 +157,7 @@ $GIT_COMMON_DIR/worktrees/X/config. Even though per-working tree
 variables for the main working tree are in the default config place,
 they are invisible from all linked working trees. The following
 configuration variables are per working directory:
+core.bare, core.worktree.
 
 LIST OUTPUT FORMAT
 ------------------
diff --git a/Documentation/technical/repository-version.txt b/Documentation/technical/repository-version.txt
index c680528..fc2cdb9 100644
--- a/Documentation/technical/repository-version.txt
+++ b/Documentation/technical/repository-version.txt
@@ -92,3 +92,6 @@ objects in the repository MUST NOT be deleted (e.g., by `git-prune` or
 
 Define behavior in multiple worktree setup. The value specifies the
 version. Default version is zero.
+
+In version 1, the following config variables are per-worktree:
+core.bare, core.worktree.
diff --git a/config.c b/config.c
index 7d94f21..c2ea91b 100644
--- a/config.c
+++ b/config.c
@@ -48,6 +48,8 @@ static struct config_source *cf;
 static int zlib_compression_seen;
 
 static struct config_pattern worktree_v1[] = {
+	{ 0, 0, "core.bare" },
+	{ 0, 0, "core.worktree" },
 	{ 0, 0, NULL }
 };
 
diff --git a/setup.c b/setup.c
index 9196945..b49d61e 100644
--- a/setup.c
+++ b/setup.c
@@ -355,46 +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 if (!strcmp(ext, "worktree"))
-			repository_format_worktree_version =
-				git_config_ulong(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;
 
@@ -407,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",
@@ -434,6 +409,7 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
 	}
 
 	strbuf_release(&sb);
+	strbuf_release(&sb2);
 	return ret;
 }
 
@@ -966,10 +942,28 @@ 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 if (!strcmp(ext, "worktree"))
+			repository_format_worktree_version =
+				git_config_ulong(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.3.0.rc1.137.g477eb31

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]