]> git.ipfire.org Git - thirdparty/git.git/commitdiff
packfile: thread odb_source_packed through packed_object_info()
authorPatrick Steinhardt <ps@pks.im>
Wed, 24 Jun 2026 12:19:14 +0000 (14:19 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Jun 2026 17:12:35 +0000 (10:12 -0700)
Add an optional `struct odb_source_packed *source` parameter to
`packed_object_info()` and `packed_object_info_with_index_pos()`. This
parameter is unused at this point in time, but it will be used in a
follow-up commit so that we can record the source of a specific object.

Note that callers in "odb/source-packed.c" pass the already-available
source, but all other callers pass `NULL` instead. This is fine though,
as we only care about populating this info when called via the packed
store.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/cat-file.c
builtin/pack-objects.c
commit-graph.c
odb/source-packed.c
pack-bitmap.c
packfile.c
packfile.h
t/helper/test-bitmap.c

index 0f3dbd9850d2fa3c73b7d1873c6c7fd8bedafcb1..8726485f1fef5a3270007a3638f9f11668a4a95d 100644 (file)
@@ -497,7 +497,7 @@ static void batch_object_write(const char *obj_name,
                        data->info.sizep = &data->size;
 
                if (pack)
-                       ret = packed_object_info(pack, offset, &data->info);
+                       ret = packed_object_info(NULL, pack, offset, &data->info);
                else
                        ret = odb_read_object_info_extended(the_repository->objects,
                                                            &data->oid, &data->info,
index bc5f9ef3218a2f03e236e9505e5f3a154dec0638..620d9ce08508ccf94a00a1bc9471ec95dfce3bfa 100644 (file)
@@ -2463,7 +2463,7 @@ static void drop_reused_delta(struct object_entry *entry)
 
        oi.sizep = &size;
        oi.typep = &type;
-       if (packed_object_info(IN_PACK(entry), entry->in_pack_offset, &oi) < 0) {
+       if (packed_object_info(NULL, IN_PACK(entry), entry->in_pack_offset, &oi) < 0) {
                /*
                 * We failed to get the info from this pack for some reason;
                 * fall back to odb_read_object_info, which may find another copy.
@@ -3804,7 +3804,7 @@ static int add_object_entry_from_pack(const struct object_id *oid,
        ofs = nth_packed_object_offset(p, pos);
 
        oi.typep = &type;
-       if (packed_object_info(p, ofs, &oi) < 0) {
+       if (packed_object_info(NULL, p, ofs, &oi) < 0) {
                die(_("could not get type of object %s in pack %s"),
                    oid_to_hex(oid), p->pack_name);
        } else if (type == OBJ_COMMIT) {
index c6d9c5c740e94d3dd9d72100e5e2309fb9fb3476..9dc8bd5eee785fbd87771ed7c8a3b15f92464db7 100644 (file)
@@ -1538,7 +1538,7 @@ static int add_packed_commits(const struct object_id *oid,
        struct object_info oi = OBJECT_INFO_INIT;
 
        oi.typep = &type;
-       if (packed_object_info(pack, offset, &oi) < 0)
+       if (packed_object_info(NULL, pack, offset, &oi) < 0)
                die(_("unable to get type of object %s"), oid_to_hex(oid));
 
        return add_packed_commits_oi(oid, &oi, data);
index 42c28fba0e34b260d5e059b56acf11be6a56d63f..43fb53b72ddf2e80bae99fd4d4a284d59e324955 100644 (file)
@@ -59,7 +59,7 @@ static int odb_source_packed_read_object_info(struct odb_source *source,
        if (!oi)
                return 0;
 
-       ret = packed_object_info(e.p, e.offset, oi);
+       ret = packed_object_info(packed, e.p, e.offset, oi);
        if (ret < 0) {
                mark_bad_packed_object(e.p, oid);
                return -1;
@@ -99,7 +99,7 @@ static int odb_source_packed_for_each_object_wrapper(const struct object_id *oid
                off_t offset = nth_packed_object_offset(pack, index_pos);
                struct object_info oi = *data->request;
 
-               if (packed_object_info_with_index_pos(pack, offset,
+               if (packed_object_info_with_index_pos(data->store, pack, offset,
                                                      &index_pos, &oi) < 0) {
                        mark_bad_packed_object(pack, oid);
                        return -1;
index 83eb47a28ba9de44dfce1f52f5cca130c2552f98..35774b6f0c0da7bc64a0c5d553025effbe4c47af 100644 (file)
@@ -1877,7 +1877,7 @@ static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,
                        ofs = pack_pos_to_offset(pack, pos);
                }
 
-               if (packed_object_info(pack, ofs, &oi) < 0) {
+               if (packed_object_info(NULL, pack, ofs, &oi) < 0) {
                        struct object_id oid;
                        nth_bitmap_object_oid(bitmap_git, &oid,
                                              pack_pos_to_index(pack, pos));
index 1d1b23b6cc782fdf34580d7bf50819a8af075af8..2b741d7a7665e9804c13baf626edefeedf6618a5 100644 (file)
@@ -1324,7 +1324,8 @@ 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 packed_git *p, off_t obj_offset,
+int packed_object_info_with_index_pos(struct odb_source_packed *source UNUSED,
+                                     struct packed_git *p, off_t obj_offset,
                                      uint32_t *maybe_index_pos, struct object_info *oi)
 {
        struct pack_window *w_curs = NULL;
@@ -1446,10 +1447,11 @@ out:
        return ret;
 }
 
-int packed_object_info(struct packed_git *p, off_t obj_offset,
+int packed_object_info(struct odb_source_packed *source,
+                      struct packed_git *p, off_t obj_offset,
                       struct object_info *oi)
 {
-       return packed_object_info_with_index_pos(p, obj_offset, NULL, oi);
+       return packed_object_info_with_index_pos(source, p, obj_offset, NULL, oi);
 }
 
 static void *unpack_compressed_entry(struct packed_git *p,
index 2329a697014a6685f4e9f7de29267c19b050ef9f..e1f77152b5c4bfaf18809b6c629e1997f77666f2 100644 (file)
@@ -320,9 +320,11 @@ extern int do_check_packed_object_crc;
  * Look up the object info for a specific offset in the packfile.
  * Returns zero on success, a negative error code otherwise.
  */
-int packed_object_info(struct packed_git *pack,
+int packed_object_info(struct odb_source_packed *source,
+                      struct packed_git *pack,
                       off_t offset, struct object_info *);
-int packed_object_info_with_index_pos(struct packed_git *p, off_t obj_offset,
+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);
 
 void mark_bad_packed_object(struct packed_git *, const struct object_id *);
index b130832b81ecce5fde292e5a39206296d4ead89e..8547ef67e243ebe6858768f954e14adccbdd9f97 100644 (file)
@@ -52,7 +52,7 @@ static int add_packed_object(const struct object_id *oid,
 
        entry = packlist_alloc(packed, oid);
        entry->idx.offset = nth_packed_object_offset(pack, pos);
-       if (packed_object_info(pack, entry->idx.offset, &oi) < 0)
+       if (packed_object_info(NULL, pack, entry->idx.offset, &oi) < 0)
                die("could not get type of object %s",
                    oid_to_hex(oid));
        oe_set_type(entry, type);