refs: rename `init_db` callback to avoid confusion

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>

Patrick Steinhardt committed May 17, 2024 at 10:18 UTC ed93ea16025decb60eb91308d682884e263e6f85
9 files changed +29 -29
builtin/worktree.c
+1 -1
@@ -509,7 +509,7 @@ static int add_worktree(const char *path, const char *refname,
509 }
510 wt_refs = get_worktree_ref_store(wt);
511
512 - ret = refs_init_db(wt_refs, REFS_INIT_DB_IS_WORKTREE, &sb);
512 + ret = ref_store_create_on_disk(wt_refs, REF_STORE_CREATE_ON_DISK_IS_WORKTREE, &sb);
513 if (ret)
514 goto done;
515
refs.c
+2 -2
@@ -1938,9 +1938,9 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
1938 }
1939
1940 /* backend functions */
1941 -int refs_init_db(struct ref_store *refs, int flags, struct strbuf *err)
1941 +int ref_store_create_on_disk(struct ref_store *refs, int flags, struct strbuf *err)
1942 {
1943 - return refs->be->init_db(refs, flags, err);
1943 + return refs->be->create_on_disk(refs, flags, err);
1944 }
1945
1946 int resolve_gitlink_ref(const char *submodule, const char *refname,
refs.h
+2 -2
@@ -114,9 +114,9 @@ int should_autocreate_reflog(const char *refname);
114
115 int is_branch(const char *refname);
116
117 -#define REFS_INIT_DB_IS_WORKTREE (1 << 0)
117 +#define REF_STORE_CREATE_ON_DISK_IS_WORKTREE (1 << 0)
118
119 -int refs_init_db(struct ref_store *refs, int flags, struct strbuf *err);
119 +int ref_store_create_on_disk(struct ref_store *refs, int flags, struct strbuf *err);
120
121 /*
122 * Return the peeled value of the oid currently being iterated via
refs/debug.c
+4 -4
@@ -33,11 +33,11 @@ struct ref_store *maybe_debug_wrap_ref_store(const char *gitdir, struct ref_stor
33 return (struct ref_store *)res;
34 }
35
36 -static int debug_init_db(struct ref_store *refs, int flags, struct strbuf *err)
36 +static int debug_create_on_disk(struct ref_store *refs, int flags, struct strbuf *err)
37 {
38 struct debug_ref_store *drefs = (struct debug_ref_store *)refs;
39 - int res = drefs->refs->be->init_db(drefs->refs, flags, err);
40 - trace_printf_key(&trace_refs, "init_db: %d\n", res);
39 + int res = drefs->refs->be->create_on_disk(drefs->refs, flags, err);
40 + trace_printf_key(&trace_refs, "create_on_disk: %d\n", res);
41 return res;
42 }
43
@@ -427,7 +427,7 @@ static int debug_reflog_expire(struct ref_store *ref_store, const char *refname,
427 struct ref_storage_be refs_be_debug = {
428 .name = "debug",
429 .init = NULL,
430 - .init_db = debug_init_db,
430 + .create_on_disk = debug_create_on_disk,
431
432 /*
433 * None of these should be NULL. If the "files" backend (in
refs/files-backend.c
+6 -6
@@ -3236,12 +3236,12 @@ static int files_reflog_expire(struct ref_store *ref_store,
3236 return -1;
3237 }
3238
3239 -static int files_init_db(struct ref_store *ref_store,
3240 - int flags,
3241 - struct strbuf *err UNUSED)
3239 +static int files_ref_store_create_on_disk(struct ref_store *ref_store,
3240 + int flags,
3241 + struct strbuf *err UNUSED)
3242 {
3243 struct files_ref_store *refs =
3244 - files_downcast(ref_store, REF_STORE_WRITE, "init_db");
3244 + files_downcast(ref_store, REF_STORE_WRITE, "create");
3245 struct strbuf sb = STRBUF_INIT;
3246
3247 /*
@@ -3264,7 +3264,7 @@ static int files_init_db(struct ref_store *ref_store,
3264 * There is no need to create directories for common refs when creating
3265 * a worktree ref store.
3266 */
3267 - if (!(flags & REFS_INIT_DB_IS_WORKTREE)) {
3267 + if (!(flags & REF_STORE_CREATE_ON_DISK_IS_WORKTREE)) {
3268 /*
3269 * Create .git/refs/{heads,tags}
3270 */
@@ -3284,7 +3284,7 @@ static int files_init_db(struct ref_store *ref_store,
3284 struct ref_storage_be refs_be_files = {
3285 .name = "files",
3286 .init = files_ref_store_init,
3287 - .init_db = files_init_db,
3287 + .create_on_disk = files_ref_store_create_on_disk,
3288 .transaction_prepare = files_transaction_prepare,
3289 .transaction_finish = files_transaction_finish,
3290 .transaction_abort = files_transaction_abort,
refs/packed-backend.c
+4 -4
@@ -1244,9 +1244,9 @@ int packed_refs_is_locked(struct ref_store *ref_store)
1244 static const char PACKED_REFS_HEADER[] =
1245 "# pack-refs with: peeled fully-peeled sorted \n";
1246
1247 -static int packed_ref_store_init_db(struct ref_store *ref_store UNUSED,
1248 - int flags UNUSED,
1249 - struct strbuf *err UNUSED)
1247 +static int packed_ref_store_create_on_disk(struct ref_store *ref_store UNUSED,
1248 + int flags UNUSED,
1249 + struct strbuf *err UNUSED)
1250 {
1251 /* Nothing to do. */
1252 return 0;
@@ -1707,7 +1707,7 @@ static struct ref_iterator *packed_reflog_iterator_begin(struct ref_store *ref_s
1707 struct ref_storage_be refs_be_packed = {
1708 .name = "packed",
1709 .init = packed_ref_store_init,
1710 - .init_db = packed_ref_store_init_db,
1710 + .create_on_disk = packed_ref_store_create_on_disk,
1711 .transaction_prepare = packed_transaction_prepare,
1712 .transaction_finish = packed_transaction_finish,
1713 .transaction_abort = packed_transaction_abort,
refs/refs-internal.h
+4 -4
@@ -530,9 +530,9 @@ typedef struct ref_store *ref_store_init_fn(struct repository *repo,
530 const char *gitdir,
531 unsigned int flags);
532
533 -typedef int ref_init_db_fn(struct ref_store *refs,
534 - int flags,
535 - struct strbuf *err);
533 +typedef int ref_store_create_on_disk_fn(struct ref_store *refs,
534 + int flags,
535 + struct strbuf *err);
536
537 typedef int ref_transaction_prepare_fn(struct ref_store *refs,
538 struct ref_transaction *transaction,
@@ -668,7 +668,7 @@ typedef int read_symbolic_ref_fn(struct ref_store *ref_store, const char *refnam
668 struct ref_storage_be {
669 const char *name;
670 ref_store_init_fn *init;
671 - ref_init_db_fn *init_db;
671 + ref_store_create_on_disk_fn *create_on_disk;
672
673 ref_transaction_prepare_fn *transaction_prepare;
674 ref_transaction_finish_fn *transaction_finish;
refs/reftable-backend.c
+5 -5
@@ -293,12 +293,12 @@ done:
293 return &refs->base;
294 }
295
296 -static int reftable_be_init_db(struct ref_store *ref_store,
297 - int flags UNUSED,
298 - struct strbuf *err UNUSED)
296 +static int reftable_be_create_on_disk(struct ref_store *ref_store,
297 + int flags UNUSED,
298 + struct strbuf *err UNUSED)
299 {
300 struct reftable_ref_store *refs =
301 - reftable_be_downcast(ref_store, REF_STORE_WRITE, "init_db");
301 + reftable_be_downcast(ref_store, REF_STORE_WRITE, "create");
302 struct strbuf sb = STRBUF_INIT;
303
304 strbuf_addf(&sb, "%s/reftable", refs->base.gitdir);
@@ -2248,7 +2248,7 @@ done:
2248 struct ref_storage_be refs_be_reftable = {
2249 .name = "reftable",
2250 .init = reftable_be_init,
2251 - .init_db = reftable_be_init_db,
2251 + .create_on_disk = reftable_be_create_on_disk,
2252 .transaction_prepare = reftable_be_transaction_prepare,
2253 .transaction_finish = reftable_be_transaction_finish,
2254 .transaction_abort = reftable_be_transaction_abort,
setup.c
+1 -1
@@ -2049,7 +2049,7 @@ void create_reference_database(unsigned int ref_storage_format,
2049 int reinit = is_reinit();
2050
2051 repo_set_ref_storage_format(the_repository, ref_storage_format);
2052 - if (refs_init_db(get_main_ref_store(the_repository), 0, &err))
2052 + if (ref_store_create_on_disk(get_main_ref_store(the_repository), 0, &err))
2053 die("failed to set up refs db: %s", err.buf);
2054
2055 /*