From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Jonathan Niedier <jrnieder@gmail.com>,
Sverre Rabbelier <srabbelier@gmail.com>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 5/9] setup: limit get_git_work_tree()'s to explicit setup case only
Date: Mon, 1 Nov 2010 13:26:30 +0700 [thread overview]
Message-ID: <1288592794-24221-5-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <AANLkTim-uW4Esk1bkPzNNGRb8svZoNwCUvXF3Fqb4QmR@mail.gmail.com>
get_git_work_tree() takes input as core.worktree, core.bare,
GIT_WORK_TREE and decides correct worktree setting.
Unfortunately it does not do its job well. core.worktree and
GIT_WORK_TREE should only be taken into account, if GIT_DIR is set
(which is handled by setup_explicit_git_dir). For other setup cases,
only core.bare matters.
Add a temporary variable setup_explicit to adjust get_git_work_tree()
behavior as such. This variable will be gone once setup_* rework is
done.
Also remove is_bare_repository_cfg check in set_git_work_tree() to
ease the rework. We are going to check for core.bare and core.worktree
early before setting worktree. For example, if core.bare is true, no
need to set worktree.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
I isolate setup_bare_git_dir and setup_discovered_git_dir from
get_git_work_tree() with this patch. setup_explicit_git_dir will
remove "startup_info->setup_explicit = 1", which means
get_git_work_tree() can no longer affect setup_* even if all the
logic is there.
builtin/init-db.c | 1 +
cache.h | 1 +
environment.c | 10 ++++++-
setup.c | 10 ++++++-
t/t1510-repo-setup.sh | 66 ++++++++++++++++++++++++------------------------
5 files changed, 51 insertions(+), 37 deletions(-)
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 9d4886c..ea06478 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -496,6 +496,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
if (is_bare_repository_cfg < 0)
is_bare_repository_cfg = guess_repository_type(git_dir);
+ startup_info->setup_explicit = 1;
if (!is_bare_repository_cfg) {
if (git_dir) {
const char *git_dir_parent = strrchr(git_dir, '/');
diff --git a/cache.h b/cache.h
index 123dd4b..b2cdda7 100644
--- a/cache.h
+++ b/cache.h
@@ -1119,6 +1119,7 @@ const char *split_cmdline_strerror(int cmdline_errno);
/* git.c */
struct startup_info {
int have_repository;
+ int setup_explicit;
};
extern struct startup_info *startup_info;
diff --git a/environment.c b/environment.c
index de5581f..d811049 100644
--- a/environment.c
+++ b/environment.c
@@ -137,8 +137,6 @@ static int git_work_tree_initialized;
*/
void set_git_work_tree(const char *new_work_tree)
{
- if (is_bare_repository_cfg >= 0)
- die("cannot set work tree after initialization");
git_work_tree_initialized = 1;
free(work_tree);
work_tree = xstrdup(make_absolute_path(new_work_tree));
@@ -147,6 +145,14 @@ void set_git_work_tree(const char *new_work_tree)
const char *get_git_work_tree(void)
{
+ if (startup_info && !startup_info->setup_explicit) {
+ if (is_bare_repository_cfg == 1)
+ return NULL;
+ if (work_tree)
+ is_bare_repository_cfg = 0;
+ return work_tree;
+ }
+
if (!git_work_tree_initialized) {
work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
/* core.bare = true overrides implicit and config work tree */
diff --git a/setup.c b/setup.c
index 49a1a25..c7d7198 100644
--- a/setup.c
+++ b/setup.c
@@ -331,6 +331,8 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
static char buffer[1024 + 1];
const char *retval;
+ if (startup_info)
+ startup_info->setup_explicit = 1;
if (PATH_MAX - 40 < strlen(gitdirenv))
die("'$%s' too big", GIT_DIR_ENVIRONMENT);
if (!is_git_directory(gitdirenv)) {
@@ -382,12 +384,15 @@ static const char *setup_discovered_git_dir(const char *work_tree_env,
char *cwd, int *nongit_ok)
{
int root_len;
+ char *work_tree;
inside_git_dir = 0;
if (!work_tree_env)
inside_work_tree = 1;
root_len = offset_1st_component(cwd);
- git_work_tree_cfg = xstrndup(cwd, offset > root_len ? offset : root_len);
+ work_tree = xstrndup(cwd, offset > root_len ? offset : root_len);
+ set_git_work_tree(work_tree);
+ free(work_tree);
if (check_repository_format_gently(gitdir, nongit_ok))
return NULL;
if (offset == len)
@@ -627,7 +632,8 @@ const char *setup_git_directory(void)
const char *retval = setup_git_directory_gently(NULL);
/* If the work tree is not the default one, recompute prefix */
- if (inside_work_tree < 0) {
+ if ((!startup_info || startup_info->setup_explicit) &&
+ inside_work_tree < 0) {
static char buffer[PATH_MAX + 1];
char *rel;
if (retval && chdir(retval))
diff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh
index fe65a02..629ba34 100755
--- a/t/t1510-repo-setup.sh
+++ b/t/t1510-repo-setup.sh
@@ -129,7 +129,7 @@ test_expect_success '#1: setup' '
cd ..
'
-test_expect_failure '#1: at root' '
+test_expect_success '#1: at root' '
cat >1/expected <<EOF &&
setup: git_dir: .git
setup: worktree: $TRASH_DIRECTORY/1
@@ -139,7 +139,7 @@ EOF
test_repo 1
'
-test_expect_failure '#1: in subdir' '
+test_expect_success '#1: in subdir' '
cat >1/sub/expected <<EOF &&
setup: git_dir: .git
setup: worktree: $TRASH_DIRECTORY/1
@@ -509,7 +509,7 @@ test_expect_success '#4: setup' '
cd ..
'
-test_expect_failure '#4: at root' '
+test_expect_success '#4: at root' '
cat >4/expected <<EOF &&
setup: git_dir: .git
setup: worktree: $TRASH_DIRECTORY/4
@@ -519,7 +519,7 @@ EOF
test_repo 4
'
-test_expect_failure '#4: in subdir' '
+test_expect_success '#4: in subdir' '
cat >4/sub/expected <<EOF &&
setup: git_dir: .git
setup: worktree: $TRASH_DIRECTORY/4
@@ -556,7 +556,7 @@ test_expect_success '#5: setup' '
cd ..
'
-test_expect_failure '#5: at root' '
+test_expect_success '#5: at root' '
cat >5/expected <<EOF &&
setup: git_dir: .git
setup: worktree: $TRASH_DIRECTORY/5
@@ -566,7 +566,7 @@ EOF
test_repo 5
'
-test_expect_failure '#5: in subdir' '
+test_expect_success '#5: in subdir' '
cat >5/sub/expected <<EOF &&
setup: git_dir: .git
setup: worktree: $TRASH_DIRECTORY/5
@@ -1207,7 +1207,7 @@ test_expect_success '#9: setup' '
cd ..
'
-test_expect_failure '#9: at root' '
+test_expect_success '#9: at root' '
cat >9/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/9.git
setup: worktree: $TRASH_DIRECTORY/9
@@ -1217,7 +1217,7 @@ EOF
GIT_WORK_TREE=non-existent test_repo 9
'
-test_expect_failure '#9: in subdir' '
+test_expect_success '#9: in subdir' '
cat >9/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/9.git
setup: worktree: $TRASH_DIRECTORY/9
@@ -1590,7 +1590,7 @@ test_expect_success '#12: setup' '
cd ..
'
-test_expect_failure '#12: at root' '
+test_expect_success '#12: at root' '
cat >12/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/12.git
setup: worktree: $TRASH_DIRECTORY/12
@@ -1600,7 +1600,7 @@ EOF
test_repo 12
'
-test_expect_failure '#12: in subdir' '
+test_expect_success '#12: in subdir' '
cat >12/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/12.git
setup: worktree: $TRASH_DIRECTORY/12
@@ -1639,7 +1639,7 @@ test_expect_success '#13: setup' '
cd ..
'
-test_expect_failure '#13: at root' '
+test_expect_success '#13: at root' '
cat >13/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/13.git
setup: worktree: $TRASH_DIRECTORY/13
@@ -1649,7 +1649,7 @@ EOF
test_repo 13
'
-test_expect_failure '#13: in subdir' '
+test_expect_success '#13: in subdir' '
cat >13/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/13.git
setup: worktree: $TRASH_DIRECTORY/13
@@ -2380,7 +2380,7 @@ test_expect_success '#17.1: setup' '
cd ..
'
-test_expect_failure '#17.1: at .git' '
+test_expect_success '#17.1: at .git' '
cat >17/.git/expected <<EOF &&
setup: git_dir: .
setup: worktree: (null)
@@ -2390,7 +2390,7 @@ EOF
test_repo 17/.git
'
-test_expect_failure '#17.1: in .git/wt' '
+test_expect_success '#17.1: in .git/wt' '
cat >17/.git/wt/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/17/.git
setup: worktree: (null)
@@ -2400,7 +2400,7 @@ EOF
test_repo 17/.git/wt
'
-test_expect_failure '#17.1: in .git/wt/sub' '
+test_expect_success '#17.1: in .git/wt/sub' '
cat >17/.git/wt/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/17/.git
setup: worktree: (null)
@@ -2431,7 +2431,7 @@ test_expect_success '#17.2: setup' '
git config --file="$TRASH_DIRECTORY/17/.git/config" core.bare true
'
-test_expect_failure '#17.2: at .git' '
+test_expect_success '#17.2: at .git' '
cat >17/.git/expected <<EOF &&
setup: git_dir: .
setup: worktree: (null)
@@ -2441,7 +2441,7 @@ EOF
test_repo 17/.git
'
-test_expect_failure '#17.2: in .git/wt' '
+test_expect_success '#17.2: in .git/wt' '
cat >17/.git/wt/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/17/.git
setup: worktree: (null)
@@ -2451,7 +2451,7 @@ EOF
test_repo 17/.git/wt
'
-test_expect_failure '#17.2: in .git/wt/sub' '
+test_expect_success '#17.2: in .git/wt/sub' '
cat >17/.git/wt/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/17/.git
setup: worktree: (null)
@@ -2461,7 +2461,7 @@ EOF
test_repo 17/.git/wt/sub
'
-test_expect_failure '#17.2: at root' '
+test_expect_success '#17.2: at root' '
cat >17/expected <<EOF &&
setup: git_dir: .git
setup: worktree: (null)
@@ -2845,7 +2845,7 @@ test_expect_success '#20.1: setup' '
cd ..
'
-test_expect_failure '#20.1: at .git' '
+test_expect_success '#20.1: at .git' '
cat >20/.git/expected <<EOF &&
setup: git_dir: .
setup: worktree: (null)
@@ -2855,7 +2855,7 @@ EOF
test_repo 20/.git
'
-test_expect_failure '#20.1: in .git/wt' '
+test_expect_success '#20.1: in .git/wt' '
cat >20/.git/wt/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/20/.git
setup: worktree: (null)
@@ -2865,7 +2865,7 @@ EOF
test_repo 20/.git/wt
'
-test_expect_failure '#20.1: in .git/wt/sub' '
+test_expect_success '#20.1: in .git/wt/sub' '
cat >20/.git/wt/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/20/.git
setup: worktree: (null)
@@ -2974,7 +2974,7 @@ test_expect_success '#21.1: setup' '
cd ..
'
-test_expect_failure '#21.1: at .git' '
+test_expect_success '#21.1: at .git' '
cat >21/.git/expected <<EOF &&
setup: git_dir: .
setup: worktree: (null)
@@ -2984,7 +2984,7 @@ EOF
test_repo 21/.git
'
-test_expect_failure '#21.1: in .git/wt' '
+test_expect_success '#21.1: in .git/wt' '
cat >21/.git/wt/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/21/.git
setup: worktree: (null)
@@ -2994,7 +2994,7 @@ EOF
test_repo 21/.git/wt
'
-test_expect_failure '#21.1: in .git/wt/sub' '
+test_expect_success '#21.1: in .git/wt/sub' '
cat >21/.git/wt/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/21/.git
setup: worktree: (null)
@@ -3025,7 +3025,7 @@ test_expect_success '#21.2: setup' '
git config --file="$TRASH_DIRECTORY/21/.git/config" core.bare true
'
-test_expect_failure '#21.2: at .git' '
+test_expect_success '#21.2: at .git' '
cat >21/.git/expected <<EOF &&
setup: git_dir: .
setup: worktree: (null)
@@ -3035,7 +3035,7 @@ EOF
test_repo 21/.git
'
-test_expect_failure '#21.2: in .git/wt' '
+test_expect_success '#21.2: in .git/wt' '
cat >21/.git/wt/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/21/.git
setup: worktree: (null)
@@ -3045,7 +3045,7 @@ EOF
test_repo 21/.git/wt
'
-test_expect_failure '#21.2: in .git/wt/sub' '
+test_expect_success '#21.2: in .git/wt/sub' '
cat >21/.git/wt/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/21/.git
setup: worktree: (null)
@@ -3055,7 +3055,7 @@ EOF
test_repo 21/.git/wt/sub
'
-test_expect_failure '#21.2: at root' '
+test_expect_success '#21.2: at root' '
cat >21/expected <<EOF &&
setup: git_dir: .git
setup: worktree: (null)
@@ -3703,7 +3703,7 @@ test_expect_success '#24: setup' '
cd ..
'
-test_expect_success '#24: at root' '
+test_expect_failure '#24: at root' '
cat >24/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/24.git
setup: worktree: (null)
@@ -3713,7 +3713,7 @@ EOF
test_repo 24
'
-test_expect_success '#24: in subdir' '
+test_expect_failure '#24: in subdir' '
cat >24/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/24.git
setup: worktree: (null)
@@ -4137,7 +4137,7 @@ test_expect_success '#28: setup' '
cd ..
'
-test_expect_success '#28: at root' '
+test_expect_failure '#28: at root' '
cat >28/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/28.git
setup: worktree: (null)
@@ -4147,7 +4147,7 @@ EOF
test_repo 28
'
-test_expect_success '#28: in subdir' '
+test_expect_failure '#28: in subdir' '
cat >28/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/28.git
setup: worktree: (null)
--
1.7.3.2.210.g045198
next prev parent reply other threads:[~2010-11-01 6:27 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-29 6:48 [PATCH 00/42] repo setup test cases and fixes Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 01/42] builtins: print setup info if repo is found Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 02/42] Add t1510 and basic rules that run repo setup Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 03/42] t1510: setup case #0 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 04/42] t1510: setup case #1 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 05/42] t1510: setup case #2 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 06/42] t1510: setup case #3 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 07/42] t1510: setup case #4 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 08/42] t1510: setup case #5 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 09/42] t1510: setup case #6 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 10/42] t1510: setup case #7 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 11/42] t1510: setup case #8 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 12/42] t1510: setup case #9 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 13/42] t1510: setup case #10 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 14/42] t1510: setup case #11 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 15/42] t1510: setup case #12 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 16/42] t1510: setup case #13 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 17/42] t1510: setup case #14 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 18/42] t1510: setup case #15 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 19/42] t1510: setup case #16 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 20/42] t1510: setup case #17 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 21/42] t1510: setup case #18 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 22/42] t1510: setup case #19 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 23/42] t1510: setup case #20 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 24/42] t1510: setup case #21 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 25/42] t1510: setup case #22 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 26/42] t1510: setup case #23 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 27/42] t1510: setup case #24 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 28/42] t1510: setup case #25 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 29/42] t1510: setup case #26 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 30/42] t1510: setup case #27 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 31/42] t1510: setup case #28 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 32/42] t1510: setup case #29 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 33/42] t1510: setup case #30 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 34/42] t1510: setup case #31 Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 35/42] rev-parse: prints --git-dir relative to user's cwd Nguyễn Thái Ngọc Duy
2010-10-29 17:06 ` Sverre Rabbelier
2010-10-30 4:42 ` Nguyen Thai Ngoc Duy
2010-10-30 7:09 ` Jonathan Nieder
2010-10-29 6:48 ` [PATCH 36/42] Add git_config_early() Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 37/42] Use git_config_early() instead of git_config() during repo setup Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 38/42] Remove all logic from get_git_work_tree() Nguyễn Thái Ngọc Duy
2010-10-29 17:09 ` Sverre Rabbelier
2010-10-30 4:38 ` Nguyen Thai Ngoc Duy
2010-11-01 6:26 ` [PATCH 1/9] git-rev-parse.txt: clarify --git-dir Nguyễn Thái Ngọc Duy
2010-11-01 6:26 ` [PATCH 2/9] rev-parse: prints --git-dir relative to user's cwd Nguyễn Thái Ngọc Duy
2010-11-01 6:26 ` [PATCH 3/9] Add git_config_early() Nguyễn Thái Ngọc Duy
2010-11-01 6:26 ` [PATCH 4/9] Use git_config_early() instead of git_config() during repo setup Nguyễn Thái Ngọc Duy
2010-11-01 6:26 ` Nguyễn Thái Ngọc Duy [this message]
2010-11-01 6:26 ` [PATCH 6/9] setup: clean up setup_bare_git_dir() Nguyễn Thái Ngọc Duy
2010-11-01 6:26 ` [PATCH 7/9] setup: clean up setup_discovered_git_dir() Nguyễn Thái Ngọc Duy
2010-11-01 6:26 ` [PATCH 8/9] setup: rework setup_explicit_git_dir() Nguyễn Thái Ngọc Duy
2010-11-01 6:26 ` [PATCH 9/9] Remove all logic from get_git_work_tree() Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 39/42] setup: clean up setup_bare_git_dir() Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 40/42] setup: clean up setup_discovered_git_dir() Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 41/42] setup: rework setup_explicit_git_dir() Nguyễn Thái Ngọc Duy
2010-10-29 6:48 ` [PATCH 42/42] t1510: all failed tests are now fixed Nguyễn Thái Ngọc Duy
2010-10-29 8:29 ` Nguyen Thai Ngoc Duy
2010-10-29 17:04 ` [PATCH 00/42] repo setup test cases and fixes Sverre Rabbelier
2010-10-29 17:09 ` Jonathan Nieder
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=1288592794-24221-5-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=srabbelier@gmail.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.