@@ -434,27 +434,26 @@ static int check_repo_format(const char *var, const char *value, void *vdata)
434
434
return 0 ;
435
435
}
436
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
438
{
439
439
struct strbuf sb = STRBUF_INIT ;
440
440
struct strbuf err = STRBUF_INIT ;
441
- struct repository_format candidate ;
442
441
int has_common ;
443
442
444
443
has_common = get_common_dir (& sb , gitdir );
445
444
strbuf_addstr (& sb , "/config" );
446
- read_repository_format (& candidate , sb .buf );
445
+ read_repository_format (candidate , sb .buf );
447
446
strbuf_release (& sb );
448
447
449
448
/*
450
449
* For historical use of check_repository_format() in git-init,
451
450
* we treat a missing config as a silent "ok", even when nongit_ok
452
451
* is unset.
453
452
*/
454
- if (candidate . version < 0 )
453
+ if (candidate -> version < 0 )
455
454
return 0 ;
456
455
457
- if (verify_repository_format (& candidate , & err ) < 0 ) {
456
+ if (verify_repository_format (candidate , & err ) < 0 ) {
458
457
if (nongit_ok ) {
459
458
warning ("%s" , err .buf );
460
459
strbuf_release (& err );
@@ -464,21 +463,21 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
464
463
die ("%s" , err .buf );
465
464
}
466
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 );
469
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 ;
472
471
if (is_bare_repository_cfg == 1 )
473
472
inside_work_tree = -1 ;
474
473
}
475
- if (candidate . work_tree ) {
474
+ if (candidate -> work_tree ) {
476
475
free (git_work_tree_cfg );
477
- git_work_tree_cfg = candidate . work_tree ;
476
+ git_work_tree_cfg = candidate -> work_tree ;
478
477
inside_work_tree = -1 ;
479
478
}
480
479
} else {
481
- free (candidate . work_tree );
480
+ free (candidate -> work_tree );
482
481
}
483
482
484
483
return 0 ;
@@ -625,6 +624,7 @@ const char *read_gitfile_gently(const char *path, int *return_error_code)
625
624
626
625
static const char * setup_explicit_git_dir (const char * gitdirenv ,
627
626
struct strbuf * cwd ,
627
+ struct repository_format * repo_fmt ,
628
628
int * nongit_ok )
629
629
{
630
630
const char * work_tree_env = getenv (GIT_WORK_TREE_ENVIRONMENT );
@@ -650,7 +650,7 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
650
650
die ("Not a git repository: '%s'" , gitdirenv );
651
651
}
652
652
653
- if (check_repository_format_gently (gitdirenv , nongit_ok )) {
653
+ if (check_repository_format_gently (gitdirenv , repo_fmt , nongit_ok )) {
654
654
free (gitfile );
655
655
return NULL ;
656
656
}
@@ -723,9 +723,10 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
723
723
724
724
static const char * setup_discovered_git_dir (const char * gitdir ,
725
725
struct strbuf * cwd , int offset ,
726
+ struct repository_format * repo_fmt ,
726
727
int * nongit_ok )
727
728
{
728
- if (check_repository_format_gently (gitdir , nongit_ok ))
729
+ if (check_repository_format_gently (gitdir , repo_fmt , nongit_ok ))
729
730
return NULL ;
730
731
731
732
/* --work-tree is set without --git-dir; use discovered one */
@@ -737,7 +738,7 @@ static const char *setup_discovered_git_dir(const char *gitdir,
737
738
gitdir = to_free = real_pathdup (gitdir , 1 );
738
739
if (chdir (cwd -> buf ))
739
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 );
741
742
free (to_free );
742
743
return ret ;
743
744
}
@@ -769,11 +770,12 @@ static const char *setup_discovered_git_dir(const char *gitdir,
769
770
770
771
/* #16.1, #17.1, #20.1, #21.1, #22.1 (see t1510) */
771
772
static const char * setup_bare_git_dir (struct strbuf * cwd , int offset ,
773
+ struct repository_format * repo_fmt ,
772
774
int * nongit_ok )
773
775
{
774
776
int root_len ;
775
777
776
- if (check_repository_format_gently ("." , nongit_ok ))
778
+ if (check_repository_format_gently ("." , repo_fmt , nongit_ok ))
777
779
return NULL ;
778
780
779
781
setenv (GIT_IMPLICIT_WORK_TREE_ENVIRONMENT , "0" , 1 );
@@ -785,7 +787,7 @@ static const char *setup_bare_git_dir(struct strbuf *cwd, int offset,
785
787
gitdir = offset == cwd -> len ? "." : xmemdupz (cwd -> buf , offset );
786
788
if (chdir (cwd -> buf ))
787
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 );
789
791
}
790
792
791
793
inside_git_dir = 1 ;
@@ -1026,6 +1028,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
1026
1028
static struct strbuf cwd = STRBUF_INIT ;
1027
1029
struct strbuf dir = STRBUF_INIT , gitdir = STRBUF_INIT ;
1028
1030
const char * prefix ;
1031
+ struct repository_format repo_fmt ;
1029
1032
1030
1033
/*
1031
1034
* We may have read an incomplete configuration before
@@ -1053,18 +1056,18 @@ const char *setup_git_directory_gently(int *nongit_ok)
1053
1056
prefix = NULL ;
1054
1057
break ;
1055
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 );
1057
1060
break ;
1058
1061
case GIT_DIR_DISCOVERED :
1059
1062
if (dir .len < cwd .len && chdir (dir .buf ))
1060
1063
die (_ ("Cannot change to '%s'" ), dir .buf );
1061
1064
prefix = setup_discovered_git_dir (gitdir .buf , & cwd , dir .len ,
1062
- nongit_ok );
1065
+ & repo_fmt , nongit_ok );
1063
1066
break ;
1064
1067
case GIT_DIR_BARE :
1065
1068
if (dir .len < cwd .len && chdir (dir .buf ))
1066
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 );
1068
1071
break ;
1069
1072
case GIT_DIR_HIT_CEILING :
1070
1073
prefix = setup_nongit (cwd .buf , nongit_ok );
@@ -1171,7 +1174,8 @@ int git_config_perm(const char *var, const char *value)
1171
1174
1172
1175
void check_repository_format (void )
1173
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 );
1175
1179
startup_info -> have_repository = 1 ;
1176
1180
}
1177
1181
0 commit comments