Skip to content

Commit

Permalink
setup: save prefix (original cwd relative to toplevel) in startup_info
Browse files Browse the repository at this point in the history
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 <pclouds@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Dec 7, 2010
1 parent 979240f commit f07d6a1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit f07d6a1

Please sign in to comment.