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 1/3] refs: pass gitdir to packed_ref_store_create
Date: Wed, 22 Dec 2021 18:11:52 +0000	[thread overview]
Message-ID: <bfebb5f08fed835cedfd5373ba98c6e38519f882.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>

This is consistent with the calling convention for ref backend creation, and
avoids storing ".git/packed-refs" (the name of a regular file) in a variable called
ref_store::gitdir.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
 refs/files-backend.c  | 5 ++---
 refs/packed-backend.c | 9 +++++----
 refs/packed-backend.h | 2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index 90b671025a7..f1b66130dfb 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -93,9 +93,8 @@ static struct ref_store *files_ref_store_create(struct repository *repo,
 
 	get_common_dir_noenv(&sb, gitdir);
 	refs->gitcommondir = strbuf_detach(&sb, NULL);
-	strbuf_addf(&sb, "%s/packed-refs", refs->gitcommondir);
-	refs->packed_ref_store = packed_ref_store_create(repo, sb.buf, flags);
-	strbuf_release(&sb);
+	refs->packed_ref_store =
+		packed_ref_store_create(repo, refs->gitcommondir, flags);
 
 	chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir);
 	chdir_notify_reparent("files-backend $GIT_COMMONDIR",
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 67152c664e2..caa1957252a 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -194,20 +194,21 @@ static int release_snapshot(struct snapshot *snapshot)
 }
 
 struct ref_store *packed_ref_store_create(struct repository *repo,
-					  const char *path,
+					  const char *gitdir,
 					  unsigned int store_flags)
 {
 	struct packed_ref_store *refs = xcalloc(1, sizeof(*refs));
 	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(path);
+	ref_store->gitdir = xstrdup(gitdir);
 	refs->store_flags = store_flags;
+	strbuf_addf(&sb, "%s/packed-refs", gitdir);
+	refs->path = strbuf_detach(&sb, NULL);
 
-	refs->path = xstrdup(path);
 	chdir_notify_reparent("packed-refs", &refs->path);
-
 	return ref_store;
 }
 
diff --git a/refs/packed-backend.h b/refs/packed-backend.h
index f61a73ec25b..9dd8a344c34 100644
--- a/refs/packed-backend.h
+++ b/refs/packed-backend.h
@@ -14,7 +14,7 @@ struct ref_transaction;
  */
 
 struct ref_store *packed_ref_store_create(struct repository *repo,
-					  const char *path,
+					  const char *gitdir,
 					  unsigned int store_flags);
 
 /*
-- 
gitgitgadget


  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   ` Han-Wen Nienhuys via GitGitGadget [this message]
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   ` [PATCH v2 3/3] refs: centralize initialization of the base ref_store Han-Wen Nienhuys via GitGitGadget
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=bfebb5f08fed835cedfd5373ba98c6e38519f882.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).