@@ -95,6 +95,8 @@ static void copy_templates(const char *template_dir)
9595 struct strbuf path = STRBUF_INIT ;
9696 struct strbuf template_path = STRBUF_INIT ;
9797 size_t template_len ;
98+ struct repository_format template_format ;
99+ struct strbuf err = STRBUF_INIT ;
98100 DIR * dir ;
99101 char * to_free = NULL ;
100102
@@ -121,17 +123,18 @@ static void copy_templates(const char *template_dir)
121123
122124 /* Make sure that template is from the correct vintage */
123125 strbuf_addstr (& template_path , "config" );
124- repository_format_version = 0 ;
125- git_config_from_file (check_repository_format_version ,
126- template_path .buf , NULL );
126+ read_repository_format (& template_format , template_path .buf );
127127 strbuf_setlen (& template_path , template_len );
128128
129- if (repository_format_version &&
130- repository_format_version != GIT_REPO_VERSION ) {
131- warning (_ ("not copying templates of "
132- "a wrong format version %d from '%s'" ),
133- repository_format_version ,
134- template_dir );
129+ /*
130+ * No mention of version at all is OK, but anything else should be
131+ * verified.
132+ */
133+ if (template_format .version >= 0 &&
134+ verify_repository_format (& template_format , & err ) < 0 ) {
135+ warning (_ ("not copying templates from '%s': %s" ),
136+ template_dir , err .buf );
137+ strbuf_release (& err );
135138 goto close_free_return ;
136139 }
137140
@@ -199,13 +202,13 @@ static int create_default_files(const char *template_path)
199202
200203 /* reading existing config may have overwrote it */
201204 if (init_shared_repository != -1 )
202- shared_repository = init_shared_repository ;
205+ set_shared_repository ( init_shared_repository ) ;
203206
204207 /*
205208 * We would have created the above under user's umask -- under
206209 * shared-repository settings, we would need to fix them up.
207210 */
208- if (shared_repository ) {
211+ if (get_shared_repository () ) {
209212 adjust_shared_perm (get_git_dir ());
210213 adjust_shared_perm (git_path_buf (& buf , "refs" ));
211214 adjust_shared_perm (git_path_buf (& buf , "refs/heads" ));
@@ -370,20 +373,20 @@ int init_db(const char *template_dir, unsigned int flags)
370373
371374 create_object_directory ();
372375
373- if (shared_repository ) {
376+ if (get_shared_repository () ) {
374377 char buf [10 ];
375378 /* We do not spell "group" and such, so that
376379 * the configuration can be read by older version
377380 * of git. Note, we use octal numbers for new share modes,
378381 * and compatibility values for PERM_GROUP and
379382 * PERM_EVERYBODY.
380383 */
381- if (shared_repository < 0 )
384+ if (get_shared_repository () < 0 )
382385 /* force to the mode value */
383- xsnprintf (buf , sizeof (buf ), "0%o" , - shared_repository );
384- else if (shared_repository == PERM_GROUP )
386+ xsnprintf (buf , sizeof (buf ), "0%o" , - get_shared_repository () );
387+ else if (get_shared_repository () == PERM_GROUP )
385388 xsnprintf (buf , sizeof (buf ), "%d" , OLD_PERM_GROUP );
386- else if (shared_repository == PERM_EVERYBODY )
389+ else if (get_shared_repository () == PERM_EVERYBODY )
387390 xsnprintf (buf , sizeof (buf ), "%d" , OLD_PERM_EVERYBODY );
388391 else
389392 die ("BUG: invalid value for shared_repository" );
@@ -399,7 +402,7 @@ int init_db(const char *template_dir, unsigned int flags)
399402 "", and the last '%s%s' is the verbatim directory name. */
400403 printf (_ ("%s%s Git repository in %s%s\n" ),
401404 reinit ? _ ("Reinitialized existing" ) : _ ("Initialized empty" ),
402- shared_repository ? _ (" shared" ) : "" ,
405+ get_shared_repository () ? _ (" shared" ) : "" ,
403406 git_dir , len && git_dir [len - 1 ] != '/' ? "/" : "" );
404407 }
405408
@@ -494,8 +497,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
494497 * and we know shared_repository should always be 0;
495498 * but just in case we play safe.
496499 */
497- saved = shared_repository ;
498- shared_repository = 0 ;
500+ saved = get_shared_repository () ;
501+ set_shared_repository ( 0 ) ;
499502 switch (safe_create_leading_directories_const (argv [0 ])) {
500503 case SCLD_OK :
501504 case SCLD_PERMS :
@@ -507,7 +510,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
507510 die_errno (_ ("cannot mkdir %s" ), argv [0 ]);
508511 break ;
509512 }
510- shared_repository = saved ;
513+ set_shared_repository ( saved ) ;
511514 if (mkdir (argv [0 ], 0777 ) < 0 )
512515 die_errno (_ ("cannot mkdir %s" ), argv [0 ]);
513516 mkdir_tried = 1 ;
@@ -525,7 +528,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
525528 }
526529
527530 if (init_shared_repository != -1 )
528- shared_repository = init_shared_repository ;
531+ set_shared_repository ( init_shared_repository ) ;
529532
530533 /*
531534 * GIT_WORK_TREE makes sense only in conjunction with GIT_DIR
0 commit comments