]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb: add `source` field to struct object_info_source
authorPatrick Steinhardt <ps@pks.im>
Wed, 24 Jun 2026 12:19:16 +0000 (14:19 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Jun 2026 17:12:35 +0000 (10:12 -0700)
The previous commit introduced `struct object_info_source` as an opt-in
container for backend-specific information, but for now we only moved
preexisting data into this structure. Most importantly, the caller has
no way yet to learn about which source an object was actually looked up
from. Instead, callers have to rely on the `whence` enum to distinguish
the object type, but cannot use that enum to tell the object source.

Add a `struct odb_source *source` field to the structure and populate it
from each backend's lookup path.

The `whence` enum is still set and used by callers; it will be removed
in a subsequent commit now that `sourcep->source` can identify the
backend on its own.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
odb.h
odb/source-inmemory.c
odb/source-loose.c
packfile.c

diff --git a/odb.h b/odb.h
index 770900289ab2170fe11357e363eab2078b97a065..330a55879ed772431646ab28ab89ab21d4b1792b 100644 (file)
--- a/odb.h
+++ b/odb.h
@@ -253,6 +253,9 @@ int odb_pretend_object(struct object_database *odb,
  * more about how exactly it is stored.
  */
 struct object_info_source {
+       /* The source that this object has been looked up from. */
+       struct odb_source *source;
+
        /*
         * Backend-specific information about the specific object. This can be
         * used for example to uniquely identify a given object in case it
index e004566d768b01c62163c9cfef34a664ba102a56..2328e62687bf4903f3c09b2ba8b1a424ceddbfff 100644 (file)
@@ -52,6 +52,9 @@ static void populate_object_info(struct odb_source_inmemory *source,
                *oi->contentp = xmemdupz(object->buf, object->size);
        if (oi->mtimep)
                *oi->mtimep = 0;
+       if (oi->sourcep)
+               oi->sourcep->source = &source->base;
+
        oi->whence = OI_CACHED;
 }
 
index 66e6bb8d3f800451d68a9cafddd7d267754f0993..5c4e9892b51bc682d90c0cdcae2ca5ae11c19eca 100644 (file)
@@ -196,6 +196,8 @@ out:
                        oi->typep = NULL;
                if (oi->delta_base_oid)
                        oidclr(oi->delta_base_oid, loose->base.odb->repo->hash_algo);
+               if (oi->sourcep && !ret)
+                       oi->sourcep->source = &loose->base;
                if (!ret)
                        oi->whence = OI_LOOSE;
        }
index 688c410b35fc251dce7d679453ebdcab73cb95ea..fa22095b757697dfbb84e89befb46111f4d349c3 100644 (file)
@@ -1324,7 +1324,7 @@ static void add_delta_base_cache(struct packed_git *p, off_t base_offset,
        hashmap_add(&delta_base_cache, &ent->ent);
 }
 
-int packed_object_info_with_index_pos(struct odb_source_packed *source UNUSED,
+int packed_object_info_with_index_pos(struct odb_source_packed *source,
                                      struct packed_git *p, off_t obj_offset,
                                      uint32_t *maybe_index_pos, struct object_info *oi)
 {
@@ -1424,6 +1424,10 @@ int packed_object_info_with_index_pos(struct odb_source_packed *source UNUSED,
        oi->whence = OI_PACKED;
 
        if (oi->sourcep) {
+               if (!source)
+                       BUG("cannot request source without an owning source");
+               oi->sourcep->source = &source->base;
+
                oi->sourcep->u.packed.offset = obj_offset;
                oi->sourcep->u.packed.pack = p;