]> git.ipfire.org Git - thirdparty/git.git/commit - refs.c
refs: introduce `is_pseudoref()` and `is_headref()`
authorKarthik Nayak <karthik.188@gmail.com>
Fri, 23 Feb 2024 10:01:08 +0000 (11:01 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 23 Feb 2024 18:36:27 +0000 (10:36 -0800)
commit1eba2240f8ba9f05a47d488bb62041c42c5d4b9c
tree668c291c97291a6c63471ffb198c0b7a4d60f090
parentc684b582bccde967473fd1aaff38a0becceec3d9
refs: introduce `is_pseudoref()` and `is_headref()`

Introduce two new functions `is_pseudoref()` and `is_headref()`. This
provides the necessary functionality for us to add pseudorefs and HEAD
to the loose ref cache in the files backend, allowing us to build
tooling to print these refs.

The `is_pseudoref()` function internally calls `is_pseudoref_syntax()`
but adds onto it by also checking to ensure that the pseudoref either
ends with a "_HEAD" suffix or matches a list of exceptions. After which
we also parse the contents of the pseudoref to ensure that it conforms
to the ref format.

We cannot directly add the new syntax checks to `is_pseudoref_syntax()`
because the function is also used by `is_current_worktree_ref()` and
making it stricter to match only known pseudorefs might have unintended
consequences due to files like 'BISECT_START' which isn't a pseudoref
but sometimes contains object ID.

Keeping this in mind, we leave `is_pseudoref_syntax()` as is and create
`is_pseudoref()` which is stricter. Ideally we'd want to move the new
syntax checks to `is_pseudoref_syntax()` but a prerequisite for this
would be to actually remove the exception list by converting those
pseudorefs to also contain a '_HEAD' suffix and perhaps move bisect
related files like 'BISECT_START' to a new directory similar to the
'rebase-merge' directory.

Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
refs.h