refs: add methods to init refs db

Alternate refs backends might not need the refs/heads directory and so
on, so we make ref db initialization part of the backend.

Signed-off-by: David Turner <dturner@twopensource.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
David Turner
2016-09-04 18:08:41 +02:00
committed by Junio C Hamano
parent a27dcf89b6
commit 6fb5acfd8f
5 changed files with 42 additions and 10 deletions

View File

@ -180,13 +180,7 @@ 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);
@ -210,11 +204,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.