diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-01-08 10:05:35 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-01-08 21:17:30 (GMT) |
commit | 2eb1d0c45271faf149a13b61bb74af52abd7b3aa (patch) | |
tree | d1e19a1d3f8066a0e0ae0f6ba66a91d1ff062444 /refs/files-backend.c | |
parent | c358d165f2a4b3176b527e18c207105f6821335e (diff) | |
download | git-2eb1d0c45271faf149a13b61bb74af52abd7b3aa.zip git-2eb1d0c45271faf149a13b61bb74af52abd7b3aa.tar.gz git-2eb1d0c45271faf149a13b61bb74af52abd7b3aa.tar.bz2 |
refs/files: skip creation of "refs/{heads,tags}" for worktrees
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs/files-backend.c')
-rw-r--r-- | refs/files-backend.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c index 054ecdb..6dae37e 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; |