Skip to content

Commit 1d186b6

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent 337959b commit 1d186b6

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

setup.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -238,31 +238,36 @@ void verify_non_filename(const char *prefix, const char *arg)
238238
*/
239239
int is_git_directory(const char *suspect)
240240
{
241-
char path[PATH_MAX];
242-
size_t len = strlen(suspect);
241+
struct strbuf path = STRBUF_INIT;
242+
int ret = 0;
243+
size_t len;
243244

244-
if (PATH_MAX <= len + strlen("/objects"))
245-
die("Too long path: %.*s", 60, suspect);
246-
strcpy(path, suspect);
245+
strbuf_addstr(&path, suspect);
246+
len = path.len;
247247
if (getenv(DB_ENVIRONMENT)) {
248248
if (access(getenv(DB_ENVIRONMENT), X_OK))
249-
return 0;
249+
goto done;
250250
}
251251
else {
252-
strcpy(path + len, "/objects");
253-
if (access(path, X_OK))
254-
return 0;
252+
strbuf_addstr(&path, "/objects");
253+
if (access(path.buf, X_OK))
254+
goto done;
255255
}
256256

257-
strcpy(path + len, "/refs");
258-
if (access(path, X_OK))
259-
return 0;
257+
strbuf_setlen(&path, len);
258+
strbuf_addstr(&path, "/refs");
259+
if (access(path.buf, X_OK))
260+
goto done;
260261

261-
strcpy(path + len, "/HEAD");
262-
if (validate_headref(path))
263-
return 0;
262+
strbuf_setlen(&path, len);
263+
strbuf_addstr(&path, "/HEAD");
264+
if (validate_headref(path.buf))
265+
goto done;
264266

265-
return 1;
267+
ret = 1;
268+
done:
269+
strbuf_release(&path);
270+
return ret;
266271
}
267272

268273
int is_inside_git_dir(void)

0 commit comments

Comments
 (0)