X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=setup.c;h=61c22e6becc1e49f1e92c916a4b8badd30a9cb2f;hb=829a1c616967176ccd859c18a6e8ca0dda77f75a;hp=1b06db53fc24f1347e2a73bbecb44a059882e898;hpb=1f7a2abcc18ec1080905dc5cd59381f7ac1c8111;p=git.git diff --git a/setup.c b/setup.c index 1b06db53f..61c22e6be 100644 --- a/setup.c +++ b/setup.c @@ -40,34 +40,6 @@ char *prefix_path(const char *prefix, int len, const char *path) return sanitized; } -/* - * Unlike prefix_path, this should be used if the named file does - * not have to interact with index entry; i.e. name of a random file - * on the filesystem. - */ -const char *prefix_filename(const char *pfx, int pfx_len, const char *arg) -{ - static char path[PATH_MAX]; -#ifndef WIN32 - if (!pfx_len || is_absolute_path(arg)) - return arg; - memcpy(path, pfx, pfx_len); - strcpy(path + pfx_len, arg); -#else - char *p; - /* don't add prefix to absolute paths, but still replace '\' by '/' */ - if (is_absolute_path(arg)) - pfx_len = 0; - else if (pfx_len) - memcpy(path, pfx, pfx_len); - strcpy(path + pfx_len, arg); - for (p = path + pfx_len; *p; p++) - if (*p == '\\') - *p = '/'; -#endif - return path; -} - int check_filename(const char *prefix, const char *arg) { const char *name; @@ -710,6 +682,11 @@ const char *setup_git_directory_gently(int *nongit_ok) const char *prefix; prefix = setup_git_directory_gently_1(nongit_ok); + if (prefix) + setenv("GIT_PREFIX", prefix, 1); + else + setenv("GIT_PREFIX", "", 1); + if (startup_info) { startup_info->have_repository = !nongit_ok || !*nongit_ok; startup_info->prefix = prefix; @@ -803,3 +780,10 @@ const char *setup_git_directory(void) { return setup_git_directory_gently(NULL); } + +const char *resolve_gitdir(const char *suspect) +{ + if (is_git_directory(suspect)) + return suspect; + return read_gitfile(suspect); +}