434
return 0;
435
}
436
437
-static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
437
+static int check_repository_format_gently(const char *gitdir, struct repository_format *candidate, int *nongit_ok)
438
{
439
struct strbuf sb = STRBUF_INIT;
440
struct strbuf err = STRBUF_INIT;
441
- struct repository_format candidate;
441
int has_common;
442
443
has_common = get_common_dir(&sb, gitdir);
444
strbuf_addstr(&sb, "/config");
446
- read_repository_format(&candidate, sb.buf);
445
+ read_repository_format(candidate, sb.buf);
446
strbuf_release(&sb);
447
448
/*
450
* we treat a missing config as a silent "ok", even when nongit_ok
451
* is unset.
452
*/
454
- if (candidate.version < 0)
453
+ if (candidate->version < 0)
454
return 0;
455
457
- if (verify_repository_format(&candidate, &err) < 0) {
456
+ if (verify_repository_format(candidate, &err) < 0) {
457
if (nongit_ok) {
458
warning("%s", err.buf);
459
strbuf_release(&err);
463
die("%s", err.buf);
464
}
465
467
- repository_format_precious_objects = candidate.precious_objects;
468
- string_list_clear(&candidate.unknown_extensions, 0);
466
+ repository_format_precious_objects = candidate->precious_objects;
467
+ string_list_clear(&candidate->unknown_extensions, 0);
468
if (!has_common) {
470
- if (candidate.is_bare != -1) {
471
- is_bare_repository_cfg = candidate.is_bare;
469
+ if (candidate->is_bare != -1) {
470
+ is_bare_repository_cfg = candidate->is_bare;
471
if (is_bare_repository_cfg == 1)
472
inside_work_tree = -1;
473
}
475
- if (candidate.work_tree) {
474
+ if (candidate->work_tree) {
475
free(git_work_tree_cfg);
477
- git_work_tree_cfg = candidate.work_tree;
476
+ git_work_tree_cfg = candidate->work_tree;
477
inside_work_tree = -1;
478
}
479
} else {
481
- free(candidate.work_tree);
480
+ free(candidate->work_tree);
481
}
482
483
return 0;
624
625
static const char *setup_explicit_git_dir(const char *gitdirenv,
626
struct strbuf *cwd,
627
+ struct repository_format *repo_fmt,
628
int *nongit_ok)
629
{
630
const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
650
die("Not a git repository: '%s'", gitdirenv);
651
}
652
653
- if (check_repository_format_gently(gitdirenv, nongit_ok)) {
653
+ if (check_repository_format_gently(gitdirenv, repo_fmt, nongit_ok)) {
654
free(gitfile);
655
return NULL;
656
}
723
724
static const char *setup_discovered_git_dir(const char *gitdir,
725
struct strbuf *cwd, int offset,
726
+ struct repository_format *repo_fmt,
727
int *nongit_ok)
728
{
728
- if (check_repository_format_gently(gitdir, nongit_ok))
729
+ if (check_repository_format_gently(gitdir, repo_fmt, nongit_ok))
730
return NULL;
731
732
/* --work-tree is set without --git-dir; use discovered one */
738
gitdir = to_free = real_pathdup(gitdir, 1);
739
if (chdir(cwd->buf))
740
die_errno("Could not come back to cwd");
740
- ret = setup_explicit_git_dir(gitdir, cwd, nongit_ok);
741
+ ret = setup_explicit_git_dir(gitdir, cwd, repo_fmt, nongit_ok);
742
free(to_free);
743
return ret;
744
}
770
771
/* #16.1, #17.1, #20.1, #21.1, #22.1 (see t1510) */
772
static const char *setup_bare_git_dir(struct strbuf *cwd, int offset,
773
+ struct repository_format *repo_fmt,
774
int *nongit_ok)
775
{
776
int root_len;
777
776
- if (check_repository_format_gently(".", nongit_ok))
778
+ if (check_repository_format_gently(".", repo_fmt, nongit_ok))
779
return NULL;
780
781
setenv(GIT_IMPLICIT_WORK_TREE_ENVIRONMENT, "0", 1);
787
gitdir = offset == cwd->len ? "." : xmemdupz(cwd->buf, offset);
788
if (chdir(cwd->buf))
789
die_errno("Could not come back to cwd");
788
- return setup_explicit_git_dir(gitdir, cwd, nongit_ok);
790
+ return setup_explicit_git_dir(gitdir, cwd, repo_fmt, nongit_ok);
791
}
792
793
inside_git_dir = 1;
1028
static struct strbuf cwd = STRBUF_INIT;
1029
struct strbuf dir = STRBUF_INIT, gitdir = STRBUF_INIT;
1030
const char *prefix;
1031
+ struct repository_format repo_fmt;
1032
1033
/*
1034
* We may have read an incomplete configuration before
1056
prefix = NULL;
1057
break;
1058
case GIT_DIR_EXPLICIT:
1056
- prefix = setup_explicit_git_dir(gitdir.buf, &cwd, nongit_ok);
1059
+ prefix = setup_explicit_git_dir(gitdir.buf, &cwd, &repo_fmt, nongit_ok);
1060
break;
1061
case GIT_DIR_DISCOVERED:
1062
if (dir.len < cwd.len && chdir(dir.buf))
1063
die(_("Cannot change to '%s'"), dir.buf);
1064
prefix = setup_discovered_git_dir(gitdir.buf, &cwd, dir.len,
1062
- nongit_ok);
1065
+ &repo_fmt, nongit_ok);
1066
break;
1067
case GIT_DIR_BARE:
1068
if (dir.len < cwd.len && chdir(dir.buf))
1069
die(_("Cannot change to '%s'"), dir.buf);
1067
- prefix = setup_bare_git_dir(&cwd, dir.len, nongit_ok);
1070
+ prefix = setup_bare_git_dir(&cwd, dir.len, &repo_fmt, nongit_ok);
1071
break;
1072
case GIT_DIR_HIT_CEILING:
1073
prefix = setup_nongit(cwd.buf, nongit_ok);
1174
1175
void check_repository_format(void)
1176
{
1174
- check_repository_format_gently(get_git_dir(), NULL);
1177
+ struct repository_format repo_fmt;
1178
+ check_repository_format_gently(get_git_dir(), &repo_fmt, NULL);
1179
startup_info->have_repository = 1;
1180
}
1181