diff options
| author | Justin Tobler <jltobler@gmail.com> | 2026-03-02 15:45:26 -0600 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-03-02 13:54:53 -0800 |
| commit | 42e69594113d647f53d65440f2ede554570b9f40 (patch) | |
| tree | 14731f497d8e6079d77bd3f1f7e800e503bd2c89 /builtin | |
| parent | 18952a1ef1a14d2fca19638118dc2eea1e24d671 (diff) | |
| download | git-42e69594113d647f53d65440f2ede554570b9f40.tar.xz | |
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>
Diffstat (limited to 'builtin')
| -rw-r--r-- | builtin/repo.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/builtin/repo.c b/builtin/repo.c index 047f5e098d..e726bb858c 100644 --- a/builtin/repo.c +++ b/builtin/repo.c @@ -16,6 +16,8 @@ #include "strbuf.h" #include "string-list.h" #include "shallow.h" +#include "tree.h" +#include "tree-walk.h" #include "utf8.h" static const char *const repo_usage[] = { @@ -211,6 +213,7 @@ struct largest_objects { struct object_data blob_size; struct object_data parent_count; + struct object_data tree_entries; }; struct ref_stats { @@ -458,6 +461,10 @@ static void stats_table_setup_structure(struct stats_table *table, &objects->largest.tree_size.oid, objects->largest.tree_size.value, " * %s", _("Maximum size")); + stats_table_object_count_addf(table, + &objects->largest.tree_entries.oid, + objects->largest.tree_entries.value, + " * %s", _("Maximum entries")); stats_table_addf(table, " * %s", _("Blobs")); stats_table_object_size_addf(table, &objects->largest.blob_size.oid, @@ -625,6 +632,8 @@ static void structure_keyvalue_print(struct repo_structure *stats, print_object_data("objects.commits.max_parents", key_delim, &stats->objects.largest.parent_count, value_delim); + print_object_data("objects.trees.max_entries", key_delim, + &stats->objects.largest.tree_entries, value_delim); fflush(stdout); } @@ -703,6 +712,20 @@ static void check_largest(struct object_data *data, struct object_id *oid, } } +static size_t count_tree_entries(struct object *obj) +{ + struct tree *t = object_as_type(obj, OBJ_TREE, 0); + struct name_entry entry; + struct tree_desc desc; + size_t count = 0; + + init_tree_desc(&desc, &t->object.oid, t->buffer, t->size); + while (tree_entry(&desc, &entry)) + count++; + + return count; +} + static int count_objects(const char *path UNUSED, struct oid_array *oids, enum object_type type, void *cb_data) { @@ -755,6 +778,8 @@ static int count_objects(const char *path UNUSED, struct oid_array *oids, stats->disk_sizes.trees += disk; check_largest(&stats->largest.tree_size, &oids->oid[i], inflated); + check_largest(&stats->largest.tree_entries, &oids->oid[i], + count_tree_entries(obj)); break; case OBJ_BLOB: stats->type_counts.blobs++; |
