Alternate refs backends might not need refs/heads and so on, so we make ref db initialization part of the backend. Signed-off-by: David Turner <dturner@xxxxxxxxxxxxxxxx> --- builtin/init-db.c | 14 ++++---------- refs-be-files.c | 17 +++++++++++++++++ refs.c | 5 +++++ refs.h | 4 ++++ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/builtin/init-db.c b/builtin/init-db.c index f6f7259..2705739 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -178,13 +178,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); @@ -208,11 +202,11 @@ static int create_default_files(const char *template_path) */ if (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")); } + if (refs_initdb(&err, shared_repository)) + 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. diff --git a/refs-be-files.c b/refs-be-files.c index 7560a55..5f2602c 100644 --- a/refs-be-files.c +++ b/refs-be-files.c @@ -3538,10 +3538,27 @@ static int files_reflog_expire(const char *refname, const unsigned char *sha1, return -1; } +static int files_initdb(struct strbuf *err, int shared) +{ + /* + * Create .git/refs/{heads,tags} + */ + safe_create_dir(git_path("refs"), 1); + safe_create_dir(git_path("refs/heads"), 1); + safe_create_dir(git_path("refs/tags"), 1); + if (shared) { + adjust_shared_perm(git_path("refs")); + adjust_shared_perm(git_path("refs/heads")); + adjust_shared_perm(git_path("refs/tags")); + } + return 0; +} + struct ref_be refs_be_files = { NULL, "files", files_init_backend, + files_initdb, files_transaction_commit, files_initial_transaction_commit, files_for_each_reflog_ent, diff --git a/refs.c b/refs.c index 6e41ed8..5fc8eb7 100644 --- a/refs.c +++ b/refs.c @@ -1102,6 +1102,11 @@ enum peel_status peel_object(const unsigned char *name, unsigned char *sha1) } /* backend functions */ +int refs_initdb(struct strbuf *err, int shared) +{ + return the_refs_backend->initdb(err, shared); +} + int ref_transaction_commit(struct ref_transaction *transaction, struct strbuf *err) { diff --git a/refs.h b/refs.h index e3136ee..ce71d33 100644 --- a/refs.h +++ b/refs.h @@ -68,6 +68,8 @@ extern int ref_exists(const char *refname); extern int is_branch(const char *refname); +extern int refs_initdb(struct strbuf *err, int shared); + /* * If refname is a non-symbolic reference that refers to a tag object, * and the tag can be (recursively) dereferenced to a non-tag object, @@ -676,6 +678,7 @@ extern int reflog_expire(const char *refname, const unsigned char *sha1, /* refs backends */ typedef void ref_backend_init_fn(void *data); +typedef int ref_backend_initdb_fn(struct strbuf *err, int shared); typedef int ref_transaction_commit_fn(struct ref_transaction *transaction, struct strbuf *err); typedef void ref_transaction_free_fn(struct ref_transaction *transaction); @@ -737,6 +740,7 @@ struct ref_be { struct ref_be *next; const char *name; ref_backend_init_fn *init_backend; + ref_backend_initdb_fn *initdb; ref_transaction_commit_fn *transaction_commit; ref_transaction_commit_fn *initial_transaction_commit; for_each_reflog_ent_fn *for_each_reflog_ent; -- 2.4.2.644.g97b850b-twtrsrc -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html