]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/worktree: create refdb via ref backend
authorPatrick Steinhardt <ps@pks.im>
Mon, 8 Jan 2024 10:05:47 +0000 (11:05 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 Jan 2024 21:17:30 +0000 (13:17 -0800)
commit8f4c00de954f809e83daf8b1425de82561f3721e
treeb79337c854f2c6cc5b74a7a75d90820b0f3c376b
parentb8a846b2e03610e6f550d364c75e514532ef7adf
builtin/worktree: create refdb via ref backend

When creating a worktree we create the worktree's ref database manually
by first writing a "HEAD" file so that the directory is recognized as a
Git repository by other commands, and then running git-update-ref(1) or
git-symbolic-ref(1) to write the actual value. But while this is fine
for the files backend, this logic simply assumes too much about how the
ref backend works and will leave behind an invalid ref database once any
other ref backend lands.

Refactor the code to instead use `refs_init_db()` to initialize the ref
database so that git-worktree(1) itself does not need to know about how
to initialize it. This will allow future ref backends to customize how
the per-worktree ref database is set up. Furthermore, as we now already
have a worktree ref store around, we can also avoid spawning external
commands to write the HEAD reference and instead use the refs API to do
so.

Note that we do not have an equivalent to passing the `--quiet` flag to
git-symbolic-ref(1) as we did before. This flag does not have an effect
anyway though, as git-symbolic-ref(1) only honors it when reading a
symref, but never when writing one.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/worktree.c