[PATCH v2 02/16] refs: rename `init_db` callback to avoid confusion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx>
---
 builtin/worktree.c      |  2 +-
 refs.c                  |  4 ++--
 refs.h                  |  4 ++--
 refs/debug.c            |  8 ++++----
 refs/files-backend.c    | 12 ++++++------
 refs/packed-backend.c   |  8 ++++----
 refs/refs-internal.h    |  8 ++++----
 refs/reftable-backend.c | 10 +++++-----
 setup.c                 |  2 +-
 9 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/builtin/worktree.c b/builtin/worktree.c
index 108cfa156a..49d9632aa8 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -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 a26c50a401..ebc6de81e9 100644
--- 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 d02dd79ca6..421ff9fdb7 100644
--- 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
diff --git a/refs/debug.c b/refs/debug.c
index c7531b17f0..4cc4910974 100644
--- a/refs/debug.c
+++ b/refs/debug.c
@@ -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
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 2c9d5e0747..f9f15d1f76 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -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,
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index a3c5a75073..b94183034e 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -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,
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index 56641aa57a..c3d5f0a6cd 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -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;
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index 010ef811b6..8583a0cdba 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -293,12 +293,12 @@ static struct ref_store *reftable_be_init(struct repository *repo,
 	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 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
 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 c7d3375645..fec6bfd5fa 100644
--- 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);
 
 	/*
-- 
2.45.1.190.g19fe900cfc.dirty

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux