Skip to content

Commit 67cecc6

Browse files
jltoblergitster
authored andcommitted
builtin/repo: add disk size info to keyvalue stucture output
Similar to a prior commit, extend the keyvalue and nul output formats of the git-repo(1) structure command to additionally provide info regarding total object disk sizes by object type. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4d279ae commit 67cecc6

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

Documentation/git-repo.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ supported:
5151
* Reference counts categorized by type
5252
* Reachable object counts categorized by type
5353
* Total inflated size of reachable objects by type
54+
* Total disk size of reachable objects by type
5455

5556
+
5657
The output format can be chosen through the flag `--format`. Three formats are

builtin/repo.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ struct object_values {
214214
struct object_stats {
215215
struct object_values type_counts;
216216
struct object_values inflated_sizes;
217+
struct object_values disk_sizes;
217218
};
218219

219220
struct repo_structure {
@@ -462,6 +463,15 @@ static void structure_keyvalue_print(struct repo_structure *stats,
462463
printf("objects.tags.inflated_size%c%" PRIuMAX "%c", key_delim,
463464
(uintmax_t)stats->objects.inflated_sizes.tags, value_delim);
464465

466+
printf("objects.commits.disk_size%c%" PRIuMAX "%c", key_delim,
467+
(uintmax_t)stats->objects.disk_sizes.commits, value_delim);
468+
printf("objects.trees.disk_size%c%" PRIuMAX "%c", key_delim,
469+
(uintmax_t)stats->objects.disk_sizes.trees, value_delim);
470+
printf("objects.blobs.disk_size%c%" PRIuMAX "%c", key_delim,
471+
(uintmax_t)stats->objects.disk_sizes.blobs, value_delim);
472+
printf("objects.tags.disk_size%c%" PRIuMAX "%c", key_delim,
473+
(uintmax_t)stats->objects.disk_sizes.tags, value_delim);
474+
465475
fflush(stdout);
466476
}
467477

@@ -536,38 +546,46 @@ static int count_objects(const char *path UNUSED, struct oid_array *oids,
536546
struct count_objects_data *data = cb_data;
537547
struct object_stats *stats = data->stats;
538548
size_t inflated_total = 0;
549+
size_t disk_total = 0;
539550
size_t object_count;
540551

541552
for (size_t i = 0; i < oids->nr; i++) {
542553
struct object_info oi = OBJECT_INFO_INIT;
543554
unsigned long inflated;
555+
off_t disk;
544556

545557
oi.sizep = &inflated;
558+
oi.disk_sizep = &disk;
546559

547560
if (odb_read_object_info_extended(data->odb, &oids->oid[i], &oi,
548561
OBJECT_INFO_SKIP_FETCH_OBJECT |
549562
OBJECT_INFO_QUICK) < 0)
550563
continue;
551564

552565
inflated_total += inflated;
566+
disk_total += disk;
553567
}
554568

555569
switch (type) {
556570
case OBJ_TAG:
557571
stats->type_counts.tags += oids->nr;
558572
stats->inflated_sizes.tags += inflated_total;
573+
stats->disk_sizes.tags += disk_total;
559574
break;
560575
case OBJ_COMMIT:
561576
stats->type_counts.commits += oids->nr;
562577
stats->inflated_sizes.commits += inflated_total;
578+
stats->disk_sizes.commits += disk_total;
563579
break;
564580
case OBJ_TREE:
565581
stats->type_counts.trees += oids->nr;
566582
stats->inflated_sizes.trees += inflated_total;
583+
stats->disk_sizes.trees += disk_total;
567584
break;
568585
case OBJ_BLOB:
569586
stats->type_counts.blobs += oids->nr;
570587
stats->inflated_sizes.blobs += inflated_total;
588+
stats->disk_sizes.blobs += disk_total;
571589
break;
572590
default:
573591
BUG("invalid object type");

t/t1901-repo-structure.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ test_description='test git repo structure'
44

55
. ./test-lib.sh
66

7+
object_type_disk_usage() {
8+
git rev-list --all --objects --disk-usage --filter=object:type=$1 \
9+
--filter-provided-objects
10+
}
11+
712
test_expect_success 'empty repository' '
813
test_when_finished "rm -rf repo" &&
914
git init repo &&
@@ -91,7 +96,7 @@ test_expect_success SHA1 'keyvalue and nul format' '
9196
test_commit_bulk 42 &&
9297
git tag -a foo -m bar &&
9398
94-
cat >expect <<-\EOF &&
99+
cat >expect <<-EOF &&
95100
references.branches.count=1
96101
references.tags.count=1
97102
references.remotes.count=0
@@ -104,6 +109,10 @@ test_expect_success SHA1 'keyvalue and nul format' '
104109
objects.trees.inflated_size=28554
105110
objects.blobs.inflated_size=453
106111
objects.tags.inflated_size=132
112+
objects.commits.disk_size=$(object_type_disk_usage commit)
113+
objects.trees.disk_size=$(object_type_disk_usage tree)
114+
objects.blobs.disk_size=$(object_type_disk_usage blob)
115+
objects.tags.disk_size=$(object_type_disk_usage tag)
107116
EOF
108117
109118
git repo structure --format=keyvalue >out 2>err &&

0 commit comments

Comments
 (0)