summaryrefslogtreecommitdiff
path: root/refs/files-backend.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2022-03-01 09:33:46 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-03-01 18:13:46 (GMT)
commitcd475b3b03809b1b1c664e0dca9f16f815456719 (patch)
tree790f4b5cace267e3cbd1ae9c08bb3541cec91f88 /refs/files-backend.c
parent8e55634b47858f036ca773f3e1d754e5dbd4bb59 (diff)
downloadgit-cd475b3b03809b1b1c664e0dca9f16f815456719.zip
git-cd475b3b03809b1b1c664e0dca9f16f815456719.tar.gz
git-cd475b3b03809b1b1c664e0dca9f16f815456719.tar.bz2
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>
Diffstat (limited to 'refs/files-backend.c')
-rw-r--r--refs/files-backend.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index f59589d..f3428a9 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -3286,6 +3286,7 @@ struct ref_storage_be refs_be_files = {
files_ref_iterator_begin,
files_read_raw_ref,
+ NULL,
files_reflog_iterator_begin,
files_for_each_reflog_ent,