]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: rename `init_db` callback to avoid confusion
authorPatrick Steinhardt <ps@pks.im>
Fri, 17 May 2024 08:18:19 +0000 (10:18 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 May 2024 17:33:36 +0000 (10:33 -0700)
Reference backends have two callbacks `init` and `init_db`. The
similarity of these two callbacks has repeatedly confused me whenever I
was looking at them, where I always had to look up which of them does
what.

Rename the `init_db` callback to `create_on_disk`, which should
hopefully be clearer.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/worktree.c
refs.c
refs.h
refs/debug.c
refs/files-backend.c
refs/packed-backend.c
refs/refs-internal.h
refs/reftable-backend.c
setup.c

index 108cfa156aff279a13e19a06957cc3dab00da889..49d9632aa8771ee5ff0505b9a6d66cecb1bc1dd9 100644 (file)
@@ -509,7 +509,7 @@ static int add_worktree(const char *path, const char *refname,
        }
        wt_refs = get_worktree_ref_store(wt);
 
-       ret = refs_init_db(wt_refs, REFS_INIT_DB_IS_WORKTREE, &sb);
+       ret = ref_store_create_on_disk(wt_refs, REF_STORE_CREATE_ON_DISK_IS_WORKTREE, &sb);
        if (ret)
                goto done;
 
diff --git a/refs.c b/refs.c
index a26c50a401ed8d63118d67d70d93231022630d8c..ebc6de81e905b33f62cd3c204f0f79cc5be922ee 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1938,9 +1938,9 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
 }
 
 /* backend functions */
