git-prompt: stop manually parsing HEAD with unknown ref formats
commitfc134b41ce2ee7b2a98a988db6eeb109e11a2831
authorPatrick Steinhardt <ps@pks.im>
Thu, 4 Jan 2024 08:21:53 +0000 (4 09:21 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 Jan 2024 19:21:45 +0000 (8 11:21 -0800)
tree1313f3300355c18c88533443dd6bd89a5eff41d1
parent4081d45d7f01ff50853ef66fb2579f0d64f13bb9
git-prompt: stop manually parsing HEAD with unknown ref formats

We're manually parsing the HEAD reference in git-prompt to figure out
whether it is a symbolic or direct reference. This makes it intimately
tied to the on-disk format we use to store references and will stop
working once we gain additional reference backends in the Git project.

Ideally, we would refactor the code to exclusively use plumbing tools to
read refs such that we do not have to care about the on-disk format at
all. Unfortunately though, spawning processes can be quite expensive on
some systems like Windows. As the Git prompt logic may be executed quite
frequently we try very hard to spawn as few processes as possible. This
refactoring is thus out of question for now.

Instead, condition the logic on the repository's ref format: if the repo
uses the the "files" backend we can continue to use the old logic and
read the respective files from disk directly. If it's anything else,
then we use git-symbolic-ref(1) to read the value of HEAD.

This change makes the Git prompt compatible with the upcoming "reftable"
format.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-prompt.sh