2525
2626static int init_is_bare_repository = 0 ;
2727static int init_shared_repository = -1 ;
28- static const char * init_db_template_dir ;
2928
3029static void copy_templates_1 (struct strbuf * path , struct strbuf * template_path ,
3130 DIR * dir )
@@ -94,7 +93,7 @@ static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
9493 }
9594}
9695
97- static void copy_templates (const char * template_dir )
96+ static void copy_templates (const char * template_dir , const char * init_template_dir )
9897{
9998 struct strbuf path = STRBUF_INIT ;
10099 struct strbuf template_path = STRBUF_INIT ;
@@ -107,7 +106,7 @@ static void copy_templates(const char *template_dir)
107106 if (!template_dir )
108107 template_dir = getenv (TEMPLATE_DIR_ENVIRONMENT );
109108 if (!template_dir )
110- template_dir = init_db_template_dir ;
109+ template_dir = init_template_dir ;
111110 if (!template_dir )
112111 template_dir = to_free = system_path (DEFAULT_GIT_TEMPLATE_DIR );
113112 if (!template_dir [0 ]) {
@@ -154,17 +153,6 @@ static void copy_templates(const char *template_dir)
154153 clear_repository_format (& template_format );
155154}
156155
157- static int git_init_db_config (const char * k , const char * v , void * cb )
158- {
159- if (!strcmp (k , "init.templatedir" ))
160- return git_config_pathname (& init_db_template_dir , k , v );
161-
162- if (starts_with (k , "core." ))
163- return platform_core_config (k , v , cb );
164-
165- return 0 ;
166- }
167-
168156/*
169157 * If the git_dir is not directly inside the working tree, then git will not
170158 * find it by default, and we need to set the worktree explicitly.
@@ -212,12 +200,9 @@ static int create_default_files(const char *template_path,
212200 int reinit ;
213201 int filemode ;
214202 struct strbuf err = STRBUF_INIT ;
203+ const char * init_template_dir = NULL ;
215204 const char * work_tree = get_git_work_tree ();
216205
217- /* Just look for `init.templatedir` */
218- init_db_template_dir = NULL ; /* re-set in case it was set before */
219- git_config (git_init_db_config , NULL );
220-
221206 /*
222207 * First copy the templates -- we might have the default
223208 * config file there, in which case we would want to read
@@ -227,7 +212,8 @@ static int create_default_files(const char *template_path,
227212 * values (since we've just potentially changed what's available on
228213 * disk).
229214 */
230- copy_templates (template_path );
215+ git_config_get_value ("init.templatedir" , & init_template_dir );
216+ copy_templates (template_path , init_template_dir );
231217 git_config_clear ();
232218 reset_shared_repository ();
233219 git_config (git_default_config , NULL );
@@ -422,8 +408,8 @@ int init_db(const char *git_dir, const char *real_git_dir,
422408 }
423409 startup_info -> have_repository = 1 ;
424410
425- /* Just look for `core.hidedotfiles` */
426- git_config (git_init_db_config , NULL );
411+ /* Ensure `core.hidedotfiles` is processed */
412+ git_config (platform_core_config , NULL );
427413
428414 safe_create_dir (git_dir , 0 );
429415
@@ -575,8 +561,10 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
575561 if (real_git_dir && !is_absolute_path (real_git_dir ))
576562 real_git_dir = real_pathdup (real_git_dir , 1 );
577563
578- if (template_dir && * template_dir && !is_absolute_path (template_dir ))
564+ if (template_dir && * template_dir && !is_absolute_path (template_dir )) {
579565 template_dir = absolute_pathdup (template_dir );
566+ UNLEAK (template_dir );
567+ }
580568
581569 if (argc == 1 ) {
582570 int mkdir_tried = 0 ;
0 commit comments