aboutsummaryrefslogtreecommitdiff
path: root/object-file.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-03-05 15:19:49 +0100
committerJunio C Hamano <gitster@pobox.com>2026-03-05 11:45:15 -0800
commit5946a564cddc0bf471f27ae4c3fe205441e3ef65 (patch)
tree17a06b3b4e5800c22d91eb90da5dd4a19512e3a9 /object-file.c
parent3bc3177ad7a472dd5fc45cff16b8f57e5800ebc2 (diff)
downloadgit-5946a564cddc0bf471f27ae4c3fe205441e3ef65.tar.xz
odb/source: make `read_object_info()` function pluggable
Introduce a new callback function in `struct odb_source` to make the function pluggable. Note that this function is a bit less straight-forward to convert compared to the other functions. The reason here is that the logic to read an object is: 1. We try to read the object. If it exists we return it. 2. If the object does not exist we reprepare the object database source. 3. We then try reading the object info a second time in case the reprepare caused it to appear. The second read is only supposed to happen for the packfile store though, as reading loose objects is not impacted by repreparing the object database. Ideally, we'd just move this whole logic into the ODB source. But that's not easily possible because we try to avoid the reprepare unless really required, which is after we have found out that no other ODB source contains the object, either. So the logic spans across multiple ODB sources, and consequently we cannot move it into an individual source. Instead, introduce a new flag `OBJECT_INFO_SECOND_READ` that tells the backend that we already tried to look up the object once, and that this time around the ODB source should try to find any new objects that may have surfaced due to an on-disk change. With this flag, the "files" backend can trivially skip trying to re-read the object as a loose object. Furthermore, as we know that we only try the second read via the packfile store, we can skip repreparing loose objects and only reprepare the packfile store. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object-file.c')
-rw-r--r--object-file.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/object-file.c b/object-file.c
index 7ef8291a48..eefde72c7d 100644
--- a/object-file.c
+++ b/object-file.c
@@ -546,6 +546,16 @@ int odb_source_loose_read_object_info(struct odb_source *source,
enum object_info_flags flags)
{
static struct strbuf buf = STRBUF_INIT;
+
+ /*
+ * The second read shouldn't cause new loose objects to show up, unless
+ * there was a race condition with a secondary process. We don't care
+ * about this case though, so we simply skip reading loose objects a
+ * second time.
+ */
+ if (flags & OBJECT_INFO_SECOND_READ)
+ return -1;
+
odb_loose_path(source, &buf, oid);
return read_object_info_from_path(source, buf.buf, oid, oi, flags);
}