Skip to content

Commit 2eb1d0c

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c358d16 commit 2eb1d0c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

refs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ int should_autocreate_reflog(const char *refname);
126126

127127
int is_branch(const char *refname);
128128

129+
#define REFS_INIT_DB_IS_WORKTREE (1 << 0)
130+
129131
int refs_init_db(struct ref_store *refs, int flags, struct strbuf *err);
130132

131133
/*

refs/files-backend.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,7 +3221,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
32213221
}
32223222

32233223
static int files_init_db(struct ref_store *ref_store,
3224-
int flags UNUSED,
3224+
int flags,
32253225
struct strbuf *err UNUSED)
32263226
{
32273227
struct files_ref_store *refs =
@@ -3245,15 +3245,21 @@ static int files_init_db(struct ref_store *ref_store,
32453245
adjust_shared_perm(sb.buf);
32463246

32473247
/*
3248-
* Create .git/refs/{heads,tags}
3248+
* There is no need to create directories for common refs when creating
3249+
* a worktree ref store.
32493250
*/
3250-
strbuf_reset(&sb);
3251-
files_ref_path(refs, &sb, "refs/heads");
3252-
safe_create_dir(sb.buf, 1);
3251+
if (!(flags & REFS_INIT_DB_IS_WORKTREE)) {
3252+
/*
3253+
* Create .git/refs/{heads,tags}
3254+
*/
3255+
strbuf_reset(&sb);
3256+
files_ref_path(refs, &sb, "refs/heads");
3257+
safe_create_dir(sb.buf, 1);
32533258

3254-
strbuf_reset(&sb);
3255-
files_ref_path(refs, &sb, "refs/tags");
3256-
safe_create_dir(sb.buf, 1);
3259+
strbuf_reset(&sb);
3260+
files_ref_path(refs, &sb, "refs/tags");
3261+
safe_create_dir(sb.buf, 1);
3262+
}
32573263

32583264
strbuf_release(&sb);
32593265
return 0;

0 commit comments

Comments
 (0)