setup.c: convert is_git_directory() to use strbuf
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
337959b491
commit
1d186b6f35
37
setup.c
37
setup.c
|
@ -238,31 +238,36 @@ void verify_non_filename(const char *prefix, const char *arg)
|
||||||
*/
|
*/
|
||||||
int is_git_directory(const char *suspect)
|
int is_git_directory(const char *suspect)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
struct strbuf path = STRBUF_INIT;
|
||||||
size_t len = strlen(suspect);
|
int ret = 0;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
if (PATH_MAX <= len + strlen("/objects"))
|
strbuf_addstr(&path, suspect);
|
||||||
die("Too long path: %.*s", 60, suspect);
|
len = path.len;
|
||||||
strcpy(path, suspect);
|
|
||||||
if (getenv(DB_ENVIRONMENT)) {
|
if (getenv(DB_ENVIRONMENT)) {
|
||||||
if (access(getenv(DB_ENVIRONMENT), X_OK))
|
if (access(getenv(DB_ENVIRONMENT), X_OK))
|
||||||
return 0;
|
goto done;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
strcpy(path + len, "/objects");
|
strbuf_addstr(&path, "/objects");
|
||||||
if (access(path, X_OK))
|
if (access(path.buf, X_OK))
|
||||||
return 0;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(path + len, "/refs");
|
strbuf_setlen(&path, len);
|
||||||
if (access(path, X_OK))
|
strbuf_addstr(&path, "/refs");
|
||||||
return 0;
|
if (access(path.buf, X_OK))
|
||||||
|
goto done;
|
||||||
|
|
||||||
strcpy(path + len, "/HEAD");
|
strbuf_setlen(&path, len);
|
||||||
if (validate_headref(path))
|
strbuf_addstr(&path, "/HEAD");
|
||||||
return 0;
|
if (validate_headref(path.buf))
|
||||||
|
goto done;
|
||||||
|
|
||||||
return 1;
|
ret = 1;
|
||||||
|
done:
|
||||||
|
strbuf_release(&path);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int is_inside_git_dir(void)
|
int is_inside_git_dir(void)
|
||||||
|
|
Loading…
Reference in New Issue