git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] worktree setup: calculate prefix even if no worktree is found

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 8, 2010, 16:50 UTC
Message-ID
<1268067033-25199-1-git-send-email-pclouds@gmail.com>

Commit a672ea6 (rehabilitate 'git index-pack' inside the object store - 2008-10-20) worked around a fault in setup_git_directory_gently(). When walking up from inside a git repository, we will return NULL as prefix. We should have returned a correct prefix anyway because cwd has been moved.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 I missed index-pack in my RUN_SETUP_GENTLY series. So three more patches
 on top.
 setup.c              |   19 ++++++++-----------
 t/t1500-rev-parse.sh |    2 +-
 t/t1501-worktree.sh  |    5 +++++
 3 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/setup.c b/setup.c
index bb3648c..8796c6f 100644
--- a/setup.c
+++ b/setup.c
@@ -392,13 +392,16 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
 	offset = len = strlen(cwd);
 	for (;;) {
 		gitfile_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
-		if (gitfile_dir) {
-			if (set_git_dir(gitfile_dir))
+		if (gitfile_dir || is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT)) {
+			if (gitfile_dir && set_git_dir(gitfile_dir))
 				die("Repository setup failed");
+			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);
 			break;
 		}
-		if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))
-			break;
 		if (is_git_directory(".")) {
 			inside_git_dir = 1;
 			if (!work_tree_env)
@@ -409,8 +412,7 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
 				set_git_dir(cwd);
 			} else
 				set_git_dir(".");
-			check_repository_format_gently(nongit_ok);
-			return NULL;
+			break;
 		}
 		while (--offset > ceil_offset && cwd[offset] != '/');
 		if (offset <= ceil_offset) {
@@ -426,11 +428,6 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
 			die_errno("Cannot change to '%s/..'", cwd);
 	}
 
-	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);
 	if (check_repository_format_gently(nongit_ok))
 		return NULL;
 	if (offset == len)
diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
index 48ee077..4ee92c7 100755
--- a/t/t1500-rev-parse.sh
+++ b/t/t1500-rev-parse.sh
@@ -42,7 +42,7 @@ test_rev_parse toplevel false false true '' .git
 cd .git || exit 1
 test_rev_parse .git/ false true false '' .
 cd objects || exit 1
-test_rev_parse .git/objects/ false true false '' "$ROOT/.git"
+test_rev_parse .git/objects/ false true false 'objects/' "$ROOT/.git"
 cd ../.. || exit 1
 
 mkdir -p sub/dir || exit 1
diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
index 9df3012..c72b578 100755
--- a/t/t1501-worktree.sh
+++ b/t/t1501-worktree.sh
@@ -28,6 +28,11 @@ test_rev_parse() {
 	[ $# -eq 0 ] && return
 }
 
+cd .git/objects || exit 1
+say "subdirectory inside .git"
+test_rev_parse 'inside'       false true false objects/
+cd ../.. || exit 1
+
 EMPTY_TREE=$(git write-tree)
 mkdir -p work/sub/dir || exit 1
 mv .git repo.git || exit 1
-- 
1.7.0.1.384.g6abcaa
Next: Nguyễn Thái Ngọc Duy
Message 1 of 3 in “worktree setup: calculate prefix even if no worktree is found”
  1. 1/3 worktree setup: calculate prefix even if no worktree is foundNguyễn Thái Ngọc Duy, Mar 8, 2010
  2. 2/3 index-pack: trust the prefix returned by setup_git_directory_gently()Nguyễn Thái Ngọc Duy, Mar 8, 2010
  3. 3/3 index-pack: use RUN_SETUP_GENTLYNguyễn Thái Ngọc Duy, Mar 8, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.