@@ -224,14 +224,15 @@ void verify_non_filename(const char *prefix, const char *arg)
224224 "'git <command> [<revision>...] -- [<file>...]'" , arg );
225225}
226226
227- static void get_common_dir (struct strbuf * sb , const char * gitdir )
227+ int get_common_dir (struct strbuf * sb , const char * gitdir )
228228{
229229 struct strbuf data = STRBUF_INIT ;
230230 struct strbuf path = STRBUF_INIT ;
231231 const char * git_common_dir = getenv (GIT_COMMON_DIR_ENVIRONMENT );
232+ int ret = 0 ;
232233 if (git_common_dir ) {
233234 strbuf_addstr (sb , git_common_dir );
234- return ;
235+ return 1 ;
235236 }
236237 strbuf_addf (& path , "%s/commondir" , gitdir );
237238 if (file_exists (path .buf )) {
@@ -246,10 +247,12 @@ static void get_common_dir(struct strbuf *sb, const char *gitdir)
246247 strbuf_addf (& path , "%s/" , gitdir );
247248 strbuf_addbuf (& path , & data );
248249 strbuf_addstr (sb , real_path (path .buf ));
250+ ret = 1 ;
249251 } else
250252 strbuf_addstr (sb , gitdir );
251253 strbuf_release (& data );
252254 strbuf_release (& path );
255+ return ret ;
253256}
254257
255258/*
@@ -340,13 +343,26 @@ void setup_work_tree(void)
340343 initialized = 1 ;
341344}
342345
346+ static int check_repo_format (const char * var , const char * value , void * cb )
347+ {
348+ if (strcmp (var , "core.repositoryformatversion" ) == 0 )
349+ repository_format_version = git_config_int (var , value );
350+ else if (strcmp (var , "core.sharedrepository" ) == 0 )
351+ shared_repository = git_config_perm (var , value );
352+ return 0 ;
353+ }
354+
343355static int check_repository_format_gently (const char * gitdir , int * nongit_ok )
344356{
345357 struct strbuf sb = STRBUF_INIT ;
346358 const char * repo_config ;
359+ config_fn_t fn ;
347360 int ret = 0 ;
348361
349- get_common_dir (& sb , gitdir );
362+ if (get_common_dir (& sb , gitdir ))
363+ fn = check_repo_format ;
364+ else
365+ fn = check_repository_format_version ;
350366 strbuf_addstr (& sb , "/config" );
351367 repo_config = sb .buf ;
352368
@@ -359,7 +375,7 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
359375 * Use a gentler version of git_config() to check if this repo
360376 * is a good one.
361377 */
362- git_config_early (check_repository_format_version , NULL , repo_config );
378+ git_config_early (fn , NULL , repo_config );
363379 if (GIT_REPO_VERSION < repository_format_version ) {
364380 if (!nongit_ok )
365381 die ("Expected git repo version <= %d, found %d" ,
@@ -841,11 +857,10 @@ int git_config_perm(const char *var, const char *value)
841857
842858int check_repository_format_version (const char * var , const char * value , void * cb )
843859{
844- if (strcmp (var , "core.repositoryformatversion" ) == 0 )
845- repository_format_version = git_config_int (var , value );
846- else if (strcmp (var , "core.sharedrepository" ) == 0 )
847- shared_repository = git_config_perm (var , value );
848- else if (strcmp (var , "core.bare" ) == 0 ) {
860+ int ret = check_repo_format (var , value , cb );
861+ if (ret )
862+ return ret ;
863+ if (strcmp (var , "core.bare" ) == 0 ) {
849864 is_bare_repository_cfg = git_config_bool (var , value );
850865 if (is_bare_repository_cfg == 1 )
851866 inside_work_tree = -1 ;
0 commit comments