]> git.ipfire.org Git - thirdparty/git.git/commit - refs/refs-internal.h
refs: add ability for backends to special-case reading of symbolic refs
authorPatrick Steinhardt <ps@pks.im>
Tue, 1 Mar 2022 09:33:46 +0000 (10:33 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 1 Mar 2022 18:13:46 +0000 (10:13 -0800)
commitcd475b3b03809b1b1c664e0dca9f16f815456719
tree790f4b5cace267e3cbd1ae9c08bb3541cec91f88
parent8e55634b47858f036ca773f3e1d754e5dbd4bb59
refs: add ability for backends to special-case reading of symbolic refs

Reading of symbolic and non-symbolic references is currently treated the
same in reference backends: we always call `refs_read_raw_ref()` and
then decide based on the returned flags what type it is. This has one
downside though: symbolic references may be treated different from
normal references in a backend from normal references. The packed-refs
backend for example doesn't even know about symbolic references, and as
a result it is pointless to even ask it for one.

There are cases where we really only care about whether a reference is
symbolic or not, but don't care about whether it exists at all or may be
a non-symbolic reference. But it is not possible to optimize for this
case right now, and as a consequence we will always first check for a
loose reference to exist, and if it doesn't, we'll query the packed-refs
backend for a known-to-not-be-symbolic reference. This is inefficient
and requires us to search all packed references even though we know to
not care for the result at all.

Introduce a new function `refs_read_symbolic_ref()` which allows us to
fix this case. This function will only ever return symbolic references
and can thus optimize for the scenario layed out above. By default, if
the backend doesn't provide an implementation for it, we just use the
old code path and fall back to `read_raw_ref()`. But in case the backend
provides its own, more efficient implementation, we will use that one
instead.

Note that this function is explicitly designed to not distinguish
between missing references and non-symbolic references. If it did, we'd
be forced to always search the packed-refs backend to see whether the
symbolic reference the user asked for really doesn't exist, or if it
exists as a non-symbolic reference.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
refs.h
refs/debug.c
refs/files-backend.c
refs/packed-backend.c
refs/refs-internal.h