Skip to content

Commit df1b071

Browse files
jltoblergitster
authored andcommitted
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>
1 parent 67cecc6 commit df1b071

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

builtin/repo.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ static void stats_table_setup_structure(struct stats_table *table,
324324
struct ref_stats *refs = &stats->refs;
325325
size_t inflated_object_total;
326326
size_t object_count_total;
327+
size_t disk_object_total;
327328
size_t ref_total;
328329

329330
ref_total = get_total_reference_count(refs);
@@ -358,6 +359,18 @@ static void stats_table_setup_structure(struct stats_table *table,
358359
" * %s", _("Blobs"));
359360
stats_table_size_addf(table, objects->inflated_sizes.tags,
360361
" * %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"));
361374
}
362375

363376
static void stats_table_print_structure(const struct stats_table *table)

t/t1901-repo-structure.sh

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@ test_description='test git repo structure'
55
. ./test-lib.sh
66

77
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
1022
}
1123

1224
test_expect_success 'empty repository' '
@@ -35,6 +47,11 @@ test_expect_success 'empty repository' '
3547
| * Trees | 0 B |
3648
| * Blobs | 0 B |
3749
| * Tags | 0 B |
50+
| * Disk size | 0 B |
51+
| * Commits | 0 B |
52+
| * Trees | 0 B |
53+
| * Blobs | 0 B |
54+
| * Tags | 0 B |
3855
EOF
3956
4057
git repo structure >out 2>err &&
@@ -58,7 +75,10 @@ test_expect_success SHA1 'repository with references and objects' '
5875
# Also creates a commit, tree, and blob.
5976
git notes add -m foo &&
6077
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 &&
6282
| Repository structure | Value |
6383
| -------------------- | ---------- |
6484
| * References | |
@@ -79,6 +99,11 @@ test_expect_success SHA1 'repository with references and objects' '
7999
| * Trees | 15.81 MiB |
80100
| * Blobs | 11.68 KiB |
81101
| * 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 |
82107
EOF
83108
84109
git repo structure >out 2>err &&

0 commit comments

Comments
 (0)