git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Karthik Nayak <karthik.188@gmail.com>,
	Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH v2 3/6] refs/files: skip creation of "refs/{heads,tags}" for worktrees
Date: Mon, 8 Jan 2024 11:05:35 +0100	[thread overview]
Message-ID: <9e99efeaa384286a51a34993fa47f5c42bd81fa0.1704705733.git.ps@pks.im> (raw)
In-Reply-To: <cover.1704705733.git.ps@pks.im>

[-- Attachment #1: Type: text/plain, Size: 2385 bytes --]

The files ref backend will create both "refs/heads" and "refs/tags" in
the Git directory. While this logic makes sense for normal repositories,
it does not for worktrees because those refs are "common" refs that
would always be contained in the main repository's ref database.

Introduce a new flag telling the backend that it is expected to create a
per-worktree ref database and skip creation of these dirs in the files
backend when the flag is set. No other backends (currently) need
worktree-specific logic, so this is the only required change to start
creating per-worktree ref databases via `refs_init_db()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 refs.h               |  2 ++
 refs/files-backend.c | 22 ++++++++++++++--------
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/refs.h b/refs.h
index 114caa272a..c2dfe451a1 100644
--- a/refs.h
+++ b/refs.h
@@ -126,6 +126,8 @@ int should_autocreate_reflog(const char *refname);
 
 int is_branch(const char *refname);
 
+#define REFS_INIT_DB_IS_WORKTREE (1 << 0)
+
 int refs_init_db(struct ref_store *refs, int flags, struct strbuf *err);
 
 /*
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 054ecdbca3..6dae37e351 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -3221,7 +3221,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
 }
 
 static int files_init_db(struct ref_store *ref_store,
-			 int flags UNUSED,
+			 int flags,
 			 struct strbuf *err UNUSED)
 {
 	struct files_ref_store *refs =
@@ -3245,15 +3245,21 @@ static int files_init_db(struct ref_store *ref_store,
 	adjust_shared_perm(sb.buf);
 
 	/*
-	 * Create .git/refs/{heads,tags}
+	 * There is no need to create directories for common refs when creating
+	 * a worktree ref store.
 	 */
-	strbuf_reset(&sb);
-	files_ref_path(refs, &sb, "refs/heads");
-	safe_create_dir(sb.buf, 1);
+	if (!(flags & REFS_INIT_DB_IS_WORKTREE)) {
+		/*
+		 * Create .git/refs/{heads,tags}
+		 */
+		strbuf_reset(&sb);
+		files_ref_path(refs, &sb, "refs/heads");
+		safe_create_dir(sb.buf, 1);
 
-	strbuf_reset(&sb);
-	files_ref_path(refs, &sb, "refs/tags");
-	safe_create_dir(sb.buf, 1);
+		strbuf_reset(&sb);
+		files_ref_path(refs, &sb, "refs/tags");
+		safe_create_dir(sb.buf, 1);
+	}
 
 	strbuf_release(&sb);
 	return 0;
-- 
2.43.GIT


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2024-01-08 10:05 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-28  9:59 [PATCH 0/6] worktree: initialize refdb via ref backends Patrick Steinhardt
2023-12-28  9:59 ` [PATCH 1/6] refs: prepare `refs_init_db()` for initializing worktree refs Patrick Steinhardt
2023-12-28  9:59 ` [PATCH 2/6] setup: move creation of "refs/" into the files backend Patrick Steinhardt
2024-01-02 13:23   ` Karthik Nayak
2024-01-03  8:33     ` Patrick Steinhardt
2023-12-28 10:00 ` [PATCH 3/6] refs/files: skip creation of "refs/{heads,tags}" for worktrees Patrick Steinhardt
2023-12-29 10:35   ` Eric Sunshine
2023-12-28 10:00 ` [PATCH 4/6] builtin/worktree: move setup of commondir file earlier Patrick Steinhardt
2023-12-28 10:00 ` [PATCH 5/6] worktree: expose interface to look up worktree by name Patrick Steinhardt
2023-12-28 10:00 ` [PATCH 6/6] builtin/worktree: create refdb via ref backend Patrick Steinhardt
2023-12-28 18:11 ` [PATCH 0/6] worktree: initialize refdb via ref backends Junio C Hamano
2023-12-28 19:57   ` Patrick Steinhardt
2024-01-08 10:05 ` [PATCH v2 " Patrick Steinhardt
2024-01-08 10:05   ` [PATCH v2 1/6] refs: prepare `refs_init_db()` for initializing worktree refs Patrick Steinhardt
2024-01-08 10:05   ` [PATCH v2 2/6] setup: move creation of "refs/" into the files backend Patrick Steinhardt
2024-01-08 10:05   ` Patrick Steinhardt [this message]
2024-01-08 10:05   ` [PATCH v2 4/6] builtin/worktree: move setup of commondir file earlier Patrick Steinhardt
2024-01-08 10:05   ` [PATCH v2 5/6] worktree: expose interface to look up worktree by name Patrick Steinhardt
2024-01-08 10:05   ` [PATCH v2 6/6] builtin/worktree: create refdb via ref backend Patrick Steinhardt
2024-01-16  9:17   ` [PATCH v2 0/6] worktree: initialize refdb via ref backends Karthik Nayak
2024-01-16 17:53     ` 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=9e99efeaa384286a51a34993fa47f5c42bd81fa0.1704705733.git.ps@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=karthik.188@gmail.com \
    --cc=sunshine@sunshineco.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).