Thread (4 messages) flat view 4 messages, 4 authors, 2016-06-15
DORMANTno replies

[PATCH] setup: do not create $X/gitdir unnecessarily when accessing git file $X

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 23:07:09
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

$X/gitdir is created, or refreshed, in order to keep a linked worktree
from being pruned. But while git file is used as the foundation for
linked worktrees, it's used for other purposes as well and we should
not create $X/gitdir in those cases.

Tighten the check. Only update an existing file, which is an
indication this is a linked worktree.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 setup.c            | 2 +-
 t/t0002-gitfile.sh | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/setup.c b/setup.c
index d343725..b30d923 100644
--- a/setup.c
+++ b/setup.c
@@ -440,7 +440,7 @@ static void update_linked_gitdir(const char *gitfile, const char *gitdir)
 	struct stat st;
 
 	strbuf_addf(&path, "%s/gitdir", gitdir);
-	if (stat(path.buf, &st) || st.st_mtime + 24 * 3600 < time(NULL))
+	if (!stat(path.buf, &st) && st.st_mtime + 24 * 3600 < time(NULL))
 		write_file(path.buf, "%s", gitfile);
 	strbuf_release(&path);
 }
diff --git a/t/t0002-gitfile.sh b/t/t0002-gitfile.sh
index 9670e8c..b1b59f2 100755
--- a/t/t0002-gitfile.sh
+++ b/t/t0002-gitfile.sh
@@ -99,6 +99,13 @@ test_expect_success 'check rev-list' '
 	test "$SHA" = "$(git rev-list HEAD)"
 '
 
+test_expect_success '$REAL/gitdir is not created on ordinary git file' '
+	echo "gitdir: $REAL" >expected &&
+	test_cmp expected .git &&
+	git status &&
+	! test -f "$REAL"/gitdir
+'
+
 test_expect_success 'setup_git_dir twice in subdir' '
 	git init sgd &&
 	(
-- 
2.2.0.513.g477eb31
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help