-int refs_init_db(struct ref_store *refs, int flags, struct strbuf *err)
+int ref_store_create_on_disk(struct ref_store *refs, int flags, struct strbuf *err)
 {
-       return refs->be->init_db(refs, flags, err);
+       return refs->be->create_on_disk(refs, flags, err);
 }
 
 int resolve_gitlink_ref(const char *submodule, const char *refname,
diff --git a/refs.h b/refs.h
index d02dd79ca66f630a01311e8255d1b1417a6072a0..421ff9fdb735699929ea79e907aa83eba19621cc 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -114,9 +114,9 @@ int should_autocreate_reflog(const char *refname);
 
 int is_branch(const char *refname);
 
-#define REFS_INIT_DB_IS_WORKTREE (1 << 0)
+#define REF_STORE_CREATE_ON_DISK_IS_WORKTREE (1 << 0)
 
-int refs_init_db(struct ref_store *refs, int flags, struct strbuf *err);
+int ref_store_create_on_disk(struct ref_store *refs, int flags, struct strbuf *err);
 
 /*
  * Return the peeled value of the oid currently being iterated via
index c7531b17f096c329353caf1fd456c726cded5ab8..4cc491097421b7d540fa903b9829df756288a4f9 100644 (file)
@@ -33,11 +33,11 @@ struct ref_store *maybe_debug_wrap_ref_store(const char *gitdir, struct ref_stor
        return (struct ref_store *)res;
 }
 
-static int debug_init_db(struct ref_store *refs, int flags, struct strbuf *err)
+static int debug_create_on_disk(struct ref_store *refs, int flags, struct strbuf *err)
 {
        struct debug_ref_store *drefs = (struct debug_ref_store *)refs;
-       int res = drefs->refs->be->init_db(drefs->refs, flags, err);
-       trace_printf_key(&trace_refs, "init_db: %d\n", res);
+       int res = drefs->refs->be->create_on_disk(drefs->refs, flags, err);
+       trace_printf_key(&trace_refs, "create_on_disk: %d\n", res);
        return res;
 }
 
@@ -427,7 +427,7 @@ static int debug_reflog_expire(struct ref_store *ref_store, const char *refname,
 struct ref_storage_be refs_be_debug = {
        .name = "debug",
        .init = NULL,
-       .init_db = debug_init_db,
+       .create_on_disk = debug_create_on_disk,
 
        /*
         * None of these should be NULL. If the "files" backend (in
index 2c9d5e0747582a92fed034de182d142a68bd0cd2..f9f15d1f76388dc767d169ccc4701380e68eef9d 100644 (file)
@@ -3236,12 +3236,12 @@ static int files_reflog_expire(struct ref_store *ref_store,
        return -1;
 }
 
-static int files_init_db(struct ref_store *ref_store,
-                        int flags,
-                        struct strbuf *err UNUSED)
+static int files_ref_store_create_on_disk(struct ref_store *ref_store,
+                                         int flags,
+                                         struct strbuf *err UNUSED)
 {
        struct files_ref_store *refs =
-               files_downcast(ref_store, REF_STORE_WRITE, "init_db");
+               files_downcast(ref_store, REF_STORE_WRITE, "create");
        struct strbuf sb = STRBUF_INIT;
 
        /*
@@ -3264,7 +3264,7 @@ static int files_init_db(struct ref_store *ref_store,
         * There is no need to create directories for common refs when creating
         * a worktree ref store.
         */
-       if (!(flags & REFS_INIT_DB_IS_WORKTREE)) {
+       if (!(flags & REF_STORE_CREATE_ON_DISK_IS_WORKTREE)) {
                /*
                 * Create .git/refs/{heads,tags}
                 */
@@ -3284,7 +3284,7 @@ static int files_init_db(struct ref_store *ref_store,
 struct ref_storage_be refs_be_files = {
        .name = "files",
        .init = files_ref_store_init,
-       .init_db = files_init_db,
+       .create_on_disk = files_ref_store_create_on_disk,
        .transaction_prepare = files_transaction_prepare,
        .transaction_finish = files_transaction_finish,
        .transaction_abort = files_transaction_abort,
index a3c5a75073b62692f1bf753973cb4427eec80c14..b94183034eb9a0c2915d2c51bdf2d5dd2a89b3b4 100644 (file)
@@ -1244,9 +1244,9 @@ int packed_refs_is_locked(struct ref_store *ref_store)
 static const char PACKED_REFS_HEADER[] =
        "# pack-refs with: peeled fully-peeled sorted \n";
 
-static int packed_ref_store_init_db(struct ref_store *ref_store UNUSED,
-                                   int flags UNUSED,
-                                   struct strbuf *err UNUSED)
+static int packed_ref_store_create_on_disk(struct ref_store *ref_store UNUSED,
+                                          int flags UNUSED,
+                                          struct strbuf *err UNUSED)
 {
        /* Nothing to do. */
        return 0;
@@ -1707,7 +1707,7 @@ static struct ref_iterator *packed_reflog_iterator_begin(struct ref_store *ref_s
 struct ref_storage_be refs_be_packed = {
        .name = "packed",
        .init = packed_ref_store_init,
-       .init_db = packed_ref_store_init_db,
+       .create_on_disk = packed_ref_store_create_on_disk,
        .transaction_prepare = packed_transaction_prepare,
        .transaction_finish = packed_transaction_finish,
        .transaction_abort = packed_transaction_abort,
index 56641aa57a138da17037307d37e1ca28baa2a1ee..c3d5f0a6cd97cd916dd24363c8088cd86d25b0e2 100644 (file)
@@ -530,9 +530,9 @@ typedef struct ref_store *ref_store_init_fn(struct repository *repo,
                                            const char *gitdir,
                                            unsigned int flags);
 
-typedef int ref_init_db_fn(struct ref_store *refs,
-                          int flags,
-                          struct strbuf *err);
+typedef int ref_store_create_on_disk_fn(struct ref_store *refs,
+                                       int flags,
+                                       struct strbuf *err);
 
 typedef int ref_transaction_prepare_fn(struct ref_store *refs,
                                       struct ref_transaction *transaction,
@@ -668,7 +668,7 @@ typedef int read_symbolic_ref_fn(struct ref_store *ref_store, const char *refnam
 struct ref_storage_be {
        const char *name;
        ref_store_init_fn *init;
-       ref_init_db_fn *init_db;
+       ref_store_create_on_disk_fn *create_on_disk;
 
        ref_transaction_prepare_fn *transaction_prepare;
        ref_transaction_finish_fn *transaction_finish;
index 010ef811b6484197912189edf8a4cf901262bf9c..8583a0cdba464c1b1ea727d05cc0450fc296e575 100644 (file)
@@ -293,12 +293,12 @@ done:
        return &refs->base;
 }
 
-static int reftable_be_init_db(struct ref_store *ref_store,
-                              int flags UNUSED,
-                              struct strbuf *err UNUSED)
+static int reftable_be_create_on_disk(struct ref_store *ref_store,
+                                     int flags UNUSED,
+                                     struct strbuf *err UNUSED)
 {
        struct reftable_ref_store *refs =
-               reftable_be_downcast(ref_store, REF_STORE_WRITE, "init_db");
+               reftable_be_downcast(ref_store, REF_STORE_WRITE, "create");
        struct strbuf sb = STRBUF_INIT;
 
        strbuf_addf(&sb, "%s/reftable", refs->base.gitdir);
@@ -2248,7 +2248,7 @@ done:
 struct ref_storage_be refs_be_reftable = {
        .name = "reftable",
        .init = reftable_be_init,
-       .init_db = reftable_be_init_db,
+       .create_on_disk = reftable_be_create_on_disk,
        .transaction_prepare = reftable_be_transaction_prepare,
        .transaction_finish = reftable_be_transaction_finish,
        .transaction_abort = reftable_be_transaction_abort,
diff --git a/setup.c b/setup.c
index c7d3375645e613e66bfbf2976422b164af851f13..fec6bfd5faa16f3a4feb8382e0ee344fa29b43d5 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -2049,7 +2049,7 @@ void create_reference_database(unsigned int ref_storage_format,
        int reinit = is_reinit();
 
        repo_set_ref_storage_format(the_repository, ref_storage_format);
-       if (refs_init_db(get_main_ref_store(the_repository), 0, &err))
+       if (ref_store_create_on_disk(get_main_ref_store(the_repository), 0, &err))
                die("failed to set up refs db: %s", err.buf);
 
        /*