32
32
# include "win32/w32_util.h"
33
33
#endif
34
34
35
+ static int check_repositoryformatversion (git_config * config );
36
+
35
37
#define GIT_FILE_CONTENT_PREFIX "gitdir:"
36
38
37
39
#define GIT_BRANCH_MASTER "master"
@@ -489,6 +491,7 @@ int git_repository_open_ext(
489
491
git_buf path = GIT_BUF_INIT , parent = GIT_BUF_INIT ,
490
492
link_path = GIT_BUF_INIT ;
491
493
git_repository * repo ;
494
+ git_config * config = NULL ;
492
495
493
496
if (repo_ptr )
494
497
* repo_ptr = NULL ;
@@ -510,22 +513,36 @@ int git_repository_open_ext(
510
513
GITERR_CHECK_ALLOC (repo -> path_gitlink );
511
514
}
512
515
516
+ /*
517
+ * We'd like to have the config, but git doesn't particularly
518
+ * care if it's not there, so we need to deal with that.
519
+ */
520
+
521
+ error = git_repository_config_snapshot (& config , repo );
522
+ if (error < 0 && error != GIT_ENOTFOUND )
523
+ goto cleanup ;
524
+
525
+ if (config && (error = check_repositoryformatversion (config )) < 0 )
526
+ goto cleanup ;
527
+
513
528
if ((flags & GIT_REPOSITORY_OPEN_BARE ) != 0 )
514
529
repo -> is_bare = 1 ;
515
530
else {
516
- git_config * config = NULL ;
517
531
518
- if ((error = git_repository_config_snapshot (& config , repo )) < 0 ||
519
- (error = load_config_data (repo , config )) < 0 ||
520
- (error = load_workdir (repo , config , & parent )) < 0 )
521
- git_repository_free (repo );
522
-
523
- git_config_free (config );
532
+ if (config &&
533
+ ((error = load_config_data (repo , config )) < 0 ||
534
+ (error = load_workdir (repo , config , & parent ))) < 0 )
535
+ goto cleanup ;
524
536
}
525
537
526
- if (!error )
527
- * repo_ptr = repo ;
538
+ cleanup :
528
539
git_buf_free (& parent );
540
+ git_config_free (config );
541
+
542
+ if (error < 0 )
543
+ git_repository_free (repo );
544
+ else
545
+ * repo_ptr = repo ;
529
546
530
547
return error ;
531
548
}
@@ -931,9 +948,14 @@ bool git_repository__reserved_names(
931
948
932
949
static int check_repositoryformatversion (git_config * config )
933
950
{
934
- int version ;
951
+ int version , error ;
935
952
936
- if (git_config_get_int32 (& version , config , "core.repositoryformatversion" ) < 0 )
953
+ error = git_config_get_int32 (& version , config , "core.repositoryformatversion" );
954
+ /* git ignores this if the config variable isn't there */
955
+ if (error == GIT_ENOTFOUND )
956
+ return 0 ;
957
+
958
+ if (error < 0 )
937
959
return -1 ;
938
960
939
961
if (GIT_REPO_VERSION < version ) {
0 commit comments