Skip to content

Commit f9f7fd3

Browse files
hanwengitster
authored andcommitted
refs: centralize initialization of the base ref_store.
Signed-off-by: Han-Wen Nienhuys <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a6db572 commit f9f7fd3

File tree

5 files changed

+11
-13
lines changed

5 files changed

+11
-13
lines changed

refs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,10 +2007,12 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt)
20072007
return refs;
20082008
}
20092009

2010-
void base_ref_store_init(struct ref_store *refs,
2011-
const struct ref_storage_be *be)
2010+
void base_ref_store_init(struct ref_store *refs, struct repository *repo,
2011+
const char *path, const struct ref_storage_be *be)
20122012
{
20132013
refs->be = be;
2014+
refs->repo = repo;
2015+
refs->gitdir = xstrdup(path);
20142016
}
20152017

20162018
/* backend functions */

refs/debug.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ struct ref_store *maybe_debug_wrap_ref_store(const char *gitdir, struct ref_stor
2626
be_copy->name = store->be->name;
2727
trace_printf_key(&trace_refs, "ref_store for %s\n", gitdir);
2828
res->refs = store;
29-
base_ref_store_init((struct ref_store *)res, be_copy);
29+
base_ref_store_init((struct ref_store *)res, store->repo, gitdir,
30+
be_copy);
3031
return (struct ref_store *)res;
3132
}
3233

refs/files-backend.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,8 @@ static struct ref_store *files_ref_store_create(struct repository *repo,
8686
struct ref_store *ref_store = (struct ref_store *)refs;
8787
struct strbuf sb = STRBUF_INIT;
8888

89-
ref_store->repo = repo;
90-
ref_store->gitdir = xstrdup(gitdir);
91-
base_ref_store_init(ref_store, &refs_be_files);
89+
base_ref_store_init(ref_store, repo, gitdir, &refs_be_files);
9290
refs->store_flags = flags;
93-
9491
get_common_dir_noenv(&sb, gitdir);
9592
refs->gitcommondir = strbuf_detach(&sb, NULL);
9693
refs->packed_ref_store =

refs/packed-backend.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,11 @@ struct ref_store *packed_ref_store_create(struct repository *repo,
201201
struct ref_store *ref_store = (struct ref_store *)refs;
202202
struct strbuf sb = STRBUF_INIT;
203203

204-
base_ref_store_init(ref_store, &refs_be_packed);
205-
ref_store->repo = repo;
206-
ref_store->gitdir = xstrdup(gitdir);
204+
base_ref_store_init(ref_store, repo, gitdir, &refs_be_packed);
207205
refs->store_flags = store_flags;
206+
208207
strbuf_addf(&sb, "%s/packed-refs", gitdir);
209208
refs->path = strbuf_detach(&sb, NULL);
210-
211209
chdir_notify_reparent("packed-refs", &refs->path);
212210
return ref_store;
213211
}

refs/refs-internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,8 @@ int parse_loose_ref_contents(const char *buf, struct object_id *oid,
710710
* Fill in the generic part of refs and add it to our collection of
711711
* reference stores.
712712
*/
713-
void base_ref_store_init(struct ref_store *refs,
714-
const struct ref_storage_be *be);
713+
void base_ref_store_init(struct ref_store *refs, struct repository *repo,
714+
const char *path, const struct ref_storage_be *be);
715715

716716
/*
717717
* Support GIT_TRACE_REFS by optionally wrapping the given ref_store instance.

0 commit comments

Comments
 (0)