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

[PATCH 1/3] setup: save prefix (original cwd relative to toplevel) in startup_info

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Nov 11, 2010, 14:08 UTC
Message-ID
<1289484484-8632-2-git-send-email-pclouds@gmail.com>
In-Reply-To
<1289484484-8632-1-git-send-email-pclouds@gmail.com>

Save the path from the original cwd to the cwd at the end of the setup procedure in the startup_info struct introduced in e37c1329 (2010-08-05). The value cannot vary from thread to thread anyway, since the cwd is global.

So now in your builtin command, instead of passing prefix around, when you want to convert a user-supplied path to a cwd-relative path, you can use startup_info->prefix directly.

Caveat: As with the return value from setup_git_directory_gently(),
startup_info->prefix would be NULL when the original cwd is not a
subdir of the toplevel.

Longer term, this woiuld allow the prefix to be reused when several noncooperating functions require access to the same repository (for example, when accessing configuration before running a builtin).

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 cache.h |    1 +
 setup.c |    4 +++-
 2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/cache.h b/cache.h
index 33decd9..222d9cf 100644
--- a/cache.h
+++ b/cache.h
@@ -1117,6 +1117,7 @@ const char *split_cmdline_strerror(int cmdline_errno);
 /* git.c */
 struct startup_info {
 	int have_repository;
+	const char *prefix;
 };
 extern struct startup_info *startup_info;
 
diff --git a/setup.c b/setup.c
index a3b76de..833db12 100644
--- a/setup.c
+++ b/setup.c
@@ -512,8 +512,10 @@ const char *setup_git_directory_gently(int *nongit_ok)
 	const char *prefix;
 
 	prefix = setup_git_directory_gently_1(nongit_ok);
-	if (startup_info)
+	if (startup_info) {
 		startup_info->have_repository = !nongit_ok || !*nongit_ok;
+		startup_info->prefix = prefix;
+	}
 	return prefix;
 }
 
-- 
1.7.3.2.210.g045198
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 2 of 12 in “Support relative path in <blah>:path syntax”
  1. 0/3 Support relative path in <blah>:path syntaxNguyễn Thái Ngọc Duy, Nov 11, 2010
  2. 1/3 setup: save prefix (original cwd relative to toplevel) in startup_infoNguyễn Thái Ngọc Duy, Nov 11, 2010
  3. 2/3 Make prefix_path() return char* without constNguyễn Thái Ngọc Duy, Nov 11, 2010
  4. 3/3 get_sha1: support relative path ":path" syntaxNguyễn Thái Ngọc Duy, Nov 11, 2010
  5. Thiago FarinaNov 14, 2010
  6. get_sha1: support relative path ":path" syntaxNguyễn Thái Ngọc Duy, Nov 15, 2010
  7. Sverre RabbelierNov 15, 2010
  8. Junio C HamanoNov 15, 2010
  9. Junio C HamanoNov 15, 2010
  10. get_sha1: support relative path ":path" syntaxNguyễn Thái Ngọc Duy, Nov 28, 2010
  11. Junio C HamanoNov 17, 2010
  12. Nguyen Thai Ngoc DuyNov 18, 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.