Skip to content

Commit 3e11449

Browse files
jltoblergitster
authored andcommitted
builtin/repo: add inflated object info to keyvalue structure output
The structure subcommand for git-repo(1) outputs basic count information for objects and references. Extend this output to also provide information regarding total size of inflated objects by object type. For now, object size by object type info is only added to the keyvalue and nul output formats. In a subsequent commit, this info is also added to the table format. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5473132 commit 3e11449

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

Documentation/git-repo.adoc

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

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

builtin/repo.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "builtin.h"
44
#include "environment.h"
5+
#include "hex.h"
6+
#include "odb.h"
57
#include "parse-options.h"
68
#include "path-walk.h"
79
#include "progress.h"
@@ -211,6 +213,7 @@ struct object_values {
211213

212214
struct object_stats {
213215
struct object_values type_counts;
216+
struct object_values inflated_sizes;
214217
};
215218

216219
struct repo_structure {
@@ -423,6 +426,15 @@ static void structure_keyvalue_print(struct repo_structure *stats,
423426
printf("objects.tags.count%c%" PRIuMAX "%c", key_delim,
424427
(uintmax_t)stats->objects.type_counts.tags, value_delim);
425428

429+
printf("objects.commits.inflated_size%c%" PRIuMAX "%c", key_delim,
430+
(uintmax_t)stats->objects.inflated_sizes.commits, value_delim);
431+
printf("objects.trees.inflated_size%c%" PRIuMAX "%c", key_delim,
432+
(uintmax_t)stats->objects.inflated_sizes.trees, value_delim);
433+
printf("objects.blobs.inflated_size%c%" PRIuMAX "%c", key_delim,
434+
(uintmax_t)stats->objects.inflated_sizes.blobs, value_delim);
435+
printf("objects.tags.inflated_size%c%" PRIuMAX "%c", key_delim,
436+
(uintmax_t)stats->objects.inflated_sizes.tags, value_delim);
437+
426438
fflush(stdout);
427439
}
428440

@@ -486,6 +498,7 @@ static void structure_count_references(struct ref_stats *stats,
486498
}
487499

488500
struct count_objects_data {
501+
struct object_database *odb;
489502
struct object_stats *stats;
490503
struct progress *progress;
491504
};
@@ -495,20 +508,39 @@ static int count_objects(const char *path UNUSED, struct oid_array *oids,
495508
{
496509
struct count_objects_data *data = cb_data;
497510
struct object_stats *stats = data->stats;
511+
size_t inflated_total = 0;
498512
size_t object_count;
499513

514+
for (size_t i = 0; i < oids->nr; i++) {
515+
struct object_info oi = OBJECT_INFO_INIT;
516+
unsigned long inflated;
517+
518+
oi.sizep = &inflated;
519+
520+
if (odb_read_object_info_extended(data->odb, &oids->oid[i], &oi,
521+
OBJECT_INFO_SKIP_FETCH_OBJECT |
522+
OBJECT_INFO_QUICK) < 0)
523+
continue;
524+
525+
inflated_total += inflated;
526+
}
527+
500528
switch (type) {
501529
case OBJ_TAG:
502530
stats->type_counts.tags += oids->nr;
531+
stats->inflated_sizes.tags += inflated_total;
503532
break;
504533
case OBJ_COMMIT:
505534
stats->type_counts.commits += oids->nr;
535+
stats->inflated_sizes.commits += inflated_total;
506536
break;
507537
case OBJ_TREE:
508538
stats->type_counts.trees += oids->nr;
539+
stats->inflated_sizes.trees += inflated_total;
509540
break;
510541
case OBJ_BLOB:
511542
stats->type_counts.blobs += oids->nr;
543+
stats->inflated_sizes.blobs += inflated_total;
512544
break;
513545
default:
514546
BUG("invalid object type");
@@ -526,6 +558,7 @@ static void structure_count_objects(struct object_stats *stats,
526558
{
527559
struct path_walk_info info = PATH_WALK_INFO_INIT;
528560
struct count_objects_data data = {
561+
.odb = repo->objects,
529562
.stats = stats,
530563
};
531564

t/t1901-repo-structure.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ test_expect_success 'repository with references and objects' '
7373
)
7474
'
7575

76-
test_expect_success 'keyvalue and nul format' '
76+
test_expect_success SHA1 'keyvalue and nul format' '
7777
test_when_finished "rm -rf repo" &&
7878
git init repo &&
7979
(
@@ -90,6 +90,10 @@ test_expect_success 'keyvalue and nul format' '
9090
objects.trees.count=42
9191
objects.blobs.count=42
9292
objects.tags.count=1
93+
objects.commits.inflated_size=9225
94+
objects.trees.inflated_size=28554
95+
objects.blobs.inflated_size=453
96+
objects.tags.inflated_size=132
9397
EOF
9498
9599
git repo structure --format=keyvalue >out 2>err &&

0 commit comments

Comments
 (0)