Skip to content

Commit f07d6a1

Browse files
pcloudsgitster
authored andcommitted
setup: save prefix (original cwd relative to toplevel) in startup_info
Save the path from the original cwd to the cwd at the end of the setup procedure in the startup_info struct introduced in e37c132 (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 would 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 <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 979240f commit f07d6a1

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,7 @@ const char *split_cmdline_strerror(int cmdline_errno);
11171117
/* git.c */
11181118
struct startup_info {
11191119
int have_repository;
1120+
const char *prefix;
11201121
};
11211122
extern struct startup_info *startup_info;
11221123

setup.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,10 @@ const char *setup_git_directory_gently(int *nongit_ok)
512512
const char *prefix;
513513

514514
prefix = setup_git_directory_gently_1(nongit_ok);
515-
if (startup_info)
515+
if (startup_info) {
516516
startup_info->have_repository = !nongit_ok || !*nongit_ok;
517+
startup_info->prefix = prefix;
518+
}
517519
return prefix;
518520
}
519521

0 commit comments

Comments
 (0)