builtin/repo: group per-type object values into struct
The `object_stats` structure stores object counts by type. In a subsequent commit, additional per-type object measurements will also be stored. Group per-type object values into a new struct to allow better reuse. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Justin Tobler committed
Dec 17, 2025 at 11:53 UTC
9faaf254ba061e9fc7065f4c940c9dfcc51e6bbe
1 file changed
+25
-17
builtin/repo.c
+25
-17
@@ -202,13 +202,17 @@ struct ref_stats {
202
size_t others;
203
};
204
205
-struct object_stats {
205
+struct object_values {
206
size_t tags;
207
size_t commits;
208
size_t trees;
209
size_t blobs;
210
};
211
212
+struct object_stats {
213
+ struct object_values type_counts;
214
+};
215
+
216
struct repo_structure {
217
struct ref_stats refs;
218
struct object_stats objects;
@@ -281,9 +285,9 @@ static inline size_t get_total_reference_count(struct ref_stats *stats)
285
return stats->branches + stats->remotes + stats->tags + stats->others;
286
}
287
284
-static inline size_t get_total_object_count(struct object_stats *stats)
288
+static inline size_t get_total_object_values(struct object_values *values)
289
{
286
- return stats->tags + stats->commits + stats->trees + stats->blobs;
290
+ return values->tags + values->commits + values->trees + values->blobs;
291
}
292
293
static void stats_table_setup_structure(struct stats_table *table,
@@ -302,14 +306,18 @@ static void stats_table_setup_structure(struct stats_table *table,
306
stats_table_count_addf(table, refs->remotes, " * %s", _("Remotes"));
307
stats_table_count_addf(table, refs->others, " * %s", _("Others"));
308
305
- object_total = get_total_object_count(objects);
309
+ object_total = get_total_object_values(&objects->type_counts);
310
stats_table_addf(table, "");
311
stats_table_addf(table, "* %s", _("Reachable objects"));
312
stats_table_count_addf(table, object_total, " * %s", _("Count"));
309
- stats_table_count_addf(table, objects->commits, " * %s", _("Commits"));
310
- stats_table_count_addf(table, objects->trees, " * %s", _("Trees"));
311
- stats_table_count_addf(table, objects->blobs, " * %s", _("Blobs"));
312
- stats_table_count_addf(table, objects->tags, " * %s", _("Tags"));
313
+ stats_table_count_addf(table, objects->type_counts.commits,
314
+ " * %s", _("Commits"));
315
+ stats_table_count_addf(table, objects->type_counts.trees,
316
+ " * %s", _("Trees"));
317
+ stats_table_count_addf(table, objects->type_counts.blobs,
318
+ " * %s", _("Blobs"));
319
+ stats_table_count_addf(table, objects->type_counts.tags,
320
+ " * %s", _("Tags"));
321
}
322
323
static void stats_table_print_structure(const struct stats_table *table)
@@ -389,13 +397,13 @@ static void structure_keyvalue_print(struct repo_structure *stats,
397
(uintmax_t)stats->refs.others, value_delim);
398
399
printf("objects.commits.count%c%" PRIuMAX "%c", key_delim,
392
- (uintmax_t)stats->objects.commits, value_delim);
400
+ (uintmax_t)stats->objects.type_counts.commits, value_delim);
401
printf("objects.trees.count%c%" PRIuMAX "%c", key_delim,
394
- (uintmax_t)stats->objects.trees, value_delim);
402
+ (uintmax_t)stats->objects.type_counts.trees, value_delim);
403
printf("objects.blobs.count%c%" PRIuMAX "%c", key_delim,
396
- (uintmax_t)stats->objects.blobs, value_delim);
404
+ (uintmax_t)stats->objects.type_counts.blobs, value_delim);
405
printf("objects.tags.count%c%" PRIuMAX "%c", key_delim,
398
- (uintmax_t)stats->objects.tags, value_delim);
406
+ (uintmax_t)stats->objects.type_counts.tags, value_delim);
407
408
fflush(stdout);
409
}
@@ -473,22 +481,22 @@ static int count_objects(const char *path UNUSED, struct oid_array *oids,
481
482
switch (type) {
483
case OBJ_TAG:
476
- stats->tags += oids->nr;
484
+ stats->type_counts.tags += oids->nr;
485
break;
486
case OBJ_COMMIT:
479
- stats->commits += oids->nr;
487
+ stats->type_counts.commits += oids->nr;
488
break;
489
case OBJ_TREE:
482
- stats->trees += oids->nr;
490
+ stats->type_counts.trees += oids->nr;
491
break;
492
case OBJ_BLOB:
485
- stats->blobs += oids->nr;
493
+ stats->type_counts.blobs += oids->nr;
494
break;
495
default:
496
BUG("invalid object type");
497
}
498
491
- object_count = get_total_object_count(stats);
499
+ object_count = get_total_object_values(&stats->type_counts);
500
display_progress(data->progress, object_count);
501
502
return 0;