sha1_array: let callbacks interrupt iteration
[gitweb.git] / builtin / init-db.c
index 3a45f0bcfba46210d6f28f61ebef56192869548d..72e81447ae84c8e69799fff5a6fe7050241bea9b 100644 (file)
@@ -180,27 +180,30 @@ static int create_default_files(const char *template_path)
        char junk[2];
        int reinit;
        int filemode;
-
-       /*
-        * Create .git/refs/{heads,tags}
-        */
-       safe_create_dir(git_path_buf(&buf, "refs"), 1);
-       safe_create_dir(git_path_buf(&buf, "refs/heads"), 1);
-       safe_create_dir(git_path_buf(&buf, "refs/tags"), 1);
+       struct strbuf err = STRBUF_INIT;
 
        /* Just look for `init.templatedir` */
        git_config(git_init_db_config, NULL);
 
-       /* First copy the templates -- we might have the default
+       /*
+        * First copy the templates -- we might have the default
         * config file there, in which case we would want to read
         * from it after installing.
+        *
+        * Before reading that config, we also need to clear out any cached
+        * values (since we've just potentially changed what's available on
+        * disk).
         */
        copy_templates(template_path);
-
+       git_config_clear();
+       reset_shared_repository();
        git_config(git_default_config, NULL);
-       is_bare_repository_cfg = init_is_bare_repository;
 
-       /* reading existing config may have overwrote it */
+       /*
+        * We must make sure command-line options continue to override any
+        * values we might have just re-read from the config.
+        */
+       is_bare_repository_cfg = init_is_bare_repository;
        if (init_shared_repository != -1)
                set_shared_repository(init_shared_repository);
 
@@ -210,11 +213,18 @@ static int create_default_files(const char *template_path)
         */
        if (get_shared_repository()) {
                adjust_shared_perm(get_git_dir());
-               adjust_shared_perm(git_path_buf(&buf, "refs"));
-               adjust_shared_perm(git_path_buf(&buf, "refs/heads"));
-               adjust_shared_perm(git_path_buf(&buf, "refs/tags"));
        }
 
+       /*
+        * We need to create a "refs" dir in any case so that older
+        * versions of git can tell that this is a repository.
+        */
+       safe_create_dir(git_path("refs"), 1);
+       adjust_shared_perm(git_path("refs"));
+
+       if (refs_init_db(&err))
+               die("failed to set up refs db: %s", err.buf);
+
        /*
         * Create the default symlink from ".git/HEAD" to the "master"
         * branch, if it does not exist yet.