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>
Nguyễn Thái Ngọc Duy committed
Nov 30, 2014 at 15:24 UTC
7d0fb0da950026c08a88d8374be5716dafce72cc
1 file changed
+8
-4
setup.c
+8
-4
@@ -342,7 +342,9 @@ void setup_work_tree(void)
342
343
static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
344
{
345
- char repo_config[PATH_MAX+1];
345
+ struct strbuf sb = STRBUF_INIT;
346
+ const char *repo_config;
347
+ int ret = 0;
348
349
/*
350
* 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)
355
* Use a gentler version of git_config() to check if this repo
356
* is a good one.
357
*/
356
- snprintf(repo_config, PATH_MAX, "%s/config", gitdir);
358
+ strbuf_addf(&sb, "%s/config", gitdir);
359
+ repo_config = sb.buf;
360
git_config_early(check_repository_format_version, NULL, repo_config);
361
if (GIT_REPO_VERSION < repository_format_version) {
362
if (!nongit_ok)
@@ -363,9 +366,10 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
366
GIT_REPO_VERSION, repository_format_version);
367
warning("Please upgrade Git");
368
*nongit_ok = -1;
366
- return -1;
369
+ ret = -1;
370
}
368
- return 0;
371
+ strbuf_release(&sb);
372
+ return ret;
373
}
374
375
/*