Skip to content

Commit 2e573d6

Browse files
pks-tgitster
authored andcommitted
refs: prepare refs_init_db() for initializing worktree refs
The purpose of `refs_init_db()` is to initialize the on-disk files of a new ref database. The function is quite inflexible right now though, as callers can neither specify the `struct ref_store` nor can they pass any flags. Refactor the interface to accept both of these. This will be required so that we can start initializing per-worktree ref databases via the ref backend instead of open-coding the initialization in "worktree.c". Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5bf20d6 commit 2e573d6

File tree

7 files changed

+13
-10
lines changed

7 files changed

+13
-10
lines changed

refs.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,11 +1944,9 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
19441944
}
19451945

19461946
/* backend functions */
1947-
int refs_init_db(struct strbuf *err)
1947+
int refs_init_db(struct ref_store *refs, int flags, struct strbuf *err)
19481948
{
1949-
struct ref_store *refs = get_main_ref_store(the_repository);
1950-
1951-
return refs->be->init_db(refs, err);
1949+
return refs->be->init_db(refs, flags, err);
19521950
}
19531951

19541952
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,

refs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ int should_autocreate_reflog(const char *refname);
126126

127127
int is_branch(const char *refname);
128128

129-
int refs_init_db(struct strbuf *err);
129+
int refs_init_db(struct ref_store *refs, int flags, struct strbuf *err);
130130

131131
/*
132132
* Return the peeled value of the oid currently being iterated via

refs/debug.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ struct ref_store *maybe_debug_wrap_ref_store(const char *gitdir, struct ref_stor
3333
return (struct ref_store *)res;
3434
}
3535

36-
static int debug_init_db(struct ref_store *refs, struct strbuf *err)
36+
static int debug_init_db(struct ref_store *refs, int flags, struct strbuf *err)
3737
{
3838
struct debug_ref_store *drefs = (struct debug_ref_store *)refs;
39-
int res = drefs->refs->be->init_db(drefs->refs, err);
39+
int res = drefs->refs->be->init_db(drefs->refs, flags, err);
4040
trace_printf_key(&trace_refs, "init_db: %d\n", res);
4141
return res;
4242
}

refs/files-backend.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3220,7 +3220,9 @@ static int files_reflog_expire(struct ref_store *ref_store,
32203220
return -1;
32213221
}
32223222

3223-
static int files_init_db(struct ref_store *ref_store, struct strbuf *err UNUSED)
3223+
static int files_init_db(struct ref_store *ref_store,
3224+
int flags UNUSED,
3225+
struct strbuf *err UNUSED)
32243226
{
32253227
struct files_ref_store *refs =
32263228
files_downcast(ref_store, REF_STORE_WRITE, "init_db");

refs/packed-backend.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,7 @@ static const char PACKED_REFS_HEADER[] =
12461246
"# pack-refs with: peeled fully-peeled sorted \n";
12471247

12481248
static int packed_init_db(struct ref_store *ref_store UNUSED,
1249+
int flags UNUSED,
12491250
struct strbuf *err UNUSED)
12501251
{
12511252
/* Nothing to do. */

refs/refs-internal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,9 @@ typedef struct ref_store *ref_store_init_fn(struct repository *repo,
529529
const char *gitdir,
530530
unsigned int flags);
531531

532-
typedef int ref_init_db_fn(struct ref_store *refs, struct strbuf *err);
532+
typedef int ref_init_db_fn(struct ref_store *refs,
533+
int flags,
534+
struct strbuf *err);
533535

534536
typedef int ref_transaction_prepare_fn(struct ref_store *refs,
535537
struct ref_transaction *transaction,

setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,7 @@ void create_reference_database(unsigned int ref_storage_format,
19431943
adjust_shared_perm(git_path("refs"));
19441944

19451945
repo_set_ref_storage_format(the_repository, ref_storage_format);
1946-
if (refs_init_db(&err))
1946+
if (refs_init_db(get_main_ref_store(the_repository), 0, &err))
19471947
die("failed to set up refs db: %s", err.buf);
19481948

19491949
/*

0 commit comments

Comments
 (0)