Skip to content

Commit

Permalink
refs: centralize initialization of the base ref_store.
Browse files Browse the repository at this point in the history
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
hanwen authored and gitster committed Dec 22, 2021
1 parent a6db572 commit f9f7fd3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
6 changes: 4 additions & 2 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2007,10 +2007,12 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt)
return refs;
}

void base_ref_store_init(struct ref_store *refs,
const struct ref_storage_be *be)
void base_ref_store_init(struct ref_store *refs, struct repository *repo,
const char *path, const struct ref_storage_be *be)
{
refs->be = be;
refs->repo = repo;
refs->gitdir = xstrdup(path);
}

/* backend functions */
Expand Down
3 changes: 2 additions & 1 deletion refs/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ struct ref_store *maybe_debug_wrap_ref_store(const char *gitdir, struct ref_stor
be_copy->name = store->be->name;
trace_printf_key(&trace_refs, "ref_store for %s\n", gitdir);
res->refs = store;
base_ref_store_init((struct ref_store *)res, be_copy);
base_ref_store_init((struct ref_store *)res, store->repo, gitdir,
be_copy);
return (struct ref_store *)res;
}

Expand Down
5 changes: 1 addition & 4 deletions refs/files-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ static struct ref_store *files_ref_store_create(struct repository *repo,
struct ref_store *ref_store = (struct ref_store *)refs;
struct strbuf sb = STRBUF_INIT;

ref_store->repo = repo;
ref_store->gitdir = xstrdup(gitdir);
base_ref_store_init(ref_store, &refs_be_files);
base_ref_store_init(ref_store, repo, gitdir, &refs_be_files);
refs->store_flags = flags;

get_common_dir_noenv(&sb, gitdir);
refs->gitcommondir = strbuf_detach(&sb, NULL);
refs->packed_ref_store =
Expand Down
6 changes: 2 additions & 4 deletions refs/packed-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,11 @@ struct ref_store *packed_ref_store_create(struct repository *repo,
struct ref_store *ref_store = (struct ref_store *)refs;
struct strbuf sb = STRBUF_INIT;

base_ref_store_init(ref_store, &refs_be_packed);
ref_store->repo = repo;
ref_store->gitdir = xstrdup(gitdir);
base_ref_store_init(ref_store, repo, gitdir, &refs_be_packed);
refs->store_flags = store_flags;

strbuf_addf(&sb, "%s/packed-refs", gitdir);
refs->path = strbuf_detach(&sb, NULL);

chdir_notify_reparent("packed-refs", &refs->path);
return ref_store;
}
Expand Down
4 changes: 2 additions & 2 deletions refs/refs-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,8 @@ int parse_loose_ref_contents(const char *buf, struct object_id *oid,
* Fill in the generic part of refs and add it to our collection of
* reference stores.
*/
void base_ref_store_init(struct ref_store *refs,
const struct ref_storage_be *be);
void base_ref_store_init(struct ref_store *refs, struct repository *repo,
const char *path, const struct ref_storage_be *be);

/*
* Support GIT_TRACE_REFS by optionally wrapping the given ref_store instance.
Expand Down

0 comments on commit f9f7fd3

Please sign in to comment.