Skip to content

Commit e6e0266

Browse files
jltoblergitster
authored andcommitted
builtin/repo: find tree with most entries
The size of a tree object usually corresponds with the number of entries it has. While iterating through objects in the repository for git-repo-structure, identify the tree with the most entries and display it in the output. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent aa5b62a commit e6e0266

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

builtin/repo.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "strbuf.h"
1717
#include "string-list.h"
1818
#include "shallow.h"
19+
#include "tree.h"
20+
#include "tree-walk.h"
1921
#include "utf8.h"
2022

2123
static const char *const repo_usage[] = {
@@ -211,6 +213,7 @@ struct largest_objects {
211213
struct object_data blob_size;
212214

213215
struct object_data parent_count;
216+
struct object_data tree_entries;
214217
};
215218

216219
struct ref_stats {
@@ -458,6 +461,10 @@ static void stats_table_setup_structure(struct stats_table *table,
458461
&objects->largest.tree_size.oid,
459462
objects->largest.tree_size.value,
460463
" * %s", _("Maximum size"));
464+
stats_table_object_count_addf(table,
465+
&objects->largest.tree_entries.oid,
466+
objects->largest.tree_entries.value,
467+
" * %s", _("Maximum entries"));
461468
stats_table_addf(table, " * %s", _("Blobs"));
462469
stats_table_object_size_addf(table,
463470
&objects->largest.blob_size.oid,
@@ -619,6 +626,10 @@ static void structure_keyvalue_print(struct repo_structure *stats,
619626
(uintmax_t)stats->objects.largest.parent_count.value, value_delim);
620627
printf("objects.commits.max_parents_oid%c%s%c", key_delim,
621628
oid_to_hex(&stats->objects.largest.parent_count.oid), value_delim);
629+
printf("objects.trees.max_entries%c%" PRIuMAX "%c", key_delim,
630+
(uintmax_t)stats->objects.largest.tree_entries.value, value_delim);
631+
printf("objects.trees.max_entries_oid%c%s%c", key_delim,
632+
oid_to_hex(&stats->objects.largest.tree_entries.oid), value_delim);
622633

623634
fflush(stdout);
624635
}
@@ -697,6 +708,20 @@ static void check_largest(struct object_data *data, struct object_id *oid,
697708
}
698709
}
699710

711+
static size_t count_tree_entries(struct object *obj)
712+
{
713+
struct tree *t = object_as_type(obj, OBJ_TREE, 0);
714+
struct name_entry entry;
715+
struct tree_desc desc;
716+
size_t count = 0;
717+
718+
init_tree_desc(&desc, &t->object.oid, t->buffer, t->size);
719+
while (tree_entry(&desc, &entry))
720+
count++;
721+
722+
return count;
723+
}
724+
700725
static int count_objects(const char *path UNUSED, struct oid_array *oids,
701726
enum object_type type, void *cb_data)
702727
{
@@ -749,6 +774,8 @@ static int count_objects(const char *path UNUSED, struct oid_array *oids,
749774
stats->disk_sizes.trees += disk;
750775
check_largest(&stats->largest.tree_size, &oids->oid[i],
751776
inflated);
777+
check_largest(&stats->largest.tree_entries, &oids->oid[i],
778+
count_tree_entries(obj));
752779
break;
753780
case OBJ_BLOB:
754781
stats->type_counts.blobs++;

t/t1901-repo-structure.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ test_expect_success 'empty repository' '
5959
| * Maximum parents | 0 |
6060
| * Trees | |
6161
| * Maximum size | 0 B |
62+
| * Maximum entries | 0 |
6263
| * Blobs | |
6364
| * Maximum size | 0 B |
6465
| * Tags | |
@@ -122,16 +123,18 @@ test_expect_success SHA1 'repository with references and objects' '
122123
| * Maximum parents [2] | 1 |
123124
| * Trees | |
124125
| * Maximum size [3] | 32.29 KiB |
126+
| * Maximum entries [4] | 1.01 k |
125127
| * Blobs | |
126-
| * Maximum size [4] | 13 B |
128+
| * Maximum size [5] | 13 B |
127129
| * Tags | |
128-
| * Maximum size [5] | 132 B |
130+
| * Maximum size [6] | 132 B |
129131
130132
[1] 0dc91eb18580102a3a216c8bfecedeba2b9f9b9a
131133
[2] 0dc91eb18580102a3a216c8bfecedeba2b9f9b9a
132134
[3] 60665251ab71dbd8c18d9bf2174f4ee0d58aa06c
133-
[4] 97d808e45116bf02103490294d3d46dad7a2ac62
134-
[5] 4dae4f5954f5e6feb3577cfb1b181daa3fd3afd2
135+
[4] 60665251ab71dbd8c18d9bf2174f4ee0d58aa06c
136+
[5] 97d808e45116bf02103490294d3d46dad7a2ac62
137+
[6] 4dae4f5954f5e6feb3577cfb1b181daa3fd3afd2
135138
EOF
136139
137140
git repo structure >out 2>err &&
@@ -176,6 +179,8 @@ test_expect_success SHA1 'keyvalue and nul format' '
176179
objects.tags.max_size_oid=1ee0f2b16ea37d895dbe9dbd76cd2ac70446176c
177180
objects.commits.max_parents=1
178181
objects.commits.max_parents_oid=de3508174b5c2ace6993da67cae9be9069e2df39
182+
objects.trees.max_entries=42
183+
objects.trees.max_entries_oid=09931deea9d81ec21300d3e13c74412f32eacec5
179184
EOF
180185
181186
git repo structure --format=keyvalue >out 2>err &&

0 commit comments

Comments
 (0)