]> git.ipfire.org Git - thirdparty/git.git/commit
worktree: don't store main worktree twice
authorPatrick Steinhardt <ps@pks.im>
Thu, 6 Jun 2024 05:29:34 +0000 (07:29 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 6 Jun 2024 16:04:33 +0000 (09:04 -0700)
commit1339cb3c47aafb08a51d2517fcbaed2954d7d127
tree5ed51c26c3de0b3b4bc56d6c723611049ca214fa
parentb5d7db9e83e16cad6fb2a055029a8d1c72af04c9
worktree: don't store main worktree twice

In `get_worktree_ref_store()` we either return the repository's main ref
store, or we look up the ref store via the map of worktree ref stores.
Which of these worktrees gets picked depends on the `is_current` bit of
the worktree, which indicates whether the worktree is the one that
corresponds to `the_repository`.

The bit is getting set in `get_worktrees()`, but only after we have
computed the list of all worktrees. This is too late though, because at
that time we have already called `get_worktree_ref_store()` on each of
the worktrees via `add_head_info()`. The consequence is that the current
worktree will not have been marked accordingly, which means that we did
not use the main ref store, but instead created a new ref store. We thus
have two separate ref stores now that map to the same ref database.

Fix this by setting `is_current` before we call `add_head_info()`.

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