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 <dtur...@twopensource.com>
---
 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 f0b095c..504a2dc 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -177,13 +177,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);
@@ -207,11 +201,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 ea91afd..0a76c8e 100644
--- a/refs-be-files.c
+++ b/refs-be-files.c
@@ -3738,10 +3738,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",
        NULL,
+       files_initdb,
        files_transaction_begin,
        files_transaction_update,
        files_transaction_create,
diff --git a/refs.c b/refs.c
index 530edcf..930c85c 100644
--- a/refs.c
+++ b/refs.c
@@ -995,6 +995,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);
+}
+
 struct ref_transaction *ref_transaction_begin(struct strbuf *err)
 {
        return the_refs_backend->transaction_begin(err);
diff --git a/refs.h b/refs.h
index bd46d0f..64dba64 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,
@@ -587,6 +589,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 struct ref_transaction *(*ref_transaction_begin_fn)(struct strbuf 
*err);
 typedef int (*ref_transaction_update_fn)(struct ref_transaction *transaction,
                const char *refname, const unsigned char *new_sha1,
@@ -666,6 +669,7 @@ struct ref_be {
        struct ref_be *next;
        const char *name;
        ref_backend_init_fn init_backend;
+       ref_backend_initdb_fn initdb;
        ref_transaction_begin_fn transaction_begin;
        ref_transaction_update_fn transaction_update;
        ref_transaction_create_fn transaction_create;
-- 
2.4.2.644.g97b850b-twtrsrc

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to