git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Han-Wen Nienhuys via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Han-Wen Nienhuys <hanwenn@gmail.com>,
	Han-Wen Nienhuys <hanwen@google.com>
Subject: [PATCH v2 3/3] refs: centralize initialization of the base ref_store.
Date: Wed, 22 Dec 2021 18:11:54 +0000	[thread overview]
Message-ID: <eea294b688f984f9218db7c6d96a6b7c75d7873a.1640196714.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1163.v2.git.git.1640196714.gitgitgadget@gmail.com>

From: Han-Wen Nienhuys <hanwen@google.com>

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
 refs.c                | 6 ++++--
 refs/debug.c          | 3 ++-
 refs/files-backend.c  | 5 +----
 refs/packed-backend.c | 6 ++----
 refs/refs-internal.h  | 4 ++--
 5 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/refs.c b/refs.c
index 4c317955813..f91edb73075 100644
--- a/refs.c
+++ b/refs.c
@@ -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 */
diff --git a/refs/debug.c b/refs/debug.c
index 8a6bb157ee6..2b0771ca53b 100644
--- a/refs/debug.c
+++ b/refs/debug.c
@@ -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;
 }
 
diff --git a/refs/files-backend.c b/refs/files-backend.c
index f1b66130dfb..5c6d49a267e 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -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 =
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index caa1957252a..d91a2018f60 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -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;
 }
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index 46a839539e3..7ff6fba4f0d 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -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.
-- 
gitgitgadget

  parent reply	other threads:[~2021-12-22 18:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-21 12:33 [PATCH 0/2] tweaks to refs/debug.c Han-Wen Nienhuys via GitGitGadget
2021-12-21 12:33 ` [PATCH 1/2] refs: print error message in debug output Han-Wen Nienhuys via GitGitGadget
2021-12-21 12:33 ` [PATCH 2/2] refs: set the repo in debug_ref_store.base Han-Wen Nienhuys via GitGitGadget
2021-12-22  5:58   ` Junio C Hamano
2021-12-22 18:13     ` Han-Wen Nienhuys
2021-12-22 18:11 ` [PATCH v2 0/3] tweaks to refs/debug.c Han-Wen Nienhuys via GitGitGadget
2021-12-22 18:11   ` [PATCH v2 1/3] refs: pass gitdir to packed_ref_store_create Han-Wen Nienhuys via GitGitGadget
2021-12-22 18:11   ` [PATCH v2 2/3] refs: print error message in debug output Han-Wen Nienhuys via GitGitGadget
2021-12-22 18:11   ` Han-Wen Nienhuys via GitGitGadget [this message]
2021-12-22 21:54   ` [PATCH v2 0/3] tweaks to refs/debug.c Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eea294b688f984f9218db7c6d96a6b7c75d7873a.1640196714.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=hanwen@google.com \
    --cc=hanwenn@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).