object-file: treat cached_object values as const

The cached-object API maps oids to in-memory entries. Once inserted, these entries should be immutable. Let's return them from the find_cached_object() call with a const tag to make this clear. Suggested-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Nov 18, 2024 at 04:55 UTC e37feea00b2b81c0295fddb4f5137d12ea1825c0
1 file changed +4 -4
object-file.c
+4 -4
@@ -327,14 +327,14 @@ static struct cached_object_entry {
327 } *cached_objects;
328 static int cached_object_nr, cached_object_alloc;
329
330 -static struct cached_object *find_cached_object(const struct object_id *oid)
330 +static const struct cached_object *find_cached_object(const struct object_id *oid)
331 {
332 - static struct cached_object empty_tree = {
332 + static const struct cached_object empty_tree = {
333 .type = OBJ_TREE,
334 .buf = "",
335 };
336 int i;
337 - struct cached_object_entry *co = cached_objects;
337 + const struct cached_object_entry *co = cached_objects;
338
339 for (i = 0; i < cached_object_nr; i++, co++) {
340 if (oideq(&co->oid, oid))
@@ -1629,7 +1629,7 @@ static int do_oid_object_info_extended(struct repository *r,
1629 struct object_info *oi, unsigned flags)
1630 {
1631 static struct object_info blank_oi = OBJECT_INFO_INIT;
1632 - struct cached_object *co;
1632 + const struct cached_object *co;
1633 struct pack_entry e;
1634 int rtype;
1635 const struct object_id *real = oid;