builtin/repo: add object disk size info to structure table
Similar to a prior commit, update the table output format for the git-repo(1) structure command to display the total object disk usage by object type. 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:54 UTC
df1b071fedfddc322fa2a5e0f71d23cb05949d6f
2 files changed
+41
-3
builtin/repo.c
+13
@@ -324,6 +324,7 @@ static void stats_table_setup_structure(struct stats_table *table,
324
struct ref_stats *refs = &stats->refs;
325
size_t inflated_object_total;
326
size_t object_count_total;
327
+ size_t disk_object_total;
328
size_t ref_total;
329
330
ref_total = get_total_reference_count(refs);
@@ -358,6 +359,18 @@ static void stats_table_setup_structure(struct stats_table *table,
359
" * %s", _("Blobs"));
360
stats_table_size_addf(table, objects->inflated_sizes.tags,
361
" * %s", _("Tags"));
362
+
363
+ disk_object_total = get_total_object_values(&objects->disk_sizes);
364
+ stats_table_size_addf(table, disk_object_total,
365
+ " * %s", _("Disk size"));
366
+ stats_table_size_addf(table, objects->disk_sizes.commits,
367
+ " * %s", _("Commits"));
368
+ stats_table_size_addf(table, objects->disk_sizes.trees,
369
+ " * %s", _("Trees"));
370
+ stats_table_size_addf(table, objects->disk_sizes.blobs,
371
+ " * %s", _("Blobs"));
372
+ stats_table_size_addf(table, objects->disk_sizes.tags,
373
+ " * %s", _("Tags"));
374
}
375
376
static void stats_table_print_structure(const struct stats_table *table)
t/t1901-repo-structure.sh
+28
-3
@@ -5,8 +5,20 @@ test_description='test git repo structure'
5
. ./test-lib.sh
6
7
object_type_disk_usage() {
8
- git rev-list --all --objects --disk-usage --filter=object:type=$1 \
9
- --filter-provided-objects
8
+ disk_usage_opt="--disk-usage"
9
+
10
+ if test "$2" = "true"
11
+ then
12
+ disk_usage_opt="--disk-usage=human"
13
+ fi
14
+
15
+ if test "$1" = "all"
16
+ then
17
+ git rev-list --all --objects $disk_usage_opt
18
+ else
19
+ git rev-list --all --objects $disk_usage_opt \
20
+ --filter=object:type=$1 --filter-provided-objects
21
+ fi
22
}
23
24
test_expect_success 'empty repository' '
@@ -35,6 +47,11 @@ test_expect_success 'empty repository' '
47
| * Trees | 0 B |
48
| * Blobs | 0 B |
49
| * Tags | 0 B |
50
+ | * Disk size | 0 B |
51
+ | * Commits | 0 B |
52
+ | * Trees | 0 B |
53
+ | * Blobs | 0 B |
54
+ | * Tags | 0 B |
55
EOF
56
57
git repo structure >out 2>err &&
@@ -58,7 +75,10 @@ test_expect_success SHA1 'repository with references and objects' '
75
# Also creates a commit, tree, and blob.
76
git notes add -m foo &&
77
61
- cat >expect <<-\EOF &&
78
+ # The tags disk size is handled specially due to the
79
+ # git-rev-list(1) --disk-usage=human option printing the full
80
+ # "byte/bytes" unit string instead of just "B".
81
+ cat >expect <<-EOF &&
82
| Repository structure | Value |
83
| -------------------- | ---------- |
84
| * References | |
@@ -79,6 +99,11 @@ test_expect_success SHA1 'repository with references and objects' '
99
| * Trees | 15.81 MiB |
100
| * Blobs | 11.68 KiB |
101
| * Tags | 132 B |
102
+ | * Disk size | $(object_type_disk_usage all true) |
103
+ | * Commits | $(object_type_disk_usage commit true) |
104
+ | * Trees | $(object_type_disk_usage tree true) |
105
+ | * Blobs | $(object_type_disk_usage blob true) |
106
+ | * Tags | $(object_type_disk_usage tag) B |
107
EOF
108
109
git repo structure >out 2>err &&