Skip to content

Commit 652f18e

Browse files
peffgitster
authored andcommitted
setup: unify repository version callbacks
Once upon a time, check_repository_format_gently would parse the config with a single callback, and that callback would set up a bunch of global variables. But now that we have separate workdirs, we have to be more careful. Commit 31e26eb (setup.c: support multi-checkout repo setup, 2014-11-30) introduced a reduced callback which omits some values like core.worktree. In the "main" callback we call the reduced one, and then add back in the missing variables. Now that we have split the config-parsing from the munging of the global variables, we can do it all with a single callback, and keep all of the "are we in a separate workdir" logic together. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 94ce167 commit 652f18e

File tree

2 files changed

+23
-43
lines changed

2 files changed

+23
-43
lines changed

cache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,6 @@ extern void git_config_set_multivar_in_file(const char *, const char *, const ch
15821582
extern int git_config_rename_section(const char *, const char *);
15831583
extern int git_config_rename_section_in_file(const char *, const char *, const char *);
15841584
extern const char *git_etc_gitconfig(void);
1585-
extern int check_repository_format_version(const char *var, const char *value, void *cb);
15861585
extern int git_env_bool(const char *, int);
15871586
extern unsigned long git_env_ulong(const char *, unsigned long);
15881587
extern int git_config_system(void);

setup.c

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -388,27 +388,26 @@ static int check_repo_format(const char *var, const char *value, void *vdata)
388388
data->precious_objects = git_config_bool(var, value);
389389
else
390390
string_list_append(&data->unknown_extensions, ext);
391+
} else if (strcmp(var, "core.bare") == 0) {
392+
data->is_bare = git_config_bool(var, value);
393+
} else if (strcmp(var, "core.worktree") == 0) {
394+
if (!value)
395+
return config_error_nonbool(var);
396+
data->work_tree = xstrdup(value);
391397
}
392398
return 0;
393399
}
394400

395-
static int read_repository_format_1(struct repository_format *, config_fn_t,
396-
const char *);
397-
398401
static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
399402
{
400403
struct strbuf sb = STRBUF_INIT;
401404
struct strbuf err = STRBUF_INIT;
402405
struct repository_format candidate;
403-
config_fn_t fn;
404-
405-
if (get_common_dir(&sb, gitdir))
406-
fn = check_repo_format;
407-
else
408-
fn = check_repository_format_version;
406+
int has_common;
409407

408+
has_common = get_common_dir(&sb, gitdir);
410409
strbuf_addstr(&sb, "/config");
411-
read_repository_format_1(&candidate, fn, sb.buf);
410+
read_repository_format(&candidate, sb.buf);
412411
strbuf_release(&sb);
413412

414413
/*
@@ -432,36 +431,34 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
432431
repository_format_version = candidate.version;
433432
repository_format_precious_objects = candidate.precious_objects;
434433
string_list_clear(&candidate.unknown_extensions, 0);
435-
if (candidate.is_bare != -1) {
436-
is_bare_repository_cfg = candidate.is_bare;
437-
if (is_bare_repository_cfg == 1)
434+
if (!has_common) {
435+
if (candidate.is_bare != -1) {
436+
is_bare_repository_cfg = candidate.is_bare;
437+
if (is_bare_repository_cfg == 1)
438+
inside_work_tree = -1;
439+
}
440+
if (candidate.work_tree) {
441+
free(git_work_tree_cfg);
442+
git_work_tree_cfg = candidate.work_tree;
438443
inside_work_tree = -1;
439-
}
440-
if (candidate.work_tree) {
441-
free(git_work_tree_cfg);
442-
git_work_tree_cfg = candidate.work_tree;
443-
inside_work_tree = -1;
444+
}
445+
} else {
446+
free(candidate.work_tree);
444447
}
445448

446449
return 0;
447450
}
448451

449-
static int read_repository_format_1(struct repository_format *format,
450-
config_fn_t fn, const char *path)
452+
int read_repository_format(struct repository_format *format, const char *path)
451453
{
452454
memset(format, 0, sizeof(*format));
453455
format->version = -1;
454456
format->is_bare = -1;
455457
string_list_init(&format->unknown_extensions, 1);
456-
git_config_from_file(fn, path, format);
458+
git_config_from_file(check_repo_format, path, format);
457459
return format->version;
458460
}
459461

460-
int read_repository_format(struct repository_format *format, const char *path)
461-
{
462-
return read_repository_format_1(format, check_repository_format_version, path);
463-
}
464-
465462
int verify_repository_format(const struct repository_format *format,
466463
struct strbuf *err)
467464
{
@@ -999,22 +996,6 @@ int git_config_perm(const char *var, const char *value)
999996
return -(i & 0666);
1000997
}
1001998

1002-
int check_repository_format_version(const char *var, const char *value, void *cb)
1003-
{
1004-
struct repository_format *data = cb;
1005-
int ret = check_repo_format(var, value, cb);
1006-
if (ret)
1007-
return ret;
1008-
if (strcmp(var, "core.bare") == 0) {
1009-
data->is_bare = git_config_bool(var, value);
1010-
} else if (strcmp(var, "core.worktree") == 0) {
1011-
if (!value)
1012-
return config_error_nonbool(var);
1013-
data->work_tree = xstrdup(value);
1014-
}
1015-
return 0;
1016-
}
1017-
1018999
void check_repository_format(void)
10191000
{
10201001
check_repository_format_gently(get_git_dir(), NULL);

0 commit comments

Comments
 (0)