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

[PATCH v2 5/6] setup.c: record the location of .git file

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jan 18, 2016, 11:21 UTC
Message-ID
<1453116094-4987-6-git-send-email-pclouds@gmail.com>
In-Reply-To
<1453116094-4987-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h |  1 +
 setup.c | 12 ++++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/cache.h b/cache.h
index fbe29ac..c912afb 100644
--- a/cache.h
+++ b/cache.h
@@ -1728,6 +1728,7 @@ const char *split_cmdline_strerror(int cmdline_errno);
 struct startup_info {
 	int have_repository;
 	const char *prefix;
+	const char *first_gitfile;
 };
 extern struct startup_info *startup_info;
 
diff --git a/setup.c b/setup.c
index 8b02429..0489f54 100644
--- a/setup.c
+++ b/setup.c
@@ -550,6 +550,8 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
 	gitfile = (char*)read_gitfile(gitdirenv);
 	if (gitfile) {
 		gitfile = xstrdup(gitfile);
+		if (startup_info && !startup_info->first_gitfile)
+			startup_info->first_gitfile = real_path_dup(gitdirenv);
 		gitdirenv = gitfile;
 	}
 
@@ -834,9 +836,12 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
 		current_device = get_device_or_die(".", NULL, 0);
 	for (;;) {
 		gitfile = (char*)read_gitfile(DEFAULT_GIT_DIR_ENVIRONMENT);
-		if (gitfile)
+		if (gitfile) {
 			gitdirenv = gitfile = xstrdup(gitfile);
-		else {
+			if (startup_info && !startup_info->first_gitfile)
+				startup_info->first_gitfile =
+					real_path_dup(DEFAULT_GIT_DIR_ENVIRONMENT);
+		} else {
 			if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))
 				gitdirenv = DEFAULT_GIT_DIR_ENVIRONMENT;
 		}
@@ -885,6 +890,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
 {
 	const char *prefix;
 
+	if (startup_info)
+		startup_info->first_gitfile = NULL;
+
 	prefix = setup_git_directory_gently_1(nongit_ok);
 	if (prefix)
 		setenv(GIT_PREFIX_ENVIRONMENT, prefix, 1);
-- 
2.7.0.96.g5373197
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 9 of 15 in “Kill and replace update_linked_gitdir()”
  1. 0/6 Kill and replace update_linked_gitdir()Nguyễn Thái Ngọc Duy, Jan 18, 2016
  2. 1/6 worktree.c: fix indentationNguyễn Thái Ngọc Duy, Jan 18, 2016
  3. 2/6 worktree: stop supporting moving worktrees manuallyNguyễn Thái Ngọc Duy, Jan 18, 2016
  4. Eric SunshineJan 18, 2016
  5. 3/6 worktree.txt: how to fix up after moving a worktreeNguyễn Thái Ngọc Duy, Jan 18, 2016
  6. Eric SunshineJan 18, 2016
  7. Duy NguyenJan 19, 2016
  8. 4/6 abspath.c: add and use real_path_dup()Nguyễn Thái Ngọc Duy, Jan 18, 2016
  9. 5/6 setup.c: record the location of .git fileNguyễn Thái Ngọc Duy, Jan 18, 2016
  10. 6/6 worktree: new command to fix up worktree's info after movingNguyễn Thái Ngọc Duy, Jan 18, 2016
  11. Philip OakleyJan 18, 2016
  12. Junio C HamanoJan 19, 2016
  13. 0/2 Kill and replace update_linked_gitdir()Nguyễn Thái Ngọc Duy, Jan 22, 2016
  14. 1/2 worktree.c: fix indentationNguyễn Thái Ngọc Duy, Jan 22, 2016
  15. 2/2 worktree: stop supporting moving worktrees manuallyNguyễn Thái Ngọc Duy, Jan 22, 2016

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.