builtin/repo: update stats for each object

When walking reachable objects in the repository, `count_objects()` processes a set of objects and updates the `struct object_stats`. In preparation for more granular statistics being collected, update the `struct object_stats` for each individual object instead. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Justin Tobler committed Mar 2, 2026 at 15:45 UTC 31c771ab443352741ecc3710d54a91890a68ee79
1 file changed +24 -29
builtin/repo.c
+24 -29
@@ -558,8 +558,6 @@ static int count_objects(const char *path UNUSED, struct oid_array *oids,
558 {
559 struct count_objects_data *data = cb_data;
560 struct object_stats *stats = data->stats;
561 - size_t inflated_total = 0;
562 - size_t disk_total = 0;
561 size_t object_count;
562
563 for (size_t i = 0; i < oids->nr; i++) {
@@ -575,33 +573,30 @@ static int count_objects(const char *path UNUSED, struct oid_array *oids,
573 OBJECT_INFO_QUICK) < 0)
574 continue;
575
578 - inflated_total += inflated;
579 - disk_total += disk;
580 - }
581 -
582 - switch (type) {
583 - case OBJ_TAG:
584 - stats->type_counts.tags += oids->nr;
585 - stats->inflated_sizes.tags += inflated_total;
586 - stats->disk_sizes.tags += disk_total;
587 - break;
588 - case OBJ_COMMIT:
589 - stats->type_counts.commits += oids->nr;
590 - stats->inflated_sizes.commits += inflated_total;
591 - stats->disk_sizes.commits += disk_total;
592 - break;
593 - case OBJ_TREE:
594 - stats->type_counts.trees += oids->nr;
595 - stats->inflated_sizes.trees += inflated_total;
596 - stats->disk_sizes.trees += disk_total;
597 - break;
598 - case OBJ_BLOB:
599 - stats->type_counts.blobs += oids->nr;
600 - stats->inflated_sizes.blobs += inflated_total;
601 - stats->disk_sizes.blobs += disk_total;
602 - break;
603 - default:
604 - BUG("invalid object type");
576 + switch (type) {
577 + case OBJ_TAG:
578 + stats->type_counts.tags++;
579 + stats->inflated_sizes.tags += inflated;
580 + stats->disk_sizes.tags += disk;
581 + break;
582 + case OBJ_COMMIT:
583 + stats->type_counts.commits++;
584 + stats->inflated_sizes.commits += inflated;
585 + stats->disk_sizes.commits += disk;
586 + break;
587 + case OBJ_TREE:
588 + stats->type_counts.trees++;
589 + stats->inflated_sizes.trees += inflated;
590 + stats->disk_sizes.trees += disk;
591 + break;
592 + case OBJ_BLOB:
593 + stats->type_counts.blobs++;
594 + stats->inflated_sizes.blobs += inflated;
595 + stats->disk_sizes.blobs += disk;
596 + break;
597 + default:
598 + BUG("invalid object type");
599 + }
600 }
601
602 object_count = get_total_object_values(&stats->type_counts);