Skip to content

Commit 7d0fb0d

Browse files
pcloudsgitster
authored andcommitted
setup.c: convert check_repository_format_gently 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 4dc4e14 commit 7d0fb0d

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

setup.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ void setup_work_tree(void)
342342

343343
static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
344344
{
345-
char repo_config[PATH_MAX+1];
345+
struct strbuf sb = STRBUF_INIT;
346+
const char *repo_config;
347+
int ret = 0;
346348

347349
/*
348350
* git_config() can't be used here because it calls git_pathdup()
@@ -353,7 +355,8 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
353355
* Use a gentler version of git_config() to check if this repo
354356
* is a good one.
355357
*/
356-
snprintf(repo_config, PATH_MAX, "%s/config", gitdir);
358+
strbuf_addf(&sb, "%s/config", gitdir);
359+
repo_config = sb.buf;
357360
git_config_early(check_repository_format_version, NULL, repo_config);
358361
if (GIT_REPO_VERSION < repository_format_version) {
359362
if (!nongit_ok)
@@ -363,9 +366,10 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
363366
GIT_REPO_VERSION, repository_format_version);
364367
warning("Please upgrade Git");
365368
*nongit_ok = -1;
366-
return -1;
369+
ret = -1;
367370
}
368-
return 0;
371+
strbuf_release(&sb);
372+
return ret;
369373
}
370374

371375
/*

0 commit comments

Comments
 (0)