{"thread":{"id":"66388","subject":"[PATCH 0/1] repo: add filtering options to \"repo structure\"","startedAt":"2026-09-24T16:45:15Z","lastAt":"2026-11-18T22:28:52Z","messageCount":40,"participants":["Mark C. Chu-Carroll","Patrick Steinhardt","Kaartic Sivaraam","Junio C Hamano","Kristoffer Haugsbakk"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"553207","messageId":"20260924164503.119506-1-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":null,"subject":"[PATCH 0/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-09-24T16:45:02Z","receivedAt":"2026-09-24T16:45:15Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"    repo: add filtering options to \"repo structure\"\n\n    \"git repo structure\" provides a collection of useful information\n    about the information stored in a repo. In particular, it's\n    valuable for diagnosing performance issues caused by large objects\n    stored in a repo.\n\n    The current implementation of \"git repo stucture\" provides summary\n    information about everything in the repository - all of the\n    branches, remotes, tags, stashes, and notes. But sometimes\n    to properly diagnose a problem, it's useful to be able to exclude\n    refs that are known to not be relevant to the issue at hand.\n\n    Add a set of flags that allow a user to selective exclude\n    reference types from the report generated by \"git repo structure\".\n    When a ref type is excluded by the filter, it no longer appears\n    in the report (ie, if \"--no-tags\" is passed, the report line\n    for \"Branches\" will no longer appear under \"* References\").\n    Following the pattern of flags that are only used to\n    disable functionality (eg, \"--no-verify\" in \"builtins/push.c\"),\n    only the \"--no-<reftype>\" syntax is listed in the updated\n    documentation.\n\n    Overview of the changes:\n    - Add an enum to represent the structure flags.\n    - Add structure flags to the options for the \"repo structure\" commands.\n    - For each reference flag, add a conditional in \"count_references\"\n      which decides whether or not to add a ref to the pending list.\n      If an references is not added to the pending list, the things it\n      transitively references will not be added to the stats.\n    - Add a set of test cases to verify that reference counts\n      in the repo structure report correctly omit the specified\n      resource types.\n    - Update the documentation for git-repo to include the new options.\n\nMark C. Chu-Carroll (1):\n  repo: add filtering options to \"repo structure\"\n\n Documentation/git-repo.adoc |  35 ++++-\n builtin/repo.c              | 158 +++++++++++++++------\n t/t1901-repo-structure.sh   | 276 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 427 insertions(+), 42 deletions(-)\n\n-- \n2.53.0\n\n"},{"id":"553208","messageId":"20260924164503.119506-2-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20260924164503.119506-1-markchucarroll@fastmail.com","subject":"[PATCH 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-09-24T16:45:03Z","receivedAt":"2026-09-24T16:45:17Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"\"git repo structure\" provides a collection of useful information\nabout the information stored in a repo. In particular, it's\nvaluable for diagnosing performance issues caused by large objects\nstored in a repo.\n\nThe current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to exclude\nrefs that are known to not be relevant to the issue at hand.\n\nAdd a set of flags that allow a user to selective exclude\nreference types from the report generated by \"git repo structure\".\nWhen a ref type is excluded by the filter, it no longer appears\nin the report (ie, if \"--no-tags\" is passed, the report line\nfor \"Branches\" will no longer appear under \"* References\").\nFollowing the pattern of flags that are only used to\ndisable functionality (eg, \"--no-verify\" in \"builtins/push.c\"),\nonly the \"--no-<reftype>\" syntax is listed in the updated\ndocumentation.\n\nOverview of the changes:\n- Add an enum to represent the structure flags.\n- Add structure flags to the options for the \"repo structure\" commands.\n- For each reference flag, add a conditional in \"count_references\"\n  which decides whether or not to add a ref to the pending list.\n  If an references is not added to the pending list, the things it\n  transitively references will not be added to the stats.\n- Add a set of test cases to verify that reference counts\n  in the repo structure report correctly omit the specified\n  resource types.\n- Update the documentation for git-repo to include the new options.\n\nSigned-off-by: Mark C. Chu-Carroll <markchucarroll@fastmail.com>\n---\n Documentation/git-repo.adoc |  35 ++++-\n builtin/repo.c              | 158 +++++++++++++++------\n t/t1901-repo-structure.sh   | 276 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 427 insertions(+), 42 deletions(-)\n\ndiff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc\nindex ed7d80c690..463260cd23 100644\n--- a/Documentation/git-repo.adoc\n+++ b/Documentation/git-repo.adoc\n@@ -10,7 +10,7 @@ SYNOPSIS\n [synopsis]\n git repo info [--format=(lines|nul) | -z] [--all | <key>...]\n git repo info --keys [--format=(lines|nul) | -z]\n-git repo structure [--format=(table|lines|nul) | -z]\n+git repo structure [--format=(table|lines|nul) | -z] [--no-branches] [--no-tags] [--no-remotes] [--no-notes] [--no-stashes]`::\n \n DESCRIPTION\n -----------\n@@ -56,7 +56,7 @@ supported:\n `nul`:::\n \tSimilar to `lines`, but using a _NUL_ character after each value.\n \n-`structure [--format=(table|lines|nul) | -z]`::\n+`structure [--format=(table|lines|nul) | -z] [--no-branches] [--no-tags] [--no-remotes] [--no-notes] [--no-stashes]`::\n \tRetrieve statistics about the current repository structure. The\n \tfollowing kinds of information are reported:\n +\n@@ -66,6 +66,23 @@ supported:\n * Total disk size of reachable objects by type\n * Largest reachable objects in the repository by type\n +\n+The types of objects counted can be filtered using flags:\n++\n+`--no-branches`:::\n+\tOmit branch refs from the set of objects to count.\n+\n+`--no-tags`:::\n+\tOmit tags from the set of objects to count.\n+\n+`--no-remotes`:::\n+\tOmit remotes from the set of objects to count.\n+\n+`--no-notes`:::\n+\tOmit notes from the set of objects to count.\n+\n+`--no-stashes`:::\n+\tOmit stashes from the set of objects to count.\n++\n The output format can be chosen through the flag `--format`. Three formats are\n supported:\n +\n@@ -141,6 +158,20 @@ using the `nul` format:\n git repo info --format=nul layout.bare layout.shallow\n ------------\n \n+* Generates information about storage usage in the repository:\n++\n+------------\n+git repo structure\n+------------\n++\n+\n+* Generates information about storage usage in the repository omitting\n+remotes:\n++\n+------------\n+git repo structure --no-remotes\n+------------\n+\n SEE ALSO\n --------\n linkgit:git-rev-parse[1]\ndiff --git a/builtin/repo.c b/builtin/repo.c\nindex 84e012f83f..c8f6e38011 100644\n--- a/builtin/repo.c\n+++ b/builtin/repo.c\n@@ -53,6 +53,20 @@ enum output_format {\n \tFORMAT_NUL_TERMINATED,\n };\n \n+enum repo_structure_filter_flags {\n+\tREPO_STRUCTURE_FILTER_BRANCHES = (1 << 0),\n+\tREPO_STRUCTURE_FILTER_TAGS = (1 << 1),\n+\tREPO_STRUCTURE_FILTER_REMOTES = (1 << 2),\n+\tREPO_STRUCTURE_FILTER_NOTES  = (1 << 3),\n+\tREPO_STRUCTURE_FILTER_STASHES = (1 << 4),\n+};\n+\n+#define REPO_STRUCTURE_FILTER_FLAGS_ALL (REPO_STRUCTURE_FILTER_BRANCHES | \\\n+\t\t\t\t\t REPO_STRUCTURE_FILTER_TAGS |\t\\\n+\t\t\t\t\t REPO_STRUCTURE_FILTER_REMOTES | \\\n+\t\t\t\t\t REPO_STRUCTURE_FILTER_NOTES |\\\n+\t\t\t\t\t REPO_STRUCTURE_FILTER_STASHES)\n+\n struct repo_info_field {\n \tconst char *key;\n \tget_value_fn *get_value;\n@@ -490,7 +504,8 @@ static inline size_t get_total_object_values(struct object_values *values)\n }\n \n static void stats_table_setup_structure(struct stats_table *table,\n-\t\t\t\t\tstruct repo_structure *stats)\n+\t\t\t\t\tstruct repo_structure *stats,\n+\t\t\t\t\tenum repo_structure_filter_flags flags)\n {\n \tstruct object_stats *objects = &stats->objects;\n \tstruct ref_stats *refs = &stats->refs;\n@@ -502,9 +517,15 @@ static void stats_table_setup_structure(struct stats_table *table,\n \tref_total = get_total_reference_count(refs);\n \tstats_table_addf(table, \"* %s\", _(\"References\"));\n \tstats_table_count_addf(table, ref_total, \"  * %s\", _(\"Count\"));\n-\tstats_table_count_addf(table, refs->branches, \"    * %s\", _(\"Branches\"));\n-\tstats_table_count_addf(table, refs->tags, \"    * %s\", _(\"Tags\"));\n-\tstats_table_count_addf(table, refs->remotes, \"    * %s\", _(\"Remotes\"));\n+\tif (flags & REPO_STRUCTURE_FILTER_BRANCHES) {\n+\t\tstats_table_count_addf(table, refs->branches, \"    * %s\", _(\"Branches\"));\n+\t}\n+\tif (flags & REPO_STRUCTURE_FILTER_TAGS) {\n+\t\tstats_table_count_addf(table, refs->tags, \"    * %s\", _(\"Tags\"));\n+\t}\n+\tif (flags & REPO_STRUCTURE_FILTER_REMOTES) {\n+\t\tstats_table_count_addf(table, refs->remotes, \"    * %s\", _(\"Remotes\"));\n+\t}\n \tstats_table_count_addf(table, refs->others, \"    * %s\", _(\"Others\"));\n \n \tobject_count_total = get_total_object_values(&objects->type_counts);\n@@ -517,8 +538,10 @@ static void stats_table_setup_structure(struct stats_table *table,\n \t\t\t       \"    * %s\", _(\"Trees\"));\n \tstats_table_count_addf(table, objects->type_counts.blobs,\n \t\t\t       \"    * %s\", _(\"Blobs\"));\n-\tstats_table_count_addf(table, objects->type_counts.tags,\n-\t\t\t       \"    * %s\", _(\"Tags\"));\n+\tif (flags & REPO_STRUCTURE_FILTER_TAGS) {\n+\t\tstats_table_count_addf(table, objects->type_counts.tags,\n+\t\t\t\t       \"    * %s\", _(\"Tags\"));\n+\t}\n \n \tinflated_object_total = get_total_object_values(&objects->inflated_sizes);\n \tstats_table_size_addf(table, inflated_object_total,\n@@ -529,8 +552,11 @@ static void stats_table_setup_structure(struct stats_table *table,\n \t\t\t      \"    * %s\", _(\"Trees\"));\n \tstats_table_size_addf(table, objects->inflated_sizes.blobs,\n \t\t\t      \"    * %s\", _(\"Blobs\"));\n-\tstats_table_size_addf(table, objects->inflated_sizes.tags,\n-\t\t\t      \"    * %s\", _(\"Tags\"));\n+\n+\tif (flags & REPO_STRUCTURE_FILTER_TAGS) {\n+\t\tstats_table_size_addf(table, objects->inflated_sizes.tags,\n+\t\t\t\t      \"    * %s\", _(\"Tags\"));\n+\t}\n \n \tdisk_object_total = get_total_object_values(&objects->disk_sizes);\n \tstats_table_size_addf(table, disk_object_total,\n@@ -541,8 +567,10 @@ static void stats_table_setup_structure(struct stats_table *table,\n \t\t\t      \"    * %s\", _(\"Trees\"));\n \tstats_table_size_addf(table, objects->disk_sizes.blobs,\n \t\t\t      \"    * %s\", _(\"Blobs\"));\n-\tstats_table_size_addf(table, objects->disk_sizes.tags,\n-\t\t\t      \"    * %s\", _(\"Tags\"));\n+\tif (flags & REPO_STRUCTURE_FILTER_TAGS) {\n+\t\tstats_table_size_addf(table, objects->disk_sizes.tags,\n+\t\t\t\t      \"    * %s\", _(\"Tags\"));\n+\t}\n \n \tstats_table_addf(table, \"\");\n \tstats_table_addf(table, \"* %s\", _(\"Largest objects\"));\n@@ -569,11 +597,13 @@ static void stats_table_setup_structure(struct stats_table *table,\n \t\t\t\t     &objects->largest.blob_size.oid,\n \t\t\t\t     objects->largest.blob_size.value,\n \t\t\t\t     \"    * %s\", _(\"Maximum size\"));\n-\tstats_table_addf(table, \"  * %s\", _(\"Tags\"));\n-\tstats_table_object_size_addf(table,\n-\t\t\t\t     &objects->largest.tag_size.oid,\n-\t\t\t\t     objects->largest.tag_size.value,\n-\t\t\t\t     \"    * %s\", _(\"Maximum size\"));\n+\tif (flags & REPO_STRUCTURE_FILTER_TAGS) {\n+\t\tstats_table_addf(table, \"  * %s\", _(\"Tags\"));\n+\t\tstats_table_object_size_addf(table,\n+\t\t\t\t\t     &objects->largest.tag_size.oid,\n+\t\t\t\t\t     objects->largest.tag_size.value,\n+\t\t\t\t\t     \"    * %s\", _(\"Maximum size\"));\n+\t}\n }\n \n #define INDEX_WIDTH 4\n@@ -681,14 +711,21 @@ static void print_object_data(const char *key, char key_delim,\n }\n \n static void structure_keyvalue_print(struct repo_structure *stats,\n-\t\t\t\t     char key_delim, char value_delim)\n+\t\t\t\t     char key_delim, char value_delim,\n+\t\t\t\t     enum repo_structure_filter_flags flags)\n {\n-\tprint_keyvalue(\"references.branches.count\", key_delim,\n-\t\t       stats->refs.branches, value_delim);\n+\tif (flags & REPO_STRUCTURE_FILTER_BRANCHES) {\n+\t\tprint_keyvalue(\"references.branches.count\", key_delim,\n+\t\t\t       stats->refs.branches, value_delim);\n+\t}\n+\tif (flags & REPO_STRUCTURE_FILTER_TAGS) {\n \tprint_keyvalue(\"references.tags.count\", key_delim,\n \t\t       stats->refs.tags, value_delim);\n-\tprint_keyvalue(\"references.remotes.count\", key_delim,\n-\t\t       stats->refs.remotes, value_delim);\n+\t}\n+\tif (flags & REPO_STRUCTURE_FILTER_REMOTES) {\n+\t\tprint_keyvalue(\"references.remotes.count\", key_delim,\n+\t\t\t       stats->refs.remotes, value_delim);\n+\t}\n \tprint_keyvalue(\"references.others.count\", key_delim,\n \t\t       stats->refs.others, value_delim);\n \n@@ -698,8 +735,10 @@ static void structure_keyvalue_print(struct repo_structure *stats,\n \t\t       stats->objects.type_counts.trees, value_delim);\n \tprint_keyvalue(\"objects.blobs.count\", key_delim,\n \t\t       stats->objects.type_counts.blobs, value_delim);\n-\tprint_keyvalue(\"objects.tags.count\", key_delim,\n-\t\t       stats->objects.type_counts.tags, value_delim);\n+\tif (flags & REPO_STRUCTURE_FILTER_TAGS) {\n+\t\tprint_keyvalue(\"objects.tags.count\", key_delim,\n+\t\t\t       stats->objects.type_counts.tags, value_delim);\n+\t}\n \n \tprint_keyvalue(\"objects.commits.inflated_size\", key_delim,\n \t\t       stats->objects.inflated_sizes.commits, value_delim);\n@@ -707,8 +746,10 @@ static void structure_keyvalue_print(struct repo_structure *stats,\n \t\t       stats->objects.inflated_sizes.trees, value_delim);\n \tprint_keyvalue(\"objects.blobs.inflated_size\", key_delim,\n \t\t       stats->objects.inflated_sizes.blobs, value_delim);\n-\tprint_keyvalue(\"objects.tags.inflated_size\", key_delim,\n-\t\t       stats->objects.inflated_sizes.tags, value_delim);\n+\tif (flags & REPO_STRUCTURE_FILTER_TAGS) {\n+\t\tprint_keyvalue(\"objects.tags.inflated_size\", key_delim,\n+\t\t\t       stats->objects.inflated_sizes.tags, value_delim);\n+\t}\n \n \tprint_keyvalue(\"objects.commits.disk_size\", key_delim,\n \t\t       stats->objects.disk_sizes.commits, value_delim);\n@@ -716,8 +757,10 @@ static void structure_keyvalue_print(struct repo_structure *stats,\n \t\t       stats->objects.disk_sizes.trees, value_delim);\n \tprint_keyvalue(\"objects.blobs.disk_size\", key_delim,\n \t\t       stats->objects.disk_sizes.blobs, value_delim);\n-\tprint_keyvalue(\"objects.tags.disk_size\", key_delim,\n-\t\t       stats->objects.disk_sizes.tags, value_delim);\n+\tif (flags & REPO_STRUCTURE_FILTER_TAGS) {\n+\t\tprint_keyvalue(\"objects.tags.disk_size\", key_delim,\n+\t\t\t       stats->objects.disk_sizes.tags, value_delim);\n+\t}\n \n \tprint_object_data(\"objects.commits.max_size\", key_delim,\n \t\t\t  &stats->objects.largest.commit_size, value_delim);\n@@ -725,8 +768,10 @@ static void structure_keyvalue_print(struct repo_structure *stats,\n \t\t\t  &stats->objects.largest.tree_size, value_delim);\n \tprint_object_data(\"objects.blobs.max_size\", key_delim,\n \t\t\t  &stats->objects.largest.blob_size, value_delim);\n-\tprint_object_data(\"objects.tags.max_size\", key_delim,\n-\t\t\t  &stats->objects.largest.tag_size, value_delim);\n+\tif (flags & REPO_STRUCTURE_FILTER_TAGS) {\n+\t\tprint_object_data(\"objects.tags.max_size\", key_delim,\n+\t\t\t\t  &stats->objects.largest.tag_size, value_delim);\n+\t}\n \n \tprint_object_data(\"objects.commits.max_parents\", key_delim,\n \t\t\t  &stats->objects.largest.parent_count, value_delim);\n@@ -739,6 +784,7 @@ static void structure_keyvalue_print(struct repo_structure *stats,\n struct count_references_data {\n \tstruct ref_stats *stats;\n \tstruct rev_info *revs;\n+\tenum repo_structure_filter_flags flags;\n \tstruct progress *progress;\n };\n \n@@ -747,19 +793,42 @@ static int count_references(const struct reference *ref, void *cb_data)\n \tstruct count_references_data *data = cb_data;\n \tstruct ref_stats *stats = data->stats;\n \tsize_t ref_count;\n+\tbool add_pending = false;\n \n \tswitch (ref_kind_from_refname(ref->name)) {\n \tcase FILTER_REFS_BRANCHES:\n-\t\tstats->branches++;\n+\t\tif (data->flags & REPO_STRUCTURE_FILTER_BRANCHES) {\n+\t\t\tstats->branches++;\n+\t\t\tadd_pending = true;\n+\t\t}\n \t\tbreak;\n \tcase FILTER_REFS_REMOTES:\n-\t\tstats->remotes++;\n+\t\tif (data->flags & REPO_STRUCTURE_FILTER_REMOTES) {\n+\t\t\tstats->remotes++;\n+\t\t\tadd_pending = true;\n+\t\t}\n \t\tbreak;\n \tcase FILTER_REFS_TAGS:\n-\t\tstats->tags++;\n+\t\tif (data->flags & REPO_STRUCTURE_FILTER_TAGS) {\n+\t\t\tstats->tags++;\n+\t\t\tadd_pending = true;\n+\t\t}\n \t\tbreak;\n \tcase FILTER_REFS_OTHERS:\n-\t\tstats->others++;\n+\t\tif (!strcmp(ref->name, \"refs/stash\")) {\n+\t\t\tif (data->flags & REPO_STRUCTURE_FILTER_STASHES) {\n+\t\t\t\tstats->others++;\n+\t\t\t\tadd_pending = true;\n+\t\t\t}\n+\t\t} else if (starts_with(ref->name, \"refs/notes\")) {\n+\t\t\tif (data->flags & REPO_STRUCTURE_FILTER_NOTES) {\n+\t\t\t\tstats->others++;\n+\t\t\t\tadd_pending = true;\n+\t\t\t}\n+\t\t} else {\n+\t\t\tstats->others++;\n+\t\t\tadd_pending = true;\n+\t\t}\n \t\tbreak;\n \tdefault:\n \t\tBUG(\"unexpected reference type\");\n@@ -769,10 +838,11 @@ static int count_references(const struct reference *ref, void *cb_data)\n \t * While iterating through references for counting, also add OIDs in\n \t * preparation for the path walk.\n \t */\n-\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n-\n-\tref_count = get_total_reference_count(stats);\n-\tdisplay_progress(data->progress, ref_count);\n+\tif (add_pending) {\n+\t\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n+\t\tref_count = get_total_reference_count(stats);\n+\t\tdisplay_progress(data->progress, ref_count);\n+\t}\n \n \treturn 0;\n }\n@@ -780,11 +850,13 @@ static int count_references(const struct reference *ref, void *cb_data)\n static void structure_count_references(struct ref_stats *stats,\n \t\t\t\t       struct rev_info *revs,\n \t\t\t\t       struct repository *repo,\n+\t\t\t\t       enum repo_structure_filter_flags flags,\n \t\t\t\t       int show_progress)\n {\n \tstruct count_references_data data = {\n \t\t.stats = stats,\n \t\t.revs = revs,\n+\t\t.flags = flags,\n \t};\n \n \tif (show_progress)\n@@ -935,6 +1007,7 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \tstruct repo_structure stats = { 0 };\n \tstruct rev_info revs;\n \tint show_progress = -1;\n+\tint flags = REPO_STRUCTURE_FILTER_FLAGS_ALL;\n \tstruct option options[] = {\n \t\tOPT_CALLBACK_F(0, \"format\", &format, N_(\"format\"),\n \t\t\t       N_(\"output format\"),\n@@ -944,6 +1017,11 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \t\t\t       PARSE_OPT_NONEG | PARSE_OPT_NOARG,\n \t\t\t       parse_format_cb),\n \t\tOPT_BOOL(0, \"progress\", &show_progress, N_(\"show progress\")),\n+\t\tOPT_BIT(0, \"branches\", &flags, N_(\"include branches in structure statistics\"), REPO_STRUCTURE_FILTER_BRANCHES),\n+\t\tOPT_BIT(0, \"tags\", &flags, N_(\"include tags in structure statistics\"), REPO_STRUCTURE_FILTER_TAGS),\n+\t\tOPT_BIT(0, \"remotes\", &flags, N_(\"include remotes in structure statistics\"), REPO_STRUCTURE_FILTER_REMOTES),\n+\t\tOPT_BIT(0, \"notes\", &flags, N_(\"include notes in structure statistics\"), REPO_STRUCTURE_FILTER_NOTES),\n+\t\tOPT_BIT(0, \"stashes\", &flags, N_(\"include stashes in structure statistics\"), REPO_STRUCTURE_FILTER_STASHES),\n \t\tOPT_END()\n \t};\n \n@@ -956,19 +1034,19 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \tif (show_progress < 0)\n \t\tshow_progress = isatty(2);\n \n-\tstructure_count_references(&stats.refs, &revs, repo, show_progress);\n+\tstructure_count_references(&stats.refs, &revs, repo, flags, show_progress);\n \tstructure_count_objects(&stats.objects, &revs, repo, show_progress);\n \n \tswitch (format) {\n \tcase FORMAT_TABLE:\n-\t\tstats_table_setup_structure(&table, &stats);\n+\t\tstats_table_setup_structure(&table, &stats, flags);\n \t\tstats_table_print_structure(&table);\n \t\tbreak;\n \tcase FORMAT_NEWLINE_TERMINATED:\n-\t\tstructure_keyvalue_print(&stats, '=', '\\n');\n+\t\tstructure_keyvalue_print(&stats, '=', '\\n', flags);\n \t\tbreak;\n \tcase FORMAT_NUL_TERMINATED:\n-\t\tstructure_keyvalue_print(&stats, '\\n', '\\0');\n+\t\tstructure_keyvalue_print(&stats, '\\n', '\\0', flags);\n \t\tbreak;\n \tdefault:\n \t\tBUG(\"invalid output format\");\ndiff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\nindex 02cc2b594a..60a82493c6 100755\n--- a/t/t1901-repo-structure.sh\n+++ b/t/t1901-repo-structure.sh\n@@ -144,6 +144,170 @@ test_expect_success SHA1 'repository with references and objects' '\n \t)\n '\n \n+\n+test_expect_success SHA1 'repository with references and objects, filtered with --no-origins' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\n+\t\tgit checkout -b other_branch &&\n+\t\ttest_commit_bulk 5 &&\n+\n+\t\tgit checkout master &&\n+\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\t# The tags disk size is handled specially due to the\n+\t\t# git-rev-list(1) --disk-usage=human option printing the full\n+\t\t# \"byte/bytes\" unit string instead of just \"B\".\n+\t\tcat >expect <<-EOF &&\n+\t\t| Repository structure      | Value      |\n+\t\t| ------------------------- | ---------- |\n+\t\t| * References              |            |\n+\t\t|   * Count                 |      4     |\n+\t\t|     * Branches            |      2     |\n+\t\t|     * Tags                |      1     |\n+\t\t|     * Others              |      1     |\n+\t\t|                           |            |\n+\t\t| * Reachable objects       |            |\n+\t\t|   * Count                 |   3.02 k   |\n+\t\t|     * Commits             |   1.01 k   |\n+\t\t|     * Trees               |   1.01 k   |\n+\t\t|     * Blobs               |   1.01 k   |\n+\t\t|     * Tags                |      1     |\n+\t\t|   * Inflated size         |  16.04 MiB |\n+\t\t|     * Commits             | 219.00 KiB |\n+\t\t|     * Trees               |  15.81 MiB |\n+\t\t|     * Blobs               |  11.68 KiB |\n+\t\t|     * Tags                |    132 B   |\n+\t\t|   * Disk size             | $(object_type_disk_usage all true) |\n+\t\t|     * Commits             | $(object_type_disk_usage commit true) |\n+\t\t|     * Trees               | $(object_type_disk_usage tree true) |\n+\t\t|     * Blobs               |  $(object_type_disk_usage blob true) |\n+\t\t|     * Tags                |    $(object_type_disk_usage tag) B   |\n+\t\t|                           |            |\n+\t\t| * Largest objects         |            |\n+\t\t|   * Commits               |            |\n+\t\t|     * Maximum size    [1] |    223 B   |\n+\t\t|     * Maximum parents [2] |      1     |\n+\t\t|   * Trees                 |            |\n+\t\t|     * Maximum size    [3] |  32.29 KiB |\n+\t\t|     * Maximum entries [4] |   1.01 k   |\n+\t\t|   * Blobs                 |            |\n+\t\t|     * Maximum size    [5] |     13 B   |\n+\t\t|   * Tags                  |            |\n+\t\t|     * Maximum size    [6] |    132 B   |\n+\n+\t\t[1] 0dc91eb18580102a3a216c8bfecedeba2b9f9b9a\n+\t\t[2] 0a8f6a47f34078bb7c4b2bb4377c2133157f6703\n+\t\t[3] 60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\t[4] 60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\t[5] 97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\t[6] 4dae4f5954f5e6feb3577cfb1b181daa3fd3afd2\n+\t\tEOF\n+\t\tgit repo structure --no-remotes >actual 2>err &&\n+\t\ttest_cmp expect actual &&\n+\t\ttest_line_count = 0 err\n+\t)\n+'\n+\n+test_expect_success SHA1 'repository with references and objects, filtered with \"--no-branches\"' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\n+\t\tgit checkout -b other_branch &&\n+\t\ttest_commit_bulk 5 &&\n+\n+\t\tgit checkout master &&\n+\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\tgit repo structure --no-branches >actual 2>err &&\n+\t\ttest_line_count = 0 err &&\n+\t\ttest_grep \"|   \\* Count                 |      3     |\" actual &&\n+\t\ttest_grep \"|     \\* Others              |      1     |\" actual &&\n+\t\ttest_grep !  \"Branches\" actual\n+\t)\n+'\n+\n+test_expect_success SHA1 'repository with references and objects, filtered with \"--no-notes\"' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\n+\t\tgit checkout -b other_branch &&\n+\t\ttest_commit_bulk 5 &&\n+\n+\t\tgit checkout master &&\n+\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\tgit repo structure --no-notes >actual 2>err &&\n+\t\ttest_line_count = 0 err &&\n+\t\ttest_grep \"|   \\* Count                 |      4     |\" actual &&\n+\t\ttest_grep \"|     \\* Others              |      0     |\" actual &&\n+\t\ttest_grep \"|     \\* Commits             | 218.81 KiB |\" actual\n+\t)\n+'\n+\n+test_expect_success SHA1 'repository with references and objects, filtered with multiple flags' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\n+\t\tgit checkout -b other_branch &&\n+\t\ttest_commit_bulk 5 &&\n+\n+\t\tgit checkout master &&\n+\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\tgit repo structure --no-notes --no-branches >actual 2>err &&\n+\t\ttest_line_count = 0 err &&\n+\t\ttest_grep \"|   \\* Count                 |      2     |\" actual &&\n+\t\ttest_grep \"|     \\* Others              |      0     |\" actual &&\n+\t\ttest_grep \"|     \\* Commits             | 217.73 KiB |\" actual &&\n+\t\ttest_grep !  \"Branches\" actual &&\n+\n+\t\tgit repo structure --no-notes --no-branches --no-remotes >actual 2>err &&\n+\t\ttest_line_count = 0 err &&\n+\t\ttest_grep \"|   \\* Count                 |      1     |\" actual &&\n+\t\ttest_grep \"|     \\* Others              |      0     |\" actual &&\n+\t\ttest_grep \"|     \\* Commits             | 217.73 KiB |\" actual &&\n+\t\ttest_grep !  \"Branches\" actual &&\n+\t\ttest_grep ! \"Remotes\" actual\n+\t)\n+'\n+\n test_expect_success SHA1 'lines and nul format' '\n \ttest_when_finished \"rm -rf repo\" &&\n \tgit init repo &&\n@@ -203,6 +367,118 @@ test_expect_success SHA1 'lines and nul format' '\n \t\ttest_line_count = 0 err\n \t)\n '\n+test_expect_success SHA1 'lines and nul format with --no-tags filter' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 42 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\tcat >expect <<-EOF &&\n+\t\treferences.branches.count=1\n+\t\treferences.remotes.count=0\n+\t\treferences.others.count=0\n+\t\tobjects.commits.count=42\n+\t\tobjects.trees.count=42\n+\t\tobjects.blobs.count=42\n+\t\tobjects.commits.inflated_size=9225\n+\t\tobjects.trees.inflated_size=28554\n+\t\tobjects.blobs.inflated_size=453\n+\t\tobjects.commits.disk_size=$(object_type_disk_usage commit)\n+\t\tobjects.trees.disk_size=$(object_type_disk_usage tree)\n+\t\tobjects.blobs.disk_size=$(object_type_disk_usage blob)\n+\t\tobjects.commits.max_size=221\n+\t\tobjects.commits.max_size_oid=de3508174b5c2ace6993da67cae9be9069e2df39\n+\t\tobjects.trees.max_size=1335\n+\t\tobjects.trees.max_size_oid=09931deea9d81ec21300d3e13c74412f32eacec5\n+\t\tobjects.blobs.max_size=11\n+\t\tobjects.blobs.max_size_oid=eaeeedced46482bd4281fda5a5f05ce24854151f\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=de3508174b5c2ace6993da67cae9be9069e2df39\n+\t\tobjects.trees.max_entries=42\n+\t\tobjects.trees.max_entries_oid=09931deea9d81ec21300d3e13c74412f32eacec5\n+\t\tEOF\n+\n+\t\tgit repo structure --format=lines --no-tags >actual 2>err &&\n+\t\ttest_cmp expect actual &&\n+\t\ttest_line_count = 0 err &&\n+\n+\t\tgit repo structure --format=nul --no-tags >out 2>err &&\n+\t\ttr \"\\012\\000\" \"=\\012\" <out >actual &&\n+\n+\t\ttest_cmp expect actual &&\n+\t\ttest_line_count = 0 err &&\n+\n+\t\t# \"-z\", as a synonym to \"--format=nul\", participates in the\n+\t\t# usual \"last one wins\" rule.\n+\t\tgit repo structure --format=table -z --no-tags >out 2>err &&\n+\t\ttr \"\\012\\000\" \"=\\012\" <out >actual &&\n+\n+\t\ttest_cmp expect actual &&\n+\t\ttest_line_count = 0 err\n+\t)\n+'\n+\n+test_expect_success SHA1 'lines and nul format with --no-branches filter' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 42 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\tcat >expect <<-EOF &&\n+\t\treferences.tags.count=1\n+\t\treferences.remotes.count=0\n+\t\treferences.others.count=0\n+\t\tobjects.commits.count=42\n+\t\tobjects.trees.count=42\n+\t\tobjects.blobs.count=42\n+\t\tobjects.tags.count=1\n+\t\tobjects.commits.inflated_size=9225\n+\t\tobjects.trees.inflated_size=28554\n+\t\tobjects.blobs.inflated_size=453\n+\t\tobjects.tags.inflated_size=132\n+\t\tobjects.commits.disk_size=$(object_type_disk_usage commit)\n+\t\tobjects.trees.disk_size=$(object_type_disk_usage tree)\n+\t\tobjects.blobs.disk_size=$(object_type_disk_usage blob)\n+\t\tobjects.tags.disk_size=$(object_type_disk_usage tag)\n+\t\tobjects.commits.max_size=221\n+\t\tobjects.commits.max_size_oid=de3508174b5c2ace6993da67cae9be9069e2df39\n+\t\tobjects.trees.max_size=1335\n+\t\tobjects.trees.max_size_oid=09931deea9d81ec21300d3e13c74412f32eacec5\n+\t\tobjects.blobs.max_size=11\n+\t\tobjects.blobs.max_size_oid=eaeeedced46482bd4281fda5a5f05ce24854151f\n+\t\tobjects.tags.max_size=132\n+\t\tobjects.tags.max_size_oid=1ee0f2b16ea37d895dbe9dbd76cd2ac70446176c\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=de3508174b5c2ace6993da67cae9be9069e2df39\n+\t\tobjects.trees.max_entries=42\n+\t\tobjects.trees.max_entries_oid=09931deea9d81ec21300d3e13c74412f32eacec5\n+\t\tEOF\n+\n+\t\tgit repo structure --format=lines --no-branches >actual 2>err &&\n+\t\tcp expect /tmp/expect &&\n+\t\tcp actual /tmp/actual &&\n+\t\ttest_cmp expect actual &&\n+\t\ttest_line_count = 0 err &&\n+\n+\t\tgit repo structure --format=nul --no-branches >out 2>err &&\n+\t\ttr \"\\012\\000\" \"=\\012\" <out >actual &&\n+\n+\t\ttest_cmp expect actual &&\n+\t\ttest_line_count = 0 err &&\n+\n+\t\t# \"-z\", as a synonym to \"--format=nul\", participates in the\n+\t\t# usual \"last one wins\" rule.\n+\t\tgit repo structure --format=table -z --no-branches >out 2>err &&\n+\t\ttr \"\\012\\000\" \"=\\012\" <out >actual &&\n+\n+\t\ttest_cmp expect actual &&\n+\t\ttest_line_count = 0 err\n+\t)\n+'\n \n test_expect_success 'progress meter option' '\n \ttest_when_finished \"rm -rf repo\" &&\n-- \n2.53.0\n\n"},{"id":"553727","messageId":"ar04uStCZ4pnEJ38@pks.im","threadId":"66388","inReplyTo":"20260924164503.119506-2-markchucarroll@fastmail.com","subject":"Re: [PATCH 1/1] repo: add filtering options to \"repo structure\"","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-09-30T16:28:41Z","receivedAt":"2026-09-30T16:28:46Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Sep 24, 2026 at 12:45:03PM -0400, Mark C. Chu-Carroll wrote:\n> \"git repo structure\" provides a collection of useful information\n> about the information stored in a repo. In particular, it's\n> valuable for diagnosing performance issues caused by large objects\n> stored in a repo.\n> \n> The current implementation of \"git repo stucture\" provides summary\n> information about everything in the repository - all of the\n> branches, remotes, tags, stashes, and notes. But sometimes\n> to properly diagnose a problem, it's useful to be able to exclude\n> refs that are known to not be relevant to the issue at hand.\n\nYes, indeed. Sometimes you may for example want to figure out where\nexactly the storage size of a particular repository is going. Or in the\ncase of GitLab for example, we may have bookkeeping references that are\nnot controllable by customers. So we may only want to get the structure\nfor all the customer-controllable branches there.\n\n> Add a set of flags that allow a user to selective exclude\n> reference types from the report generated by \"git repo structure\".\n> When a ref type is excluded by the filter, it no longer appears\n> in the report (ie, if \"--no-tags\" is passed, the report line\n> for \"Branches\" will no longer appear under \"* References\").\n> Following the pattern of flags that are only used to\n> disable functionality (eg, \"--no-verify\" in \"builtins/push.c\"),\n> only the \"--no-<reftype>\" syntax is listed in the updated\n> documentation.\n\nHmm, okay. I would have expected that the user can essentially pass\narbitrary revisions as understood by git-log(1) et al. And if they pass\nany such revisions, we should not enumerate anything but what they have\npassed, so the flags shouldn't only be used to exclude.\n\nSo, for example:\n\n    $ git repo structure --branches\n    $ git repo structure master\n    $ git repo structure --all --not --branches\n\nI would hope that git-repo(1) can achieve that rather easily because I\nexpect that it uses `struct rev_info`, but let's read on.\n\n> Overview of the changes:\n> - Add an enum to represent the structure flags.\n> - Add structure flags to the options for the \"repo structure\" commands.\n> - For each reference flag, add a conditional in \"count_references\"\n>   which decides whether or not to add a ref to the pending list.\n>   If an references is not added to the pending list, the things it\n>   transitively references will not be added to the stats.\n> - Add a set of test cases to verify that reference counts\n>   in the repo structure report correctly omit the specified\n>   resource types.\n> - Update the documentation for git-repo to include the new options.\n\nNote that we typically don't have lists of what exactly has changed in\nthe commit. That kind of information is already visible from the diff\nitself. So what the commit message itself should focus on is whether any\nof these changes are non-obvious or whethere there's any dragons to be\nfound.\n\nSo in summary: everything that may surprise the reader should be part of\nthe commit message, everything that's just obvious plumbing doesn't\nreally have to be mentioned.\n\n> diff --git a/builtin/repo.c b/builtin/repo.c\n> index 84e012f83f..c8f6e38011 100644\n> --- a/builtin/repo.c\n> +++ b/builtin/repo.c\n> @@ -490,7 +504,8 @@ static inline size_t get_total_object_values(struct object_values *values)\n>  }\n>  \n>  static void stats_table_setup_structure(struct stats_table *table,\n> -\t\t\t\t\tstruct repo_structure *stats)\n> +\t\t\t\t\tstruct repo_structure *stats,\n> +\t\t\t\t\tenum repo_structure_filter_flags flags)\n>  {\n>  \tstruct object_stats *objects = &stats->objects;\n>  \tstruct ref_stats *refs = &stats->refs;\n> @@ -502,9 +517,15 @@ static void stats_table_setup_structure(struct stats_table *table,\n>  \tref_total = get_total_reference_count(refs);\n>  \tstats_table_addf(table, \"* %s\", _(\"References\"));\n>  \tstats_table_count_addf(table, ref_total, \"  * %s\", _(\"Count\"));\n> -\tstats_table_count_addf(table, refs->branches, \"    * %s\", _(\"Branches\"));\n> -\tstats_table_count_addf(table, refs->tags, \"    * %s\", _(\"Tags\"));\n> -\tstats_table_count_addf(table, refs->remotes, \"    * %s\", _(\"Remotes\"));\n> +\tif (flags & REPO_STRUCTURE_FILTER_BRANCHES) {\n> +\t\tstats_table_count_addf(table, refs->branches, \"    * %s\", _(\"Branches\"));\n> +\t}\n> +\tif (flags & REPO_STRUCTURE_FILTER_TAGS) {\n> +\t\tstats_table_count_addf(table, refs->tags, \"    * %s\", _(\"Tags\"));\n> +\t}\n> +\tif (flags & REPO_STRUCTURE_FILTER_REMOTES) {\n> +\t\tstats_table_count_addf(table, refs->remotes, \"    * %s\", _(\"Remotes\"));\n> +\t}\n>  \tstats_table_count_addf(table, refs->others, \"    * %s\", _(\"Others\"));\n>  \n>  \tobject_count_total = get_total_object_values(&objects->type_counts);\n\nCoding style: we don't use curly braces around single-line statements.\n\nBut more importantly, I think this is where the mismatch in expectations\ncomes from that I was pointing out further up. My expectation was that\nwhat we want to achieve is to filter the reachable objects by revisions,\nwhich I think is a much more useful thing to do. But what the flags do\ninstead us to filter the output in the \"References\" count.\n\nI think that we should rather go into the direction of filtering objects\nand not the ref output, as the latter isn't all that useful. It _may_\nmake sense to maybe make some sections of the output optional, but\nexcluding individual ref types is arguably too fine-grained.\n\nIn any case, to go into the direction of filtering objects you'd want to\nadapt `parse_options()` so that it accepts unknown options (you can\nachieve that by passing `PARSE_OPT_KEEP_ARGV0 |\nPARSE_OPT_KEEP_UNKNOWN_OPT`) and then pass argv to `setup_revisions()`.\nAnd I think that _should_ already achieve proper filtering of objects by\nrevisions.\n\nThanks!\n\nPatrick\n"},{"id":"554205","messageId":"20261005174045.1900391-1-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20260924164503.119506-2-markchucarroll@fastmail.com","subject":"[PATCH v2 0/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-05T17:40:43Z","receivedAt":"2026-10-05T17:40:43Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"\"git repo structure\" provides a collection of useful information\nabout the information stored in a repo. In particular, it's\nvaluable for diagnosing performance issues caused by large objects\nstored in a repo.\n\nThe current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to\nget information about the specific part of the repo that's\nexhibiting a problem.\n\nAdd the option to specify a set of filters in the form\nof a list of include and exclude queries. Each of these\nspecifies a commit or ref or range. The set of objects processed\nwill consist of all objects reachable from any of the\nincludes which are _not_ reached exclusively by paths\nincluding any of the excludes.\n\nUpdates since v1: this change has been completely rewritten. The\noriginal version implemented filters the same way as\n\"git-sizer\", by selecting object types to include or exclude.\nThis version drops he type-based filters in favor of\nspecifying object traversal roots and exclusions.\n\nMark C. Chu-Carroll (1):\n  repo: add filtering options to \"repo structure\"\n\n Documentation/git-repo.adoc | 41 ++++++++++++++++--\n builtin/repo.c              | 16 +++++--\n t/t1901-repo-structure.sh   | 84 +++++++++++++++++++++++++++++++++++++\n 3 files changed, 133 insertions(+), 8 deletions(-)\n\n-- \n2.53.0\n\n\n"},{"id":"554206","messageId":"20261005174045.1900391-2-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20261005174045.1900391-1-markchucarroll@fastmail.com","subject":"[PATCH v2 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-05T17:40:44Z","receivedAt":"2026-10-05T17:40:44Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"Implement filtering for repo structure, imitating the mechanism\nused in \"git log\".\n\nSigned-off-by: Mark C. Chu-Carroll <markchucarroll@fastmail.com>\n---\n Documentation/git-repo.adoc | 41 ++++++++++++++++--\n builtin/repo.c              | 16 +++++--\n t/t1901-repo-structure.sh   | 84 +++++++++++++++++++++++++++++++++++++\n 3 files changed, 133 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc\nindex ed7d80c690..5cbdf8e727 100644\n--- a/Documentation/git-repo.adoc\n+++ b/Documentation/git-repo.adoc\n@@ -10,7 +10,7 @@ SYNOPSIS\n [synopsis]\n git repo info [--format=(lines|nul) | -z] [--all | <key>...]\n git repo info --keys [--format=(lines|nul) | -z]\n-git repo structure [--format=(table|lines|nul) | -z]\n+git repo structure [--format=(table|lines|nul) | -z] [<include|^exclude>...]\n \n DESCRIPTION\n -----------\n@@ -56,9 +56,10 @@ supported:\n `nul`:::\n \tSimilar to `lines`, but using a _NUL_ character after each value.\n \n-`structure [--format=(table|lines|nul) | -z]`::\n-\tRetrieve statistics about the current repository structure. The\n-\tfollowing kinds of information are reported:\n+`structure [--format=(table|lines|nul) | -z] [<include|^exclude>...]::\n++\n+Retrieve statistics about the current repository structure. The\n+following kinds of information are reported:\n +\n * Reference counts categorized by type\n * Reachable object counts categorized by type\n@@ -66,6 +67,16 @@ supported:\n * Total disk size of reachable objects by type\n * Largest reachable objects in the repository by type\n +\n+The set of objects counted can be filtered by specifying a\n+collection of query clauses to select which objects will be\n+counted. These parameters follow the same syntax as the parameters\n+to similar commands like `git log`. Semantically, these parameters\n+are treated as a collection of include and exclude specifiers. Th\n+set of objects counted will consist of all objects reachable from\n+an object included by one of the include specifiers via a path that\n+does not include an object in an exclude clause. If no includes\n+are specified, then the include set is all reachable objects. \n++\n The output format can be chosen through the flag `--format`. Three formats are\n supported:\n +\n@@ -141,6 +152,28 @@ using the `nul` format:\n git repo info --format=nul layout.bare layout.shallow\n ------------\n \n+* Generates information about storage usage in the repository:\n++\n+------------\n+git repo structure\n+------------\n++\n+\n+* Generates information about storage usage in the repository omitting\n+the branch \"foo\":\n++\n+------------\n+git repo structure ^foo \n+------------\n++\n+* Generates information about repository objects reachable from\n+the references \"x\" and \"y\", but omitting anything that can\n+only be reached on a path including \"xchild\":\n++\n+------------\n+git repo structure x y ^xchild\n+------------\n++\n SEE ALSO\n --------\n linkgit:git-rev-parse[1]\ndiff --git a/builtin/repo.c b/builtin/repo.c\nindex 84e012f83f..b3aca71298 100644\n--- a/builtin/repo.c\n+++ b/builtin/repo.c\n@@ -27,7 +27,7 @@\n \t\"git repo info --keys [--format=(lines|nul) | -z]\"\n \n #define REPO_STRUCTURE_USAGE \\\n-\t\"git repo structure [--format=(table|lines|nul) | -z]\"\n+\t\"git repo structure [--format=(table|lines|nul) | -z] [<include|^exclude>...]\"\n \n static const char *const repo_usage[] = {\n \tREPO_INFO_USAGE,\n@@ -946,12 +946,20 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \t\tOPT_BOOL(0, \"progress\", &show_progress, N_(\"show progress\")),\n \t\tOPT_END()\n \t};\n+\tstruct setup_revision_opt s_r_opt;\n+\tmemset(&s_r_opt, 0, sizeof(s_r_opt));\n+\ts_r_opt.def = \"HEAD\";\n+\ts_r_opt.revarg_opt = REVARG_COMMITTISH;\n \n-\targc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);\n-\tif (argc)\n-\t\tusage(_(\"too many arguments\"));\n+\targc = parse_options(argc, argv, prefix, options, repo_structure_usage,\n+\t\t\t     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);\n \n \trepo_init_revisions(repo, &revs, prefix);\n+\tif (argc > 1) {\n+\t\targc = setup_revisions(argc, argv, &revs, &s_r_opt);\n+\t\tif (argc > 1)\n+\t\t\tusage(_(\"too many arguments\"));\n+\t}\n \n \tif (show_progress < 0)\n \t\tshow_progress = isatty(2);\ndiff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\nindex 02cc2b594a..eb2c595955 100755\n--- a/t/t1901-repo-structure.sh\n+++ b/t/t1901-repo-structure.sh\n@@ -144,6 +144,90 @@ test_expect_success SHA1 'repository with references and objects' '\n \t)\n '\n \n+test_expect_success SHA1 'repository with references and objects, filtered' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+ \t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\t# git-rev-list(1) --disk-usage=human option printing the full\n+\t\t# \"byte/bytes\" unit string instead of just \"B\".\n+\t\tcat >expect <<-EOF &&\n+\t\t| Repository structure      | Value      |\n+\t\t| ------------------------- | ---------- |\n+\t\t| * References              |            |\n+\t\t|   * Count                 |      5     |\n+\t\t|     * Branches            |      2     |\n+\t\t|     * Tags                |      1     |\n+\t\t|     * Remotes             |      1     |\n+\t\t|     * Others              |      1     |\n+\t\t|                           |            |\n+\t\t| * Reachable objects       |            |\n+\t\t|   * Count                 |   3.06 k   |\n+\t\t|     * Commits             |   1.05 k   |\n+\t\t|     * Trees               |   1.01 k   |\n+\t\t|     * Blobs               |   1.01 k   |\n+\t\t|     * Tags                |      1     |\n+\t\t|   * Inflated size         |  16.04 MiB |\n+\t\t|     * Commits             | 226.54 KiB |\n+\t\t|     * Trees               |  15.81 MiB |\n+\t\t|     * Blobs               |  11.68 KiB |\n+\t\t|     * Tags                |    132 B   |\n+\t\t|   * Disk size             | $(object_type_disk_usage all true) |\n+\t\t|     * Commits             | $(object_type_disk_usage commit true) |\n+\t\t|     * Trees               | $(object_type_disk_usage tree true) |\n+\t\t|     * Blobs               |  $(object_type_disk_usage blob true) |\n+\t\t|     * Tags                |    $(object_type_disk_usage tag) B   |\n+\t\t|                           |            |\n+\t\t| * Largest objects         |            |\n+\t\t|   * Commits               |            |\n+\t\t|     * Maximum size    [1] |    223 B   |\n+\t\t|     * Maximum parents [2] |      1     |\n+\t\t|   * Trees                 |            |\n+\t\t|     * Maximum size    [3] |  32.29 KiB |\n+\t\t|     * Maximum entries [4] |   1.01 k   |\n+\t\t|   * Blobs                 |            |\n+\t\t|     * Maximum size    [5] |     13 B   |\n+\t\t|   * Tags                  |            |\n+\t\t|     * Maximum size    [6] |    132 B   |\n+\n+\t\t[1] 0dc91eb18580102a3a216c8bfecedeba2b9f9b9a\n+\t\t[2] df6400c01440c329f1011669c4c26cc0c7852887\n+\t\t[3] 60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\t[4] 60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\t[5] 97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\t[6] 4dae4f5954f5e6feb3577cfb1b181daa3fd3afd2\n+\t\tEOF\n+\n+\t\tgit repo structure  >actual 2>actual-err &&\n+\t\tcp actual /tmp/actual &&\n+\t\tcp expect /tmp/expect &&\n+\t\ttest_cmp expect actual &&\n+\t\ttest_line_count = 0 actual-err &&\n+\n+\t\tgit repo structure grobble ^master >actual 2>actual-err &&\n+\t\tcp actual /tmp &&\n+\t\tcp actual-err /tmp &&\n+\t\ttest_grep \"|     \\* Commits             |    21     |\" actual &&\n+\t\ttest_grep \"|     \\* Trees               |     2     |\" actual &&\n+\t\ttest_grep \"|     \\* Commits             |  4.50 KiB |\" actual &&\n+\t\ttest_grep \"|     \\* Trees               | 32.35 KiB |\" actual &&\n+\t\ttest_grep \"|     \\* Blobs               | 11.68 KiB |\" actual &&\n+\t\ttest_line_count = 0 actual-err\n+\t)\n+'\n+\n test_expect_success SHA1 'lines and nul format' '\n \ttest_when_finished \"rm -rf repo\" &&\n \tgit init repo &&\n-- \n2.53.0\n\n\n"},{"id":"554212","messageId":"DLX4QVXQJTQ4.24JR7ES0P3H@fastmail.com","threadId":"66388","inReplyTo":"ar04uStCZ4pnEJ38@pks.im","subject":"Re: [PATCH 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-05T18:52:27Z","receivedAt":"2026-10-05T18:52:27Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"On Wed Sep 30, 2026 at 12:28 PM EDT, Patrick Steinhardt wrote:\n> On Thu, Sep 24, 2026 at 12:45:03PM -0400, Mark C. Chu-Carroll wrote:\n>> \"git repo structure\" provides a collection of useful information\n>> about the information stored in a repo. In particular, it's\n>> valuable for diagnosing performance issues caused by large objects\n>> stored in a repo.\n>> \n>> The current implementation of \"git repo stucture\" provides summary\n>> information about everything in the repository - all of the\n>> branches, remotes, tags, stashes, and notes. But sometimes\n>> to properly diagnose a problem, it's useful to be able to exclude\n>> refs that are known to not be relevant to the issue at hand.\n>\n> Yes, indeed. Sometimes you may for example want to figure out where\n> exactly the storage size of a particular repository is going. Or in the\n> case of GitLab for example, we may have bookkeeping references that are\n> not controllable by customers. So we may only want to get the structure\n> for all the customer-controllable branches there.\n>\n>> Add a set of flags that allow a user to selective exclude\n>> reference types from the report generated by \"git repo structure\".\n>> When a ref type is excluded by the filter, it no longer appears\n>> in the report (ie, if \"--no-tags\" is passed, the report line\n>> for \"Branches\" will no longer appear under \"* References\").\n>> Following the pattern of flags that are only used to\n>> disable functionality (eg, \"--no-verify\" in \"builtins/push.c\"),\n>> only the \"--no-<reftype>\" syntax is listed in the updated\n>> documentation.\n>\n> Hmm, okay. I would have expected that the user can essentially pass\n> arbitrary revisions as understood by git-log(1) et al. And if they pass\n> any such revisions, we should not enumerate anything but what they have\n> passed, so the flags shouldn't only be used to exclude.\n>\n> So, for example:\n>\n>     $ git repo structure --branches\n>     $ git repo structure master\n>     $ git repo structure --all --not --branches\n>\n> I would hope that git-repo(1) can achieve that rather easily because I\n> expect that it uses `struct rev_info`, but let's read on.\n\nThat makes sense. My initial understanding was that most of what \n\"git repo structure\" does is internalize the functionality of git-sizer\ninto the core of git. The only filters offered by git-sizer are \ntype-based. But I agree that a commit list based filter is a lot \nmore useful, so I've updated the patch set to implement it.\n\n   -Mark\n\n\n\n-- \nMark Craig Chu-Carroll (@MarkChuCarroll at gitlab)\n*** Software Tools/Math Geek - Software Engineer at Gitlab\n*** Work Email: mcarroll@gitlab.com / markchucarroll@fastmail.com\n*** Personal Blog: http://goodmath.org/blog / Personal email: markcc@gmail.com\n\n\n"},{"id":"554235","messageId":"asSMX-K2qLsaXc3v@pks.im","threadId":"66388","inReplyTo":"20261005174045.1900391-2-markchucarroll@fastmail.com","subject":"Re: [PATCH v2 1/1] repo: add filtering options to \"repo structure\"","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-06T05:51:27Z","receivedAt":"2026-10-06T05:51:27Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Oct 05, 2026 at 01:40:44PM -0400, Mark C. Chu-Carroll wrote:\n> Implement filtering for repo structure, imitating the mechanism\n> used in \"git log\".\n\nThe message should give an explanation of what this change does, and\nwhat the motivation behind it is.\n\n> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc\n> index ed7d80c690..5cbdf8e727 100644\n> --- a/Documentation/git-repo.adoc\n> +++ b/Documentation/git-repo.adoc\n> @@ -10,7 +10,7 @@ SYNOPSIS\n>  [synopsis]\n>  git repo info [--format=(lines|nul) | -z] [--all | <key>...]\n>  git repo info --keys [--format=(lines|nul) | -z]\n> -git repo structure [--format=(table|lines|nul) | -z]\n> +git repo structure [--format=(table|lines|nul) | -z] [<include|^exclude>...]\n\nI think we should probably have this be `[<revs>...]`.\n\n> @@ -56,9 +56,10 @@ supported:\n>  `nul`:::\n>  \tSimilar to `lines`, but using a _NUL_ character after each value.\n>  \n> -`structure [--format=(table|lines|nul) | -z]`::\n> -\tRetrieve statistics about the current repository structure. The\n> -\tfollowing kinds of information are reported:\n> +`structure [--format=(table|lines|nul) | -z] [<include|^exclude>...]::\n\nSame here.\n\n> @@ -66,6 +67,16 @@ supported:\n>  * Total disk size of reachable objects by type\n>  * Largest reachable objects in the repository by type\n>  +\n> +The set of objects counted can be filtered by specifying a\n> +collection of query clauses to select which objects will be\n\ns/query clauses/revisions/, which is a well-defined term. So with this\nchange I think we can drop most of the remaining paragraph, except for\nthe last sentence.\n\n> +counted. These parameters follow the same syntax as the parameters\n> +to similar commands like `git log`. Semantically, these parameters\n> +are treated as a collection of include and exclude specifiers. Th\n> +set of objects counted will consist of all objects reachable from\n> +an object included by one of the include specifiers via a path that\n> +does not include an object in an exclude clause. If no includes\n> +are specified, then the include set is all reachable objects. \n> ++\n>  The output format can be chosen through the flag `--format`. Three formats are\n>  supported:\n>  +\n> diff --git a/builtin/repo.c b/builtin/repo.c\n> index 84e012f83f..b3aca71298 100644\n> --- a/builtin/repo.c\n> +++ b/builtin/repo.c\n> @@ -946,12 +946,20 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n>  \t\tOPT_BOOL(0, \"progress\", &show_progress, N_(\"show progress\")),\n>  \t\tOPT_END()\n>  \t};\n> +\tstruct setup_revision_opt s_r_opt;\n> +\tmemset(&s_r_opt, 0, sizeof(s_r_opt));\n> +\ts_r_opt.def = \"HEAD\";\n> +\ts_r_opt.revarg_opt = REVARG_COMMITTISH;\n\nThis can be:\n\n    struct setup_revision_opt s_r_opt = {\n        .def = \"HEAD\",\n        .revarg_opt = REVARG_COMMITTISH,\n    };\n\nBut I wonder whether we want to pass it at all:\n\n  - `.def` specifies the default, but do we even want to have one when\n    the user has passed arguments?\n\n  - `.revarg_opt` makes us treat it like a committish by default, but a\n    user may for example want to figure out the size of all objects\n    reachable from a specific tree, only.\n\nSo maybe we shouldn't be setting this at all and just pass `NULL` to\n`setup_revisions()`?\n\n> -\targc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);\n> -\tif (argc)\n> -\t\tusage(_(\"too many arguments\"));\n> +\targc = parse_options(argc, argv, prefix, options, repo_structure_usage,\n> +\t\t\t     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);\n\nMakes sense. Here we keep argv0 because of `setup_revisions()`' weird\ncalling convention. And we also ignore any unknown options so that we\ncan pass them along, too.\n\n>  \trepo_init_revisions(repo, &revs, prefix);\n> +\tif (argc > 1) {\n> +\t\targc = setup_revisions(argc, argv, &revs, &s_r_opt);\n> +\t\tif (argc > 1)\n> +\t\t\tusage(_(\"too many arguments\"));\n> +\t}\n>  \n>  \tif (show_progress < 0)\n>  \t\tshow_progress = isatty(2);\n\nAnd then, if we have any additional parameters then we pass it on to\n`setup_revisions()`.\n\n> diff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\n> index 02cc2b594a..eb2c595955 100755\n> --- a/t/t1901-repo-structure.sh\n> +++ b/t/t1901-repo-structure.sh\n> @@ -144,6 +144,90 @@ test_expect_success SHA1 'repository with references and objects' '\n>  \t)\n>  '\n>  \n> +test_expect_success SHA1 'repository with references and objects, filtered' '\n> +\ttest_when_finished \"rm -rf repo\" &&\n> +\tgit init repo &&\n> +\t(\n> +\t\tcd repo &&\n> +\t\ttest_commit_bulk 1005 &&\n> +\t\tgit tag -a foo -m bar &&\n> +\n> +\t\toid=\"$(git rev-parse HEAD)\" &&\n> +\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n> +\t\tgit checkout -b grobble &&\n> +\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n> +\t\tgit checkout master &&\n> + \t\ttest_commit_bulk 20 &&\n> +\t\t# Also creates a commit, tree, and blob.\n> +\t\tgit notes add -m foo &&\n> +\n> +\t\t# git-rev-list(1) --disk-usage=human option printing the full\n> +\t\t# \"byte/bytes\" unit string instead of just \"B\".\n> +\t\tcat >expect <<-EOF &&\n> +\t\t| Repository structure      | Value      |\n> +\t\t| ------------------------- | ---------- |\n> +\t\t| * References              |            |\n> +\t\t|   * Count                 |      5     |\n> +\t\t|     * Branches            |      2     |\n> +\t\t|     * Tags                |      1     |\n> +\t\t|     * Remotes             |      1     |\n> +\t\t|     * Others              |      1     |\n> +\t\t|                           |            |\n> +\t\t| * Reachable objects       |            |\n> +\t\t|   * Count                 |   3.06 k   |\n> +\t\t|     * Commits             |   1.05 k   |\n> +\t\t|     * Trees               |   1.01 k   |\n> +\t\t|     * Blobs               |   1.01 k   |\n> +\t\t|     * Tags                |      1     |\n> +\t\t|   * Inflated size         |  16.04 MiB |\n> +\t\t|     * Commits             | 226.54 KiB |\n> +\t\t|     * Trees               |  15.81 MiB |\n> +\t\t|     * Blobs               |  11.68 KiB |\n> +\t\t|     * Tags                |    132 B   |\n> +\t\t|   * Disk size             | $(object_type_disk_usage all true) |\n> +\t\t|     * Commits             | $(object_type_disk_usage commit true) |\n> +\t\t|     * Trees               | $(object_type_disk_usage tree true) |\n> +\t\t|     * Blobs               |  $(object_type_disk_usage blob true) |\n> +\t\t|     * Tags                |    $(object_type_disk_usage tag) B   |\n> +\t\t|                           |            |\n> +\t\t| * Largest objects         |            |\n> +\t\t|   * Commits               |            |\n> +\t\t|     * Maximum size    [1] |    223 B   |\n> +\t\t|     * Maximum parents [2] |      1     |\n> +\t\t|   * Trees                 |            |\n> +\t\t|     * Maximum size    [3] |  32.29 KiB |\n> +\t\t|     * Maximum entries [4] |   1.01 k   |\n> +\t\t|   * Blobs                 |            |\n> +\t\t|     * Maximum size    [5] |     13 B   |\n> +\t\t|   * Tags                  |            |\n> +\t\t|     * Maximum size    [6] |    132 B   |\n> +\n> +\t\t[1] 0dc91eb18580102a3a216c8bfecedeba2b9f9b9a\n> +\t\t[2] df6400c01440c329f1011669c4c26cc0c7852887\n> +\t\t[3] 60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n> +\t\t[4] 60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n> +\t\t[5] 97d808e45116bf02103490294d3d46dad7a2ac62\n> +\t\t[6] 4dae4f5954f5e6feb3577cfb1b181daa3fd3afd2\n> +\t\tEOF\n> +\n> +\t\tgit repo structure  >actual 2>actual-err &&\n> +\t\tcp actual /tmp/actual &&\n> +\t\tcp expect /tmp/expect &&\n> +\t\ttest_cmp expect actual &&\n> +\t\ttest_line_count = 0 actual-err &&\n> +\n> +\t\tgit repo structure grobble ^master >actual 2>actual-err &&\n> +\t\tcp actual /tmp &&\n> +\t\tcp actual-err /tmp &&\n> +\t\ttest_grep \"|     \\* Commits             |    21     |\" actual &&\n> +\t\ttest_grep \"|     \\* Trees               |     2     |\" actual &&\n> +\t\ttest_grep \"|     \\* Commits             |  4.50 KiB |\" actual &&\n> +\t\ttest_grep \"|     \\* Trees               | 32.35 KiB |\" actual &&\n> +\t\ttest_grep \"|     \\* Blobs               | 11.68 KiB |\" actual &&\n> +\t\ttest_line_count = 0 actual-err\n> +\t)\n> +'\n\nI wonder whether we maybe want to have some additional tests that assert\nthat you can also pass e.g.:\n\n  - A tree or blob.\n\n  - Revision options, like for example `--all --filter=object:type=blob`.\n\nTo make the test a bit less repetitive we might also want to use\n`--format=lines` and then only check for\n\"objects.*.{inflated,disk}_size\" to exercise only the parts that matter\nto this test.\n\nThanks!\n\nPatrick\n\n"},{"id":"554510","messageId":"07eeee7c-4086-4b7f-b59c-74ba7227d6e0@gmail.com","threadId":"66388","inReplyTo":"asSMX-K2qLsaXc3v@pks.im","subject":"Re: [PATCH v2 1/1] repo: add filtering options to \"repo structure\"","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2026-10-08T15:46:09Z","receivedAt":"2026-10-08T15:46:09Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"On 10/6/26 11:21, Patrick Steinhardt wrote:\n> On Mon, Oct 05, 2026 at 01:40:44PM -0400, Mark C. Chu-Carroll wrote:\n>> Implement filtering for repo structure, imitating the mechanism\n>> used in \"git log\".\n> > The message should give an explanation of what this change does, and\n> what the motivation behind it is.\n> Indeed. The cover letter provides more context about the change. I think it makes sense to include a significant portion of the cover letter in the commit message. We could even likely drop the cover letter altogether if it feels to add no value.\n\nThat said,\n\n> repo: add filtering options to \"repo structure\"\n\nI think the following may be a better commit title:\n\n  repo: add revision filtering support to \"repo structure\"\n\n-- \nSivaraam\n\n\n"},{"id":"554620","messageId":"DM0FD46SBK3O.1YAZ1A9YPENY@fastmail.com","threadId":"66388","inReplyTo":"07eeee7c-4086-4b7f-b59c-74ba7227d6e0@gmail.com","subject":"Re: [PATCH v2 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-09T15:49:40Z","receivedAt":"2026-10-09T15:49:40Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"On Thu Oct 8, 2026 at 11:46 AM EDT, Kaartic Sivaraam wrote:\n> On 10/6/26 11:21, Patrick Steinhardt wrote:\n>> On Mon, Oct 05, 2026 at 01:40:44PM -0400, Mark C. Chu-Carroll wrote:\n>>> Implement filtering for repo structure, imitating the mechanism\n>>> used in \"git log\".\n>> \n>> The message should give an explanation of what this change does, and\n>> what the motivation behind it is.\n>> \n>\n> Indeed. The cover letter provides more context about the change. I think \n> it makes sense to include a significant portion of the cover letter in \n> the commit message. We could even likely drop the cover letter \n> altogether if it feels to add no value.\n>\n> That said,\n>\n>  > repo: add filtering options to \"repo structure\"\n>\n> I think the following may be a better commit title:\n>\n>    repo: add revision filtering support to \"repo structure\"\n \nYou're right - that's much better.\n\n    -Mark\n\n\n\n\n-- \nMark Craig Chu-Carroll (@MarkChuCarroll at gitlab)\n*** Software Tools/Math Geek - Software Engineer at Gitlab\n*** Work Email: mcarroll@gitlab.com / markchucarroll@fastmail.com\n*** Personal Blog: http://goodmath.org/blog / Personal email: markcc@gmail.com\n\n\n"},{"id":"554625","messageId":"20261009180951.1628134-1-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20260924164503.119506-2-markchucarroll@fastmail.com","subject":"[PATCH v3 0/1] repo: add revision filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-09T18:09:50Z","receivedAt":"2026-10-09T18:09:50Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"\"git repo structure\" provides a collection of useful information\nabout the information stored in a repo. In particular, it's\nvaluable for diagnosing performance issues caused by large objects\nstored in a repo.\n\nThe current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to get\ninformation about the specific part of the repo that's exhibiting\na problem.\n\nAdd the option to specify a set of revs. If revs are included,\nthen the set of objects processed will be limited based on the\nrev specification; otherwise, all objects will be processed.\n\nMark C. Chu-Carroll (1):\n  repo: add revision filtering options to \"repo structure\"\n\n Documentation/git-repo.adoc     |  37 +++++-\n Documentation/git-rev-list.adoc |   2 +-\n Documentation/revisions.adoc    |   2 +-\n builtin/repo.c                  |  32 +++--\n revision.c                      |   2 +-\n revision.h                      |   2 +-\n t/t1901-repo-structure.sh       | 211 ++++++++++++++++++++++++--------\n 7 files changed, 217 insertions(+), 71 deletions(-)\n\n-- \n2.53.0\n\n\n"},{"id":"554626","messageId":"20261009180951.1628134-2-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20261009180951.1628134-1-markchucarroll@fastmail.com","subject":"[PATCH v3 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-09T18:09:51Z","receivedAt":"2026-10-09T18:09:51Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"The current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to\nfilter this information to get focused data about the specific\npart of the repo that's exhibiting a problem.\n\nUpdate \"git repo structure\" to use rev expressions\nto filter the set of objects to be processed.\n\nThis implementation makes an awkward trade-off involving\n\"setup_revisions\". In order to accept standard the standard\nrevs parameters, it uses `setup_revisions`, which does a ref\nwalk and populates the pending objects list that will be used\nby \"repo structure\". But this ref walk doesn't count refs in the\nway that \"repo structure\" requires, and because \"setup_revisions\"\ndoesn't support a custom callback for its ref-walk, that's not\nchangeable.\n\nSo in the cases where a user specifies revs, \"repo structure\" does\nan initial ref-walk as part of \"setup_revisions\", and then a second\nref-walk in \"count_references\" in repo.c to count by reference type.\nFurther, if the user doesn't specify a revs parameter, \"setup_revisions\"\nis not called, so the \"count_references\" walk needs to add objects\nto the pending list. A parameter is added to \"count_references\"\nto allow it to distinguish the cases where the pending\nlist is already populated from the case where it needs to\npopulate it.\n\nSigned-off-by: Mark C. Chu-Carroll <markchucarroll@fastmail.com>\n---\n Documentation/git-repo.adoc     |  37 +++++-\n Documentation/git-rev-list.adoc |   2 +-\n Documentation/revisions.adoc    |   2 +-\n builtin/repo.c                  |  32 +++--\n revision.c                      |   2 +-\n revision.h                      |   2 +-\n t/t1901-repo-structure.sh       | 211 ++++++++++++++++++++++++--------\n 7 files changed, 217 insertions(+), 71 deletions(-)\n\ndiff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc\nindex ed7d80c690..d2cbabd330 100644\n--- a/Documentation/git-repo.adoc\n+++ b/Documentation/git-repo.adoc\n@@ -10,7 +10,7 @@ SYNOPSIS\n [synopsis]\n git repo info [--format=(lines|nul) | -z] [--all | <key>...]\n git repo info --keys [--format=(lines|nul) | -z]\n-git repo structure [--format=(table|lines|nul) | -z]\n+git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\n \n DESCRIPTION\n -----------\n@@ -56,9 +56,10 @@ supported:\n `nul`:::\n \tSimilar to `lines`, but using a _NUL_ character after each value.\n \n-`structure [--format=(table|lines|nul) | -z]`::\n-\tRetrieve statistics about the current repository structure. The\n-\tfollowing kinds of information are reported:\n+`structure [--format=(table|lines|nul) | -z] [<revs>...]::\n++\n+Retrieve statistics about the current repository structure. The\n+following kinds of information are reported:\n +\n * Reference counts categorized by type\n * Reachable object counts categorized by type\n@@ -66,6 +67,12 @@ supported:\n * Total disk size of reachable objects by type\n * Largest reachable objects in the repository by type\n +\n+The set of objects counted can be filtered by specifying a collection\n+of revisions to select which objects will be counted. These parameters\n+follow the same syntax as the parameters to similar commands like\n+`git log`. If no includes are specified, then the include set is all\n+reachable objects.\n++\n The output format can be chosen through the flag `--format`. Three formats are\n supported:\n +\n@@ -141,6 +148,28 @@ using the `nul` format:\n git repo info --format=nul layout.bare layout.shallow\n ------------\n \n+* Generates information about storage usage in the repository:\n++\n+------------\n+git repo structure\n+------------\n++\n+\n+* Generates information about storage usage in the repository omitting\n+the branch \"foo\":\n++\n+------------\n+git repo structure ^foo\n+------------\n++\n+* Generates information about repository objects reachable from\n+the references \"x\" and \"y\", but omitting anything that can\n+only be reached on a path including \"xchild\":\n++\n+------------\n+git repo structure x y ^xchild\n+------------\n++\n SEE ALSO\n --------\n linkgit:git-rev-parse[1]\ndiff --git a/Documentation/git-rev-list.adoc b/Documentation/git-rev-list.adoc\nindex f582491dd4..05f16a1146 100644\n--- a/Documentation/git-rev-list.adoc\n+++ b/Documentation/git-rev-list.adoc\n@@ -114,7 +114,7 @@ do\n done |\n sort -n\n ----------\n-\n+p\n * Compare the on-disk size of branches in one group of refs, excluding\n   another. If you co-mingle objects from multiple remotes in a single\n   repository, this can show which remotes are contributing to the\ndiff --git a/Documentation/revisions.adoc b/Documentation/revisions.adoc\nindex 3fbfbd3d5f..4391f8daa6 100644\n--- a/Documentation/revisions.adoc\n+++ b/Documentation/revisions.adoc\n@@ -226,7 +226,7 @@ existing tag object.\n   This is most useful to address a blob or tree from a commit or tree that has\n   the same tree structure as the working tree.\n \n-':[<n>:]<path>', e.g. ':0:README', ':README'::\n+ ':[<n>:]<path>', e.g. ':0:README', ':README'::\n   A colon, optionally followed by a stage number (0 to 3) and a\n   colon, followed by a path, names a blob object in the\n   index at the given path. A missing stage number (and the colon\ndiff --git a/builtin/repo.c b/builtin/repo.c\nindex 84e012f83f..081940a85c 100644\n--- a/builtin/repo.c\n+++ b/builtin/repo.c\n@@ -27,7 +27,7 @@\n \t\"git repo info --keys [--format=(lines|nul) | -z]\"\n \n #define REPO_STRUCTURE_USAGE \\\n-\t\"git repo structure [--format=(table|lines|nul) | -z]\"\n+\t\"git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\"\n \n static const char *const repo_usage[] = {\n \tREPO_INFO_USAGE,\n@@ -740,6 +740,7 @@ struct count_references_data {\n \tstruct ref_stats *stats;\n \tstruct rev_info *revs;\n \tstruct progress *progress;\n+\tbool add_to_pending;\n };\n \n static int count_references(const struct reference *ref, void *cb_data)\n@@ -766,10 +767,12 @@ static int count_references(const struct reference *ref, void *cb_data)\n \t}\n \n \t/*\n-\t * While iterating through references for counting, also add OIDs in\n+\t * While iterating through references for counting, if we didn't already\n+\t * populate the pending list in setup_revisions, also add OIDs in\n \t * preparation for the path walk.\n \t */\n-\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n+\tif (data->add_to_pending)\n+\t\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n \n \tref_count = get_total_reference_count(stats);\n \tdisplay_progress(data->progress, ref_count);\n@@ -780,11 +783,13 @@ static int count_references(const struct reference *ref, void *cb_data)\n static void structure_count_references(struct ref_stats *stats,\n \t\t\t\t       struct rev_info *revs,\n \t\t\t\t       struct repository *repo,\n-\t\t\t\t       int show_progress)\n+\t\t\t\t       int show_progress,\n+\t\t\t\t       bool add_to_pending)\n {\n \tstruct count_references_data data = {\n \t\t.stats = stats,\n \t\t.revs = revs,\n+\t\t.add_to_pending = add_to_pending\n \t};\n \n \tif (show_progress)\n@@ -935,6 +940,7 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \tstruct repo_structure stats = { 0 };\n \tstruct rev_info revs;\n \tint show_progress = -1;\n+\tbool included_revision_args = false;\n \tstruct option options[] = {\n \t\tOPT_CALLBACK_F(0, \"format\", &format, N_(\"format\"),\n \t\t\t       N_(\"output format\"),\n@@ -947,16 +953,20 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \t\tOPT_END()\n \t};\n \n-\targc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);\n-\tif (argc)\n-\t\tusage(_(\"too many arguments\"));\n-\n-\trepo_init_revisions(repo, &revs, prefix);\n-\n+\targc = parse_options(argc, argv, prefix, options, repo_structure_usage,\n+\t\t\t     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);\n \tif (show_progress < 0)\n \t\tshow_progress = isatty(2);\n \n-\tstructure_count_references(&stats.refs, &revs, repo, show_progress);\n+\trepo_init_revisions(repo, &revs, prefix);\n+\tif (argc > 1) {\n+\t\targc = setup_revisions(argc, argv, &revs, NULL);\n+\t\tincluded_revision_args = true;\n+\t}\n+\tif (argc > 1)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tstructure_count_references(&stats.refs, &revs, repo, show_progress, !included_revision_args);\n \tstructure_count_objects(&stats.objects, &revs, repo, show_progress);\n \n \tswitch (format) {\ndiff --git a/revision.c b/revision.c\nindex ee1df92d1d..79d44b58b5 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -2837,7 +2837,7 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,\n \t * NOTE!\n \t *\n \t * Commands like \"git shortlog\" will not accept the options below\n-\t * unless parse_revision_opt queues them (as opposed to erroring\n+\t * unless parse_revision_op\tt queues them (as opposed to erroring\n \t * out).\n \t *\n \t * When implementing your new pseudo-option, remember to\ndiff --git a/revision.h b/revision.h\nindex e5dabd18ce..63135c5f88 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -125,7 +125,7 @@ struct topo_walk_info;\n \n struct rev_info {\n \t/*\n-\t * Work queue of commits, stored as either a linked list or a\n+~\t * Work queue of commits, stored as either a linked list or a\n \t * priority queue, but never both at the same time.\n \t * rev_info_commit_list_to_queue() converts list to queue.\n \t */\ndiff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\nindex 02cc2b594a..e35b46a277 100755\n--- a/t/t1901-repo-structure.sh\n+++ b/t/t1901-repo-structure.sh\n@@ -21,58 +21,6 @@ object_type_disk_usage() {\n \tfi\n }\n \n-test_expect_success 'empty repository' '\n-\ttest_when_finished \"rm -rf repo\" &&\n-\tgit init repo &&\n-\t(\n-\t\tcd repo &&\n-\t\tcat >expect <<-\\EOF &&\n-\t\t| Repository structure      | Value  |\n-\t\t| ------------------------- | ------ |\n-\t\t| * References              |        |\n-\t\t|   * Count                 |    0   |\n-\t\t|     * Branches            |    0   |\n-\t\t|     * Tags                |    0   |\n-\t\t|     * Remotes             |    0   |\n-\t\t|     * Others              |    0   |\n-\t\t|                           |        |\n-\t\t| * Reachable objects       |        |\n-\t\t|   * Count                 |    0   |\n-\t\t|     * Commits             |    0   |\n-\t\t|     * Trees               |    0   |\n-\t\t|     * Blobs               |    0   |\n-\t\t|     * Tags                |    0   |\n-\t\t|   * Inflated size         |    0 B |\n-\t\t|     * Commits             |    0 B |\n-\t\t|     * Trees               |    0 B |\n-\t\t|     * Blobs               |    0 B |\n-\t\t|     * Tags                |    0 B |\n-\t\t|   * Disk size             |    0 B |\n-\t\t|     * Commits             |    0 B |\n-\t\t|     * Trees               |    0 B |\n-\t\t|     * Blobs               |    0 B |\n-\t\t|     * Tags                |    0 B |\n-\t\t|                           |        |\n-\t\t| * Largest objects         |        |\n-\t\t|   * Commits               |        |\n-\t\t|     * Maximum size        |    0 B |\n-\t\t|     * Maximum parents     |    0   |\n-\t\t|   * Trees                 |        |\n-\t\t|     * Maximum size        |    0 B |\n-\t\t|     * Maximum entries     |    0   |\n-\t\t|   * Blobs                 |        |\n-\t\t|     * Maximum size        |    0 B |\n-\t\t|   * Tags                  |        |\n-\t\t|     * Maximum size        |    0 B |\n-\t\tEOF\n-\n-\t\tgit repo structure >out 2>err &&\n-\n-\t\ttest_cmp expect out &&\n-\t\ttest_line_count = 0 err\n-\t)\n-'\n-\n test_expect_success SHA1 'repository with references and objects' '\n \ttest_when_finished \"rm -rf repo\" &&\n \tgit init repo &&\n@@ -144,6 +92,165 @@ test_expect_success SHA1 'repository with references and objects' '\n \t)\n '\n \n+test_expect_success SHA1 'repository with branches' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\t\tgit repo structure --format=lines  >actual 2>actual-err &&\n+\t\ttest_line_count = 0 actual-err &&\n+\t\ttest_grep \"objects.commits.inflated.size=231976\" actual &&\n+\t\ttest_grep \"objects.commits.count=1046\" actual &&\n+\t\ttest_grep \"objects.blobs.count=1006\" actual &&\n+\t\ttest_grep \"objects.trees.count=1006\" actual &&\n+\t\ttest_grep \"objects.trees.disk_size=284547\" actual &&\n+\t\ttest_grep \"objects.blobs.disk_size=21022\" actual &&\n+\t\ttest_grep \"objects.tags.disk_size=126\" actual &&\n+\t\ttest_line_count = 0 actual-err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by a positive rev' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\tgit notes add -m foo &&\n+\n+\t\tgit repo structure --format=lines grobble >actual 2>actual-err &&\n+\t\ttest_grep \"objects.commits.count=1025\" actual &&\n+\t\ttest_grep \"objects.commits.disk_size=160455\" actual &&\n+\t\ttest_grep \"objects.commits.inflated.size=227371\" actual &&\n+\t\ttest_grep \"objects.blobs.count=1005\" actual &&\n+\t\ttest_grep \"objects.blobs.disk_size=21003\" actual &&\n+\t\ttest_grep \"objects.blobs.inflated_size=11958\" actual &&\n+\t\ttest_grep \"objects.trees.count=1005\" actual &&\n+\t\ttest_grep \"objects.trees.disk_size=284462\" actual &&\n+\t\ttest_grep \"objects.trees.inflated_size=16578363\" actual &&\n+\t\ttest_grep \"objects.tags.disk_size=0\" actual &&\n+\t\ttest_line_count = 0 actual-err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by both positive and negative revs' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\t\tgit repo structure --format=lines  >actual 2>actual-err &&\n+\t\ttest_line_count = 0 actual-err &&\n+\n+\t\tgit repo structure --format=lines grobble ^master >actual 2>actual-err &&\n+\t\ttest_grep \"objects.commits.count=20\" actual &&\n+\t\ttest_grep \"objects.commits.disk_size=3122\" actual &&\n+\t\ttest_grep \"objects.commits.inflated.size=4411\" actual &&\n+\t\ttest_grep \"objects.blobs.count=1005\" actual &&\n+\t\ttest_grep \"objects.blobs.disk_size=21003\" actual &&\n+\t\ttest_grep \"objects.blobs.inflated_size=11958\" actual &&\n+\t\ttest_grep \"objects.trees.count=1\" actual &&\n+\t\ttest_grep \"objects.trees.disk_size=53\" actual &&\n+\t\ttest_grep \"objects.trees.inflated_size=33063\" actual &&\n+\t\ttest_grep \"objects.tags.disk_size=0\" actual &&\n+\t\ttest_line_count = 0 actual-err\n+\t)\n+'\n+\n+test_expect_success 'filter by object type' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\t\tgit repo structure --format=lines --objects --all --filter=object:type=blob >actual 2>actual-err &&\n+\t\tcp actual /tmp/test-actual-exclude-blob &&\n+\t\ttest_grep \"objects.commits.disk_size=0\" actual &&\n+\t\ttest_grep \"objects.commits.max_size=0\" actual &&\n+\t\ttest_grep \"objects.tags.disk_size=0\" actual &&\n+\t\ttest_grep \"objects.tags.inflated_size=0\" actual &&\n+\t\ttest_grep \"objects.trees.disk_size=0\" actual &&\n+\t\ttest_grep \"objects.trees.inflated_size=0\" actual &&\n+\t\ttest_grep \"objects.blobs.disk_size=21022\" actual &&\n+\t\ttest_grep \"objects.blobs.count=1006\" actual &&\n+\t\ttest_grep \"objects.blobs.disk_size=21022\" actual &&\n+\t\ttest_grep \"objects.blobs.inflated_size=11962\" actual &&\n+\t\ttest_line_count = 0 actual-err\n+\t)\n+'\n+\n+test_expect_success 'filter using by ref^{tree}' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\t\tgit repo structure --format=lines HEAD^{tree}  >actual 2>err &&\n+\t\ttest_grep \"objects.commits.count=0\" actual &&\n+\t\ttest_grep \"objects.trees.count=1\" actual &&\n+\t\ttest_grep \"objects.blobs.count=1005\" actual &&\n+\t\ttest_grep \"objects.tags.count=0\" actual &&\n+\t\ttest_grep \"objects.commits.inflated_size=0\" actual &&\n+\t\ttest_grep \"objects.trees.inflated_size=33063\" actual &&\n+\t\ttest_grep \"objects.blobs.inflated_size=11958\" actual &&\n+\t\ttest_grep \"objects.tags.inflated_size=0\" actual &&\n+\t\ttest_grep \"objects.commits.disk_size=0\" actual &&\n+\t\ttest_grep \"objects.trees.disk_size=53\" actual &&\n+\t\ttest_grep \"objects.blobs.disk_size=21003\" actual &&\n+\t\ttest_grep \"objects.tags.disk_size=0\" actual &&\n+\t\ttest_line_count = 0 err\n+\t)\n+'\n+\n test_expect_success SHA1 'lines and nul format' '\n \ttest_when_finished \"rm -rf repo\" &&\n \tgit init repo &&\n-- \n2.53.0\n\n\n"},{"id":"554663","messageId":"xmqqse2elg8j.fsf@gitster.g","threadId":"66388","inReplyTo":"20261009180951.1628134-2-markchucarroll@fastmail.com","subject":"Re: [PATCH v3 1/1] repo: add filtering options to \"repo structure\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-09T21:24:28Z","receivedAt":"2026-10-09T21:24:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Mark C. Chu-Carroll\" <markchucarroll@fastmail.com> writes:\n\n> diff --git a/revision.c b/revision.c\n> index ee1df92d1d..79d44b58b5 100644\n> --- a/revision.c\n> +++ b/revision.c\n> @@ -2837,7 +2837,7 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,\n>  \t * NOTE!\n>  \t *\n>  \t * Commands like \"git shortlog\" will not accept the options below\n> -\t * unless parse_revision_opt queues them (as opposed to erroring\n> +\t * unless parse_revision_op\tt queues them (as opposed to erroring\n>  \t * out).\n>  \t *\n>  \t * When implementing your new pseudo-option, remember to\n\nWhat is this change about?\n\n> diff --git a/revision.h b/revision.h\n> index e5dabd18ce..63135c5f88 100644\n> --- a/revision.h\n> +++ b/revision.h\n> @@ -125,7 +125,7 @@ struct topo_walk_info;\n>  \n>  struct rev_info {\n>  \t/*\n> -\t * Work queue of commits, stored as either a linked list or a\n> +~\t * Work queue of commits, stored as either a linked list or a\n>  \t * priority queue, but never both at the same time.\n>  \t * rev_info_commit_list_to_queue() converts list to queue.\n>  \t */\n\nDitto.\n\nEverybody makes mistakes during their editing, and occasionally fat\nthumb hits unintended keys while the cursor is in an area one is not\nediting at all.  Mistakes happen and that is perfectly OK.\n\nBut a hunk like this one in a submitted patch is a clear sign that\neven the author is not reading what they are sending out.  And this\npatch, among its 16 hunks, two are such hunks that was never\nproofread.\n\nQuite honestly, it is beyond me how anybody would expect others to\nseriously take their time to review such a patch.\n\nGrumble.\n\n"},{"id":"554690","messageId":"DM18BTUM3WZH.3S2G5JAJ93AXC@fastmail.com","threadId":"66388","inReplyTo":"xmqqse2elg8j.fsf@gitster.g","subject":"Re: [PATCH v3 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-10T14:31:31Z","receivedAt":"2026-10-10T14:31:31Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"On Fri Oct 9, 2026 at 5:24 PM EDT, Junio C Hamano wrote:\n> \"Mark C. Chu-Carroll\" <markchucarroll@fastmail.com> writes:\n>\n>> diff --git a/revision.c b/revision.c\n>> index ee1df92d1d..79d44b58b5 100644\n>> --- a/revision.c\n>> +++ b/revision.c\n>> @@ -2837,7 +2837,7 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,\n>>  \t * NOTE!\n>>  \t *\n>>  \t * Commands like \"git shortlog\" will not accept the options below\n>> -\t * unless parse_revision_opt queues them (as opposed to erroring\n>> +\t * unless parse_revision_op\tt queues them (as opposed to erroring\n>>  \t * out).\n>>  \t *\n>>  \t * When implementing your new pseudo-option, remember to\n>\n> What is this change about?\n>\n>> diff --git a/revision.h b/revision.h\n>> index e5dabd18ce..63135c5f88 100644\n>> --- a/revision.h\n>> +++ b/revision.h\n>> @@ -125,7 +125,7 @@ struct topo_walk_info;\n>>  \n>>  struct rev_info {\n>>  \t/*\n>> -\t * Work queue of commits, stored as either a linked list or a\n>> +~\t * Work queue of commits, stored as either a linked list or a\n>>  \t * priority queue, but never both at the same time.\n>>  \t * rev_info_commit_list_to_queue() converts list to queue.\n>>  \t */\n>\n> Ditto.\n>\n> Everybody makes mistakes during their editing, and occasionally fat\n> thumb hits unintended keys while the cursor is in an area one is not\n> editing at all.  Mistakes happen and that is perfectly OK.\n>\n> But a hunk like this one in a submitted patch is a clear sign that\n> even the author is not reading what they are sending out.  And this\n> patch, among its 16 hunks, two are such hunks that was never\n> proofread.\n>\n> Quite honestly, it is beyond me how anybody would expect others to\n> seriously take their time to review such a patch.\n\nI'm really sorry - I honestly don't know how this slipped through.\nI went through _so_ many revisions of this patch trying to make sure\nthat everything was correct. I caught this mistake and fixed it, but\nfat-fingered and sent the wrong version. I'm really annoyed at myself -\nI've put a lot of time into this change. I got the hard parts right,\nand went and found a way to screw up the simple part - sending the\nright $^#&@! version.\n\n\n\n\n-- \nMark Craig Chu-Carroll (@MarkChuCarroll at gitlab)\n*** Software Tools/Math Geek - Software Engineer at Gitlab\n*** Work Email: mcarroll@gitlab.com / markchucarroll@fastmail.com\n*** Personal Blog: http://goodmath.org/blog / Personal email: markcc@gmail.com\n\n\n"},{"id":"554691","messageId":"20261010150539.930614-2-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20260924164503.119506-2-markchucarroll@fastmail.com","subject":"[PATCH v4 0/1] repo: add revision filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-10T15:05:39Z","receivedAt":"2026-10-10T15:05:39Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"\"git repo structure\" provides a collection of useful information                                                        \nabout the information stored in a repo. In particular, it's                                                             \nvaluable for diagnosing performance issues caused by large objects                                                      \nstored in a repo.                                                                                                       \n                                                                                                                        \nThe current implementation of \"git repo stucture\" provides summary                                                      \ninformation about everything in the repository - all of the                                                             \nbranches, remotes, tags, stashes, and notes. But sometimes                                                              \nto properly diagnose a problem, it's useful to be able to get                                                           \ninformation about the specific part of the repo that's exhibiting                                                       \na problem.                                                                                                              \n                                                                                                                        \nAdd the option to specify a set of revs. If revs are included,                                                          \nthen the set of objects processed will be limited based on the                                                          \nrev specification; otherwise, all objects will be processed.\n\nDifferences from v3:\n- Remove inadvertent edits.\n- Ensure that this is the right version of the patch, because I'm an idiot.\n\n\nMark C. Chu-Carroll (1):\n  repo: add revision filtering options to \"repo structure\"\n\n Documentation/git-repo.adoc |  32 +++++-\n builtin/repo.c              |  32 ++++--\n t/t1901-repo-structure.sh   | 211 +++++++++++++++++++++++++++---------\n 3 files changed, 210 insertions(+), 65 deletions(-)\n\n-- \n2.53.0\n\n\n"},{"id":"554692","messageId":"20261010150539.930614-4-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20261010150539.930614-2-markchucarroll@fastmail.com","subject":"[PATCH v4 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-10T15:05:41Z","receivedAt":"2026-10-10T15:05:41Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"The current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to\nfilter this information to get focused data about the specific\npart of the repo that's exhibiting a problem.\n\nUpdate \"git repo structure\" to use rev expressions\nto filter the set of objects to be processed.\n\nThis implementation makes an awkward trade-off involving\n\"setup_revisions\". In order to accept standard the standard\nrevs parameters, it uses `setup_revisions`, which does a ref\nwalk and populates the pending objects list that will be used\nby \"repo structure\". But this ref walk doesn't count refs in the\nway that \"repo structure\" requires, and because \"setup_revisions\"\ndoesn't support a custom callback for its ref-walk, that's not\nchangeable.\n\nSo in the cases where a user specifies revs, \"repo structure\" does\nan initial ref-walk as part of \"setup_revisions\", and then a second\nref-walk in \"count_references\" in repo.c to count by reference type.\nFurther, if the user doesn't specify a revs parameter, \"setup_revisions\"\nis not called, so the \"count_references\" walk needs to add objects\nto the pending list. A parameter is added to \"count_references\"\nto allow it to distinguish the cases where the pending\nlist is already populated from the case where it needs to\npopulate it.\n\nSigned-off-by: Mark C. Chu-Carroll <markchucarroll@fastmail.com>\n---\n Documentation/git-repo.adoc |  32 +++++-\n builtin/repo.c              |  32 ++++--\n t/t1901-repo-structure.sh   | 211 +++++++++++++++++++++++++++---------\n 3 files changed, 210 insertions(+), 65 deletions(-)\n\ndiff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc\nindex ed7d80c690..67be7efd23 100644\n--- a/Documentation/git-repo.adoc\n+++ b/Documentation/git-repo.adoc\n@@ -10,7 +10,7 @@ SYNOPSIS\n [synopsis]\n git repo info [--format=(lines|nul) | -z] [--all | <key>...]\n git repo info --keys [--format=(lines|nul) | -z]\n-git repo structure [--format=(table|lines|nul) | -z]\n+git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\n \n DESCRIPTION\n -----------\n@@ -56,7 +56,7 @@ supported:\n `nul`:::\n \tSimilar to `lines`, but using a _NUL_ character after each value.\n \n-`structure [--format=(table|lines|nul) | -z]`::\n+`structure [--format=(table|lines|nul) | -z] [<revs>...]`::\n \tRetrieve statistics about the current repository structure. The\n \tfollowing kinds of information are reported:\n +\n@@ -66,6 +66,12 @@ supported:\n * Total disk size of reachable objects by type\n * Largest reachable objects in the repository by type\n +\n+The set of objects counted can be filtered by specifying a collection\n+of revisions to select which objects will be counted. These parameters\n+follow the same syntax as the parameters to similar commands like\n+`git log`. If no includes are specified, then the include set is all\n+reachable objects.\n++\n The output format can be chosen through the flag `--format`. Three formats are\n supported:\n +\n@@ -141,6 +147,28 @@ using the `nul` format:\n git repo info --format=nul layout.bare layout.shallow\n ------------\n \n+* Generates information about storage usage in the repository:\n++\n+------------\n+git repo structure\n+------------\n++\n+\n+* Generates information about storage usage in the repository omitting\n+the branch \"foo\":\n++\n+------------\n+git repo structure ^foo\n+------------\n++\n+* Generates information about repository objects reachable from\n+the references \"x\" and \"y\", but omitting anything that can\n+only be reached on a path including \"xchild\":\n++\n+------------\n+git repo structure x y ^xchild\n+------------\n++\n SEE ALSO\n --------\n linkgit:git-rev-parse[1]\ndiff --git a/builtin/repo.c b/builtin/repo.c\nindex 84e012f83f..081940a85c 100644\n--- a/builtin/repo.c\n+++ b/builtin/repo.c\n@@ -27,7 +27,7 @@\n \t\"git repo info --keys [--format=(lines|nul) | -z]\"\n \n #define REPO_STRUCTURE_USAGE \\\n-\t\"git repo structure [--format=(table|lines|nul) | -z]\"\n+\t\"git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\"\n \n static const char *const repo_usage[] = {\n \tREPO_INFO_USAGE,\n@@ -740,6 +740,7 @@ struct count_references_data {\n \tstruct ref_stats *stats;\n \tstruct rev_info *revs;\n \tstruct progress *progress;\n+\tbool add_to_pending;\n };\n \n static int count_references(const struct reference *ref, void *cb_data)\n@@ -766,10 +767,12 @@ static int count_references(const struct reference *ref, void *cb_data)\n \t}\n \n \t/*\n-\t * While iterating through references for counting, also add OIDs in\n+\t * While iterating through references for counting, if we didn't already\n+\t * populate the pending list in setup_revisions, also add OIDs in\n \t * preparation for the path walk.\n \t */\n-\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n+\tif (data->add_to_pending)\n+\t\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n \n \tref_count = get_total_reference_count(stats);\n \tdisplay_progress(data->progress, ref_count);\n@@ -780,11 +783,13 @@ static int count_references(const struct reference *ref, void *cb_data)\n static void structure_count_references(struct ref_stats *stats,\n \t\t\t\t       struct rev_info *revs,\n \t\t\t\t       struct repository *repo,\n-\t\t\t\t       int show_progress)\n+\t\t\t\t       int show_progress,\n+\t\t\t\t       bool add_to_pending)\n {\n \tstruct count_references_data data = {\n \t\t.stats = stats,\n \t\t.revs = revs,\n+\t\t.add_to_pending = add_to_pending\n \t};\n \n \tif (show_progress)\n@@ -935,6 +940,7 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \tstruct repo_structure stats = { 0 };\n \tstruct rev_info revs;\n \tint show_progress = -1;\n+\tbool included_revision_args = false;\n \tstruct option options[] = {\n \t\tOPT_CALLBACK_F(0, \"format\", &format, N_(\"format\"),\n \t\t\t       N_(\"output format\"),\n@@ -947,16 +953,20 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \t\tOPT_END()\n \t};\n \n-\targc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);\n-\tif (argc)\n-\t\tusage(_(\"too many arguments\"));\n-\n-\trepo_init_revisions(repo, &revs, prefix);\n-\n+\targc = parse_options(argc, argv, prefix, options, repo_structure_usage,\n+\t\t\t     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);\n \tif (show_progress < 0)\n \t\tshow_progress = isatty(2);\n \n-\tstructure_count_references(&stats.refs, &revs, repo, show_progress);\n+\trepo_init_revisions(repo, &revs, prefix);\n+\tif (argc > 1) {\n+\t\targc = setup_revisions(argc, argv, &revs, NULL);\n+\t\tincluded_revision_args = true;\n+\t}\n+\tif (argc > 1)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tstructure_count_references(&stats.refs, &revs, repo, show_progress, !included_revision_args);\n \tstructure_count_objects(&stats.objects, &revs, repo, show_progress);\n \n \tswitch (format) {\ndiff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\nindex 02cc2b594a..e35b46a277 100755\n--- a/t/t1901-repo-structure.sh\n+++ b/t/t1901-repo-structure.sh\n@@ -21,58 +21,6 @@ object_type_disk_usage() {\n \tfi\n }\n \n-test_expect_success 'empty repository' '\n-\ttest_when_finished \"rm -rf repo\" &&\n-\tgit init repo &&\n-\t(\n-\t\tcd repo &&\n-\t\tcat >expect <<-\\EOF &&\n-\t\t| Repository structure      | Value  |\n-\t\t| ------------------------- | ------ |\n-\t\t| * References              |        |\n-\t\t|   * Count                 |    0   |\n-\t\t|     * Branches            |    0   |\n-\t\t|     * Tags                |    0   |\n-\t\t|     * Remotes             |    0   |\n-\t\t|     * Others              |    0   |\n-\t\t|                           |        |\n-\t\t| * Reachable objects       |        |\n-\t\t|   * Count                 |    0   |\n-\t\t|     * Commits             |    0   |\n-\t\t|     * Trees               |    0   |\n-\t\t|     * Blobs               |    0   |\n-\t\t|     * Tags                |    0   |\n-\t\t|   * Inflated size         |    0 B |\n-\t\t|     * Commits             |    0 B |\n-\t\t|     * Trees               |    0 B |\n-\t\t|     * Blobs               |    0 B |\n-\t\t|     * Tags                |    0 B |\n-\t\t|   * Disk size             |    0 B |\n-\t\t|     * Commits             |    0 B |\n-\t\t|     * Trees               |    0 B |\n-\t\t|     * Blobs               |    0 B |\n-\t\t|     * Tags                |    0 B |\n-\t\t|                           |        |\n-\t\t| * Largest objects         |        |\n-\t\t|   * Commits               |        |\n-\t\t|     * Maximum size        |    0 B |\n-\t\t|     * Maximum parents     |    0   |\n-\t\t|   * Trees                 |        |\n-\t\t|     * Maximum size        |    0 B |\n-\t\t|     * Maximum entries     |    0   |\n-\t\t|   * Blobs                 |        |\n-\t\t|     * Maximum size        |    0 B |\n-\t\t|   * Tags                  |        |\n-\t\t|     * Maximum size        |    0 B |\n-\t\tEOF\n-\n-\t\tgit repo structure >out 2>err &&\n-\n-\t\ttest_cmp expect out &&\n-\t\ttest_line_count = 0 err\n-\t)\n-'\n-\n test_expect_success SHA1 'repository with references and objects' '\n \ttest_when_finished \"rm -rf repo\" &&\n \tgit init repo &&\n@@ -144,6 +92,165 @@ test_expect_success SHA1 'repository with references and objects' '\n \t)\n '\n \n+test_expect_success SHA1 'repository with branches' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\t\tgit repo structure --format=lines  >actual 2>actual-err &&\n+\t\ttest_line_count = 0 actual-err &&\n+\t\ttest_grep \"objects.commits.inflated.size=231976\" actual &&\n+\t\ttest_grep \"objects.commits.count=1046\" actual &&\n+\t\ttest_grep \"objects.blobs.count=1006\" actual &&\n+\t\ttest_grep \"objects.trees.count=1006\" actual &&\n+\t\ttest_grep \"objects.trees.disk_size=284547\" actual &&\n+\t\ttest_grep \"objects.blobs.disk_size=21022\" actual &&\n+\t\ttest_grep \"objects.tags.disk_size=126\" actual &&\n+\t\ttest_line_count = 0 actual-err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by a positive rev' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\tgit notes add -m foo &&\n+\n+\t\tgit repo structure --format=lines grobble >actual 2>actual-err &&\n+\t\ttest_grep \"objects.commits.count=1025\" actual &&\n+\t\ttest_grep \"objects.commits.disk_size=160455\" actual &&\n+\t\ttest_grep \"objects.commits.inflated.size=227371\" actual &&\n+\t\ttest_grep \"objects.blobs.count=1005\" actual &&\n+\t\ttest_grep \"objects.blobs.disk_size=21003\" actual &&\n+\t\ttest_grep \"objects.blobs.inflated_size=11958\" actual &&\n+\t\ttest_grep \"objects.trees.count=1005\" actual &&\n+\t\ttest_grep \"objects.trees.disk_size=284462\" actual &&\n+\t\ttest_grep \"objects.trees.inflated_size=16578363\" actual &&\n+\t\ttest_grep \"objects.tags.disk_size=0\" actual &&\n+\t\ttest_line_count = 0 actual-err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by both positive and negative revs' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\t\tgit repo structure --format=lines  >actual 2>actual-err &&\n+\t\ttest_line_count = 0 actual-err &&\n+\n+\t\tgit repo structure --format=lines grobble ^master >actual 2>actual-err &&\n+\t\ttest_grep \"objects.commits.count=20\" actual &&\n+\t\ttest_grep \"objects.commits.disk_size=3122\" actual &&\n+\t\ttest_grep \"objects.commits.inflated.size=4411\" actual &&\n+\t\ttest_grep \"objects.blobs.count=1005\" actual &&\n+\t\ttest_grep \"objects.blobs.disk_size=21003\" actual &&\n+\t\ttest_grep \"objects.blobs.inflated_size=11958\" actual &&\n+\t\ttest_grep \"objects.trees.count=1\" actual &&\n+\t\ttest_grep \"objects.trees.disk_size=53\" actual &&\n+\t\ttest_grep \"objects.trees.inflated_size=33063\" actual &&\n+\t\ttest_grep \"objects.tags.disk_size=0\" actual &&\n+\t\ttest_line_count = 0 actual-err\n+\t)\n+'\n+\n+test_expect_success 'filter by object type' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\t\tgit repo structure --format=lines --objects --all --filter=object:type=blob >actual 2>actual-err &&\n+\t\tcp actual /tmp/test-actual-exclude-blob &&\n+\t\ttest_grep \"objects.commits.disk_size=0\" actual &&\n+\t\ttest_grep \"objects.commits.max_size=0\" actual &&\n+\t\ttest_grep \"objects.tags.disk_size=0\" actual &&\n+\t\ttest_grep \"objects.tags.inflated_size=0\" actual &&\n+\t\ttest_grep \"objects.trees.disk_size=0\" actual &&\n+\t\ttest_grep \"objects.trees.inflated_size=0\" actual &&\n+\t\ttest_grep \"objects.blobs.disk_size=21022\" actual &&\n+\t\ttest_grep \"objects.blobs.count=1006\" actual &&\n+\t\ttest_grep \"objects.blobs.disk_size=21022\" actual &&\n+\t\ttest_grep \"objects.blobs.inflated_size=11962\" actual &&\n+\t\ttest_line_count = 0 actual-err\n+\t)\n+'\n+\n+test_expect_success 'filter using by ref^{tree}' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\t\tgit repo structure --format=lines HEAD^{tree}  >actual 2>err &&\n+\t\ttest_grep \"objects.commits.count=0\" actual &&\n+\t\ttest_grep \"objects.trees.count=1\" actual &&\n+\t\ttest_grep \"objects.blobs.count=1005\" actual &&\n+\t\ttest_grep \"objects.tags.count=0\" actual &&\n+\t\ttest_grep \"objects.commits.inflated_size=0\" actual &&\n+\t\ttest_grep \"objects.trees.inflated_size=33063\" actual &&\n+\t\ttest_grep \"objects.blobs.inflated_size=11958\" actual &&\n+\t\ttest_grep \"objects.tags.inflated_size=0\" actual &&\n+\t\ttest_grep \"objects.commits.disk_size=0\" actual &&\n+\t\ttest_grep \"objects.trees.disk_size=53\" actual &&\n+\t\ttest_grep \"objects.blobs.disk_size=21003\" actual &&\n+\t\ttest_grep \"objects.tags.disk_size=0\" actual &&\n+\t\ttest_line_count = 0 err\n+\t)\n+'\n+\n test_expect_success SHA1 'lines and nul format' '\n \ttest_when_finished \"rm -rf repo\" &&\n \tgit init repo &&\n-- \n2.53.0\n\n\n"},{"id":"554846","messageId":"as4a7t-NEQi-4Yqp@pks.im","threadId":"66388","inReplyTo":"20261010150539.930614-4-markchucarroll@fastmail.com","subject":"Re: [PATCH v4 1/1] repo: add filtering options to \"repo structure\"","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-13T11:50:06Z","receivedAt":"2026-10-13T11:50:06Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Sat, Oct 10, 2026 at 11:05:41AM -0400, Mark C. Chu-Carroll wrote:\n[snip]\n> This implementation makes an awkward trade-off involving\n> \"setup_revisions\". In order to accept standard the standard\n> revs parameters, it uses `setup_revisions`, which does a ref\n> walk and populates the pending objects list that will be used\n> by \"repo structure\". But this ref walk doesn't count refs in the\n> way that \"repo structure\" requires, and because \"setup_revisions\"\n> doesn't support a custom callback for its ref-walk, that's not\n> changeable.\n\nIt's a tradeoff indeed, but I think it's a sensible one. I see these as\ncounting two different things, refs and objects, and the revisions only\nfilter objects.\n\n> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc\n> index ed7d80c690..67be7efd23 100644\n> --- a/Documentation/git-repo.adoc\n> +++ b/Documentation/git-repo.adoc\n> @@ -66,6 +66,12 @@ supported:\n>  * Total disk size of reachable objects by type\n>  * Largest reachable objects in the repository by type\n>  +\n> +The set of objects counted can be filtered by specifying a collection\n> +of revisions to select which objects will be counted. These parameters\n> +follow the same syntax as the parameters to similar commands like\n> +`git log`. If no includes are specified, then the include set is all\n> +reachable objects.\n\nNit: I think it would make sense to define \"reachable\" in this case, as\nthere are a bunch of data structures that could in theory make an object\nreachable. How about this instead:\n\n  Defaults to all objects reachable from a reference.\n\n> @@ -141,6 +147,28 @@ using the `nul` format:\n>  git repo info --format=nul layout.bare layout.shallow\n>  ------------\n>  \n> +* Generates information about storage usage in the repository:\n> ++\n> +------------\n> +git repo structure\n> +------------\n> ++\n> +\n> +* Generates information about storage usage in the repository omitting\n> +the branch \"foo\":\n> ++\n> +------------\n> +git repo structure ^foo\n> +------------\n\nWait, wouldn't this result in the empty set of objects because there are\nno positive revisions?\n\n> diff --git a/builtin/repo.c b/builtin/repo.c\n> index 84e012f83f..081940a85c 100644\n> --- a/builtin/repo.c\n> +++ b/builtin/repo.c\n> @@ -766,10 +767,12 @@ static int count_references(const struct reference *ref, void *cb_data)\n>  \t}\n>  \n>  \t/*\n> -\t * While iterating through references for counting, also add OIDs in\n> +\t * While iterating through references for counting, if we didn't already\n> +\t * populate the pending list in setup_revisions, also add OIDs in\n>  \t * preparation for the path walk.\n>  \t */\n> -\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n> +\tif (data->add_to_pending)\n> +\t\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n>  \n>  \tref_count = get_total_reference_count(stats);\n>  \tdisplay_progress(data->progress, ref_count);\n\nRight. An alternative would be to simply never call `add_pending_oid()`\nhere and always let the revision walk handle this by defaulting to\n\"--all\". That'd have the downside of walking references twice, but the\nupside of making each of the steps completely self-contained.\n\nI think ultimately it doesn't matter too much which of these two\napproaches we pick. I'd have picked defaulting to \"--all\" myself, but I\nwon't insist on it.\n\n> @@ -947,16 +953,20 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n>  \t\tOPT_END()\n>  \t};\n>  \n> -\targc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);\n> -\tif (argc)\n> -\t\tusage(_(\"too many arguments\"));\n> -\n> -\trepo_init_revisions(repo, &revs, prefix);\n> -\n> +\targc = parse_options(argc, argv, prefix, options, repo_structure_usage,\n> +\t\t\t     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);\n\nYes. We require `ARGV0` because of `seutp_revisions()` weird API, and\nunknown options should of course be forwarded to it.\n\n>  \tif (show_progress < 0)\n>  \t\tshow_progress = isatty(2);\n>  \n> -\tstructure_count_references(&stats.refs, &revs, repo, show_progress);\n> +\trepo_init_revisions(repo, &revs, prefix);\n> +\tif (argc > 1) {\n> +\t\targc = setup_revisions(argc, argv, &revs, NULL);\n> +\t\tincluded_revision_args = true;\n> +\t}\n> +\tif (argc > 1)\n> +\t\tusage(_(\"too many arguments\"));\n\nTiny nit: this reads a bit odd because we have the same condition twice,\nand the second evaluation really only needs to happen in case we have\ncalled `setup_revisions()`. So I'd have moved the second check right\nafter the call to that function.\n\n> diff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\n> index 02cc2b594a..e35b46a277 100755\n> --- a/t/t1901-repo-structure.sh\n> +++ b/t/t1901-repo-structure.sh\n> @@ -21,58 +21,6 @@ object_type_disk_usage() {\n>  \tfi\n>  }\n>  \n> -test_expect_success 'empty repository' '\n> -\ttest_when_finished \"rm -rf repo\" &&\n> -\tgit init repo &&\n> -\t(\n> -\t\tcd repo &&\n> -\t\tcat >expect <<-\\EOF &&\n> -\t\t| Repository structure      | Value  |\n> -\t\t| ------------------------- | ------ |\n> -\t\t| * References              |        |\n> -\t\t|   * Count                 |    0   |\n> -\t\t|     * Branches            |    0   |\n> -\t\t|     * Tags                |    0   |\n> -\t\t|     * Remotes             |    0   |\n> -\t\t|     * Others              |    0   |\n> -\t\t|                           |        |\n> -\t\t| * Reachable objects       |        |\n> -\t\t|   * Count                 |    0   |\n> -\t\t|     * Commits             |    0   |\n> -\t\t|     * Trees               |    0   |\n> -\t\t|     * Blobs               |    0   |\n> -\t\t|     * Tags                |    0   |\n> -\t\t|   * Inflated size         |    0 B |\n> -\t\t|     * Commits             |    0 B |\n> -\t\t|     * Trees               |    0 B |\n> -\t\t|     * Blobs               |    0 B |\n> -\t\t|     * Tags                |    0 B |\n> -\t\t|   * Disk size             |    0 B |\n> -\t\t|     * Commits             |    0 B |\n> -\t\t|     * Trees               |    0 B |\n> -\t\t|     * Blobs               |    0 B |\n> -\t\t|     * Tags                |    0 B |\n> -\t\t|                           |        |\n> -\t\t| * Largest objects         |        |\n> -\t\t|   * Commits               |        |\n> -\t\t|     * Maximum size        |    0 B |\n> -\t\t|     * Maximum parents     |    0   |\n> -\t\t|   * Trees                 |        |\n> -\t\t|     * Maximum size        |    0 B |\n> -\t\t|     * Maximum entries     |    0   |\n> -\t\t|   * Blobs                 |        |\n> -\t\t|     * Maximum size        |    0 B |\n> -\t\t|   * Tags                  |        |\n> -\t\t|     * Maximum size        |    0 B |\n> -\t\tEOF\n> -\n> -\t\tgit repo structure >out 2>err &&\n> -\n> -\t\ttest_cmp expect out &&\n> -\t\ttest_line_count = 0 err\n> -\t)\n> -'\n\nHuh, why did you drop this test?\n\n> @@ -144,6 +92,165 @@ test_expect_success SHA1 'repository with references and objects' '\n>  \t)\n>  '\n>  \n> +test_expect_success SHA1 'repository with branches' '\n> +\ttest_when_finished \"rm -rf repo\" &&\n> +\tgit init repo &&\n> +\t(\n> +\t\tcd repo &&\n> +\t\ttest_commit_bulk 1005 &&\n> +\t\tgit tag -a foo -m bar &&\n> +\n> +\t\toid=\"$(git rev-parse HEAD)\" &&\n> +\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n> +\t\tgit checkout -b grobble &&\n> +\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n> +\t\tgit checkout master &&\n> +\t\ttest_commit_bulk 20 &&\n> +\t\t# Also creates a commit, tree, and blob.\n> +\t\tgit notes add -m foo &&\n> +\t\tgit repo structure --format=lines  >actual 2>actual-err &&\n\nThere's two spaces here between `--format=lines  >actual`.\n\n> +\t\ttest_line_count = 0 actual-err &&\n\n`test_must_be_empty actual-err`. The same applies to some lines further\ndown.\n\n> +\t\ttest_grep \"objects.commits.inflated.size=231976\" actual &&\n> +\t\ttest_grep \"objects.commits.count=1046\" actual &&\n> +\t\ttest_grep \"objects.blobs.count=1006\" actual &&\n> +\t\ttest_grep \"objects.trees.count=1006\" actual &&\n> +\t\ttest_grep \"objects.trees.disk_size=284547\" actual &&\n> +\t\ttest_grep \"objects.blobs.disk_size=21022\" actual &&\n> +\t\ttest_grep \"objects.tags.disk_size=126\" actual &&\n\nI think this would be a bit easier to parse if you instead:\n\n    cat >expect <<-\\EOF &&\n    objects.commits.inflated.size=231976\n    objects.commits.count=1046\n    objects.blobs.count=1006\n    objects.trees.count=1006\n    objects.trees.disk_size=284547\n    objects.blobs.disk_size=21022\n    objects.tags.disk_size=126\n    EOF\n    test_grep \"^objects\" actual >actual.objects &&\n    test_cmp expect actual.objects\n\nIt's also more efficient because we don't have to invoke grep 8 times.\nBut we'd also have to add the inflated size (which I've omitted out of\nlaziness).\n\n> +test_expect_success SHA1 'filter by both positive and negative revs' '\n> +\ttest_when_finished \"rm -rf repo\" &&\n> +\tgit init repo &&\n> +\t(\n> +\t\tcd repo &&\n> +\t\ttest_commit_bulk 1005 &&\n> +\t\tgit tag -a foo -m bar &&\n> +\n> +\t\toid=\"$(git rev-parse HEAD)\" &&\n> +\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n> +\t\tgit checkout -b grobble &&\n> +\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n> +\t\tgit checkout master &&\n> +\t\ttest_commit_bulk 20 &&\n> +\t\t# Also creates a commit, tree, and blob.\n> +\t\tgit notes add -m foo &&\n> +\t\tgit repo structure --format=lines  >actual 2>actual-err &&\n> +\t\ttest_line_count = 0 actual-err &&\n> +\n> +\t\tgit repo structure --format=lines grobble ^master >actual 2>actual-err &&\n> +\t\ttest_grep \"objects.commits.count=20\" actual &&\n> +\t\ttest_grep \"objects.commits.disk_size=3122\" actual &&\n> +\t\ttest_grep \"objects.commits.inflated.size=4411\" actual &&\n> +\t\ttest_grep \"objects.blobs.count=1005\" actual &&\n> +\t\ttest_grep \"objects.blobs.disk_size=21003\" actual &&\n> +\t\ttest_grep \"objects.blobs.inflated_size=11958\" actual &&\n> +\t\ttest_grep \"objects.trees.count=1\" actual &&\n> +\t\ttest_grep \"objects.trees.disk_size=53\" actual &&\n> +\t\ttest_grep \"objects.trees.inflated_size=33063\" actual &&\n> +\t\ttest_grep \"objects.tags.disk_size=0\" actual &&\n> +\t\ttest_line_count = 0 actual-err\n> +\t)\n> +'\n> +\n> +test_expect_success 'filter by object type' '\n> +\ttest_when_finished \"rm -rf repo\" &&\n> +\tgit init repo &&\n> +\t(\n> +\t\tcd repo &&\n> +\t\ttest_commit_bulk 1005 &&\n> +\t\tgit tag -a foo -m bar &&\n> +\n> +\t\toid=\"$(git rev-parse HEAD)\" &&\n> +\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n> +\t\tgit checkout -b grobble &&\n> +\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n> +\t\tgit checkout master &&\n> +\t\ttest_commit_bulk 20 &&\n> +\t\t# Also creates a commit, tree, and blob.\n> +\t\tgit notes add -m foo &&\n> +\t\tgit repo structure --format=lines --objects --all --filter=object:type=blob >actual 2>actual-err &&\n> +\t\tcp actual /tmp/test-actual-exclude-blob &&\n> +\t\ttest_grep \"objects.commits.disk_size=0\" actual &&\n> +\t\ttest_grep \"objects.commits.max_size=0\" actual &&\n> +\t\ttest_grep \"objects.tags.disk_size=0\" actual &&\n> +\t\ttest_grep \"objects.tags.inflated_size=0\" actual &&\n> +\t\ttest_grep \"objects.trees.disk_size=0\" actual &&\n> +\t\ttest_grep \"objects.trees.inflated_size=0\" actual &&\n> +\t\ttest_grep \"objects.blobs.disk_size=21022\" actual &&\n> +\t\ttest_grep \"objects.blobs.count=1006\" actual &&\n> +\t\ttest_grep \"objects.blobs.disk_size=21022\" actual &&\n> +\t\ttest_grep \"objects.blobs.inflated_size=11962\" actual &&\n> +\t\ttest_line_count = 0 actual-err\n> +\t)\n> +'\n> +\n> +test_expect_success 'filter using by ref^{tree}' '\n\nI think I'd drop this test here as we're now starting to cross the\nborder of exercising the rev-walk machinery. The preceding tests seem\nsufficient as you have tested positive revs, negative revs and options.\n\nOther than that though I think this is on the right track, thanks!\n\nPatrick\n\n"},{"id":"554861","messageId":"DM3RGXVFVT35.1EPI4MJB0RDBB@fastmail.com","threadId":"66388","inReplyTo":"as4a7t-NEQi-4Yqp@pks.im","subject":"Re: [PATCH v4 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-13T13:56:53Z","receivedAt":"2026-10-13T13:56:53Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"On Tue Oct 13, 2026 at 7:50 AM EDT, Patrick Steinhardt wrote:\n> On Sat, Oct 10, 2026 at 11:05:41AM -0400, Mark C. Chu-Carroll wrote:\n> [snip]\n>> This implementation makes an awkward trade-off involving\n>> \"setup_revisions\". In order to accept standard the standard\n>> revs parameters, it uses `setup_revisions`, which does a ref\n>> walk and populates the pending objects list that will be used\n>> by \"repo structure\". But this ref walk doesn't count refs in the\n>> way that \"repo structure\" requires, and because \"setup_revisions\"\n>> doesn't support a custom callback for its ref-walk, that's not\n>> changeable.\n>\n> It's a tradeoff indeed, but I think it's a sensible one. I see these as\n> counting two different things, refs and objects, and the revisions only\n> filter objects.\n\nI guess my wording wasn't clear. The tradeoff here isn't that\nthe revision filters don't affect refs - it's that when we use\nsetup_revisions, we end up doing the ref-walk twice. \n\n>> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc\n>> index ed7d80c690..67be7efd23 100644\n>> --- a/Documentation/git-repo.adoc\n>> +++ b/Documentation/git-repo.adoc\n>> @@ -66,6 +66,12 @@ supported:\n>>  * Total disk size of reachable objects by type\n>>  * Largest reachable objects in the repository by type\n>>  +\n>> +The set of objects counted can be filtered by specifying a collection\n>> +of revisions to select which objects will be counted. These parameters\n>> +follow the same syntax as the parameters to similar commands like\n>> +`git log`. If no includes are specified, then the include set is all\n>> +reachable objects.\n>\n> Nit: I think it would make sense to define \"reachable\" in this case, as\n> there are a bunch of data structures that could in theory make an object\n> reachable. How about this instead:\n>\n>   Defaults to all objects reachable from a reference.\n\nSounds good to me.\n\n>\n>> @@ -141,6 +147,28 @@ using the `nul` format:\n>>  git repo info --format=nul layout.bare layout.shallow\n>>  ------------\n>>  \n>> +* Generates information about storage usage in the repository:\n>> ++\n>> +------------\n>> +git repo structure\n>> +------------\n>> ++\n>> +\n>> +* Generates information about storage usage in the repository omitting\n>> +the branch \"foo\":\n>> ++\n>> +------------\n>> +git repo structure ^foo\n>> +------------\n>\n> Wait, wouldn't this result in the empty set of objects because there are\n> no positive revisions?\n\nYes. One of these days, I'm going to learn to type. That's supposed to\nbe \"git repo structure --all ^foo\". \n\n\n>> diff --git a/builtin/repo.c b/builtin/repo.c\n>> index 84e012f83f..081940a85c 100644\n>> --- a/builtin/repo.c\n>> +++ b/builtin/repo.c\n>> @@ -766,10 +767,12 @@ static int count_references(const struct reference *ref, void *cb_data)\n>>  \t}\n>>  \n>>  \t/*\n>> -\t * While iterating through references for counting, also add OIDs in\n>> +\t * While iterating through references for counting, if we didn't already\n>> +\t * populate the pending list in setup_revisions, also add OIDs in\n>>  \t * preparation for the path walk.\n>>  \t */\n>> -\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n>> +\tif (data->add_to_pending)\n>> +\t\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n>>  \n>>  \tref_count = get_total_reference_count(stats);\n>>  \tdisplay_progress(data->progress, ref_count);\n>\n> Right. An alternative would be to simply never call `add_pending_oid()`\n> here and always let the revision walk handle this by defaulting to\n> \"--all\". That'd have the downside of walking references twice, but the\n> upside of making each of the steps completely self-contained.\n>\n> I think ultimately it doesn't matter too much which of these two\n> approaches we pick. I'd have picked defaulting to \"--all\" myself, but I\n> won't insist on it.\n\nI went back and forth on this a fair bit. Both approaches work,\nand both have their downsides. In the end, I felt like munging argv\nto add the \"--all\" was uglier than this. (Plus, when you do the default\n\"--all\", the command will always fail on an empty repos, because the\n\"all\" logic tries to call \"refs_head_ref\", but there are no head refs in\na newly initialized empty repo.) \n\n>>  \tif (show_progress < 0)\n>>  \t\tshow_progress = isatty(2);\n>>  \n>> -\tstructure_count_references(&stats.refs, &revs, repo, show_progress);\n>> +\trepo_init_revisions(repo, &revs, prefix);\n>> +\tif (argc > 1) {\n>> +\t\targc = setup_revisions(argc, argv, &revs, NULL);\n>> +\t\tincluded_revision_args = true;\n>> +\t}\n>> +\tif (argc > 1)\n>> +\t\tusage(_(\"too many arguments\"));\n>\n> Tiny nit: this reads a bit odd because we have the same condition twice,\n> and the second evaluation really only needs to happen in case we have\n> called `setup_revisions()`. So I'd have moved the second check right\n> after the call to that function.\n\nWill do.\n\n>\n>> diff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\n>> index 02cc2b594a..e35b46a277 100755\n>> --- a/t/t1901-repo-structure.sh\n>> +++ b/t/t1901-repo-structure.sh\n>> @@ -21,58 +21,6 @@ object_type_disk_usage() {\n>>  \tfi\n>>  }\n>>  \n>> -test_expect_success 'empty repository' '\n>> ...\n>> -\t)\n>> -'\n>\n> Huh, why did you drop this test?\n\nWhen I was floundering about whether to use \"--all\" default, I found that the\ncommand will fail on an empty repos. Even without the \"--all\" default, it seems\nstrange that some version of \"git repo structure\" will succeed, and others will\nfail with a confusing error (\"'HEAD': unknown revision or path not in the\nworking tree.\"). It seemed to me that when you consider that running this\ncommand in an empty repo is pointless, I thought it made sense to drop that.\nI'm happy to either add a line to the documentation, or to reinstate the test.\n\n\n>> @@ -144,6 +92,165 @@ test_expect_success SHA1 'repository with references and objects' '\n>> ...\n>> +\t\tgit repo structure --format=lines  >actual 2>actual-err &&\n>\n> There's two spaces here between `--format=lines  >actual`.\n\nGood catch, I have no idea how anyone can see that.\n\n>\n>> +\t\ttest_line_count = 0 actual-err &&\n>\n> `test_must_be_empty actual-err`. The same applies to some lines further\n> down.\n>\n>> +\t\ttest_grep \"objects.commits.inflated.size=231976\" actual &&\n>> +\t\ttest_grep \"objects.commits.count=1046\" actual &&\n>> +\t\ttest_grep \"objects.blobs.count=1006\" actual &&\n>> +\t\ttest_grep \"objects.trees.count=1006\" actual &&\n>> +\t\ttest_grep \"objects.trees.disk_size=284547\" actual &&\n>> +\t\ttest_grep \"objects.blobs.disk_size=21022\" actual &&\n>> +\t\ttest_grep \"objects.tags.disk_size=126\" actual &&\n>\n> I think this would be a bit easier to parse if you instead:\n>\n>     cat >expect <<-\\EOF &&\n>     objects.commits.inflated.size=231976\n>     objects.commits.count=1046\n>     objects.blobs.count=1006\n>     objects.trees.count=1006\n>     objects.trees.disk_size=284547\n>     objects.blobs.disk_size=21022\n>     objects.tags.disk_size=126\n>     EOF\n>     test_grep \"^objects\" actual >actual.objects &&\n>     test_cmp expect actual.objects\n>\n> It's also more efficient because we don't have to invoke grep 8 times.\n> But we'd also have to add the inflated size (which I've omitted out of\n> laziness).\n\nGood idea, will do.\n\n\n\n\n\n\n-- \nMark Craig Chu-Carroll (@MarkChuCarroll at gitlab)\n*** Software Tools/Math Geek - Software Engineer at Gitlab\n*** Work Email: mcarroll@gitlab.com / markchucarroll@fastmail.com\n*** Personal Blog: http://goodmath.org/blog / Personal email: markcc@gmail.com\n\n\n"},{"id":"554863","messageId":"as46v5NEne3SKajZ@pks.im","threadId":"66388","inReplyTo":"DM3RGXVFVT35.1EPI4MJB0RDBB@fastmail.com","subject":"Re: [PATCH v4 1/1] repo: add filtering options to \"repo structure\"","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-13T14:05:51Z","receivedAt":"2026-10-13T14:05:51Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Oct 13, 2026 at 09:56:53AM -0400, Mark C. Chu-Carroll wrote:\n> On Tue Oct 13, 2026 at 7:50 AM EDT, Patrick Steinhardt wrote:\n> > On Sat, Oct 10, 2026 at 11:05:41AM -0400, Mark C. Chu-Carroll wrote:\n> > [snip]\n> >> This implementation makes an awkward trade-off involving\n> >> \"setup_revisions\". In order to accept standard the standard\n> >> revs parameters, it uses `setup_revisions`, which does a ref\n> >> walk and populates the pending objects list that will be used\n> >> by \"repo structure\". But this ref walk doesn't count refs in the\n> >> way that \"repo structure\" requires, and because \"setup_revisions\"\n> >> doesn't support a custom callback for its ref-walk, that's not\n> >> changeable.\n> >\n> > It's a tradeoff indeed, but I think it's a sensible one. I see these as\n> > counting two different things, refs and objects, and the revisions only\n> > filter objects.\n> \n> I guess my wording wasn't clear. The tradeoff here isn't that\n> the revision filters don't affect refs - it's that when we use\n> setup_revisions, we end up doing the ref-walk twice. \n\nAh, right, that makes sense. I really don't think that's much of an\nissue though. We of course shouldn't be unreasonably wasteful, but it's\nnot like `git repo structure` would be on any critical path. Also, in\nmost repositories I would claim that the time it takes to enumerate all\nobjects is going to significantly outweight the time it takes to\nenumerate all refs anyway.\n\n> >> diff --git a/builtin/repo.c b/builtin/repo.c\n> >> index 84e012f83f..081940a85c 100644\n> >> --- a/builtin/repo.c\n> >> +++ b/builtin/repo.c\n> >> @@ -766,10 +767,12 @@ static int count_references(const struct reference *ref, void *cb_data)\n> >>  \t}\n> >>  \n> >>  \t/*\n> >> -\t * While iterating through references for counting, also add OIDs in\n> >> +\t * While iterating through references for counting, if we didn't already\n> >> +\t * populate the pending list in setup_revisions, also add OIDs in\n> >>  \t * preparation for the path walk.\n> >>  \t */\n> >> -\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n> >> +\tif (data->add_to_pending)\n> >> +\t\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n> >>  \n> >>  \tref_count = get_total_reference_count(stats);\n> >>  \tdisplay_progress(data->progress, ref_count);\n> >\n> > Right. An alternative would be to simply never call `add_pending_oid()`\n> > here and always let the revision walk handle this by defaulting to\n> > \"--all\". That'd have the downside of walking references twice, but the\n> > upside of making each of the steps completely self-contained.\n> >\n> > I think ultimately it doesn't matter too much which of these two\n> > approaches we pick. I'd have picked defaulting to \"--all\" myself, but I\n> > won't insist on it.\n> \n> I went back and forth on this a fair bit. Both approaches work,\n> and both have their downsides. In the end, I felt like munging argv\n> to add the \"--all\" was uglier than this. (Plus, when you do the default\n> \"--all\", the command will always fail on an empty repos, because the\n> \"all\" logic tries to call \"refs_head_ref\", but there are no head refs in\n> a newly initialized empty repo.) \n\nYeah, that part is a bit ugly indeed.\n\n> >> diff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\n> >> index 02cc2b594a..e35b46a277 100755\n> >> --- a/t/t1901-repo-structure.sh\n> >> +++ b/t/t1901-repo-structure.sh\n> >> @@ -21,58 +21,6 @@ object_type_disk_usage() {\n> >>  \tfi\n> >>  }\n> >>  \n> >> -test_expect_success 'empty repository' '\n> >> ...\n> >> -\t)\n> >> -'\n> >\n> > Huh, why did you drop this test?\n> \n> When I was floundering about whether to use \"--all\" default, I found that the\n> command will fail on an empty repos. Even without the \"--all\" default, it seems\n> strange that some version of \"git repo structure\" will succeed, and others will\n> fail with a confusing error (\"'HEAD': unknown revision or path not in the\n> working tree.\"). It seemed to me that when you consider that running this\n> command in an empty repo is pointless, I thought it made sense to drop that.\n> I'm happy to either add a line to the documentation, or to reinstate the test.\n\nI think we should ideally know to handle this case alright. It's\nprobably fine to abort in the case where the user explicitly asks for\nrefs that we cannot parse, including in the case of \"--all\".\n\nBut I really think we should succeed in an empty repository, because\nthat's a state that is quite common. So I'd definitely retain that test\nand make sure that at least `git repo structure` without any args works\nalright.\n\nPatrick\n\n"},{"id":"554885","messageId":"20261013172849.1109478-2-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20261010150539.930614-2-markchucarroll@fastmail.com","subject":"[PATCH v5 0/1] repo: add revision filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-13T17:28:49Z","receivedAt":"2026-10-13T17:28:49Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"\"git repo structure\" provides a collection of useful information                                                        \nabout the information stored in a repo. In particular, it's                                                             \nvaluable for diagnosing performance issues caused by large objects                                                      \nstored in a repo.                                                                                                       \n                                                                                                                        \nThe current implementation of \"git repo stucture\" provides summary                                                      \ninformation about everything in the repository - all of the                                                             \nbranches, remotes, tags, stashes, and notes. But sometimes                                                              \nto properly diagnose a problem, it's useful to be able to get                                                           \ninformation about the specific part of the repo that's exhibiting                                                       \na problem.                                                                                                              \n                                                                                                                        \nAdd the option to specify a set of revs. If revs are included,                                                          \nthen the set of objects processed will be limited based on the                                                          \nrev specification; otherwise, all objects will be processed.\n\nDifferences from v4:\n- Make some control flow cleanups.\n- Improve tests.\n\nMark C. Chu-Carroll (1):\n  repo: add filtering options to \"repo structure\"\n\n Documentation/git-repo.adoc |  31 +++++-\n builtin/repo.c              |  32 ++++--\n t/t1901-repo-structure.sh   | 208 +++++++++++++++++++++++++++++++++++-\n 3 files changed, 253 insertions(+), 18 deletions(-)\n\n-- \n2.53.0\n\n\n"},{"id":"554886","messageId":"20261013172849.1109478-4-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20261013172849.1109478-2-markchucarroll@fastmail.com","subject":"[PATCH v5 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-13T17:28:51Z","receivedAt":"2026-10-13T17:28:51Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"The current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to\nfilter this information to get focused data about the specific\npart of the repo that's exhibiting a problem.\n\nUpdate \"git repo structure\" to use rev expressions\nto filter the set of objects to be processed.\n\nThis implementation makes an awkward trade-off involving\n\"setup_revisions\" which results in doing the ref-walk twice when\nrevisions are specified on the command line. In order to accept standard\nthe standard revs parameters, it uses `setup_revisions`, which does a\nref walk and populates the pending objects list that will be used by\n\"repo structure\". But this ref walk doesn't count refs in the way that\n\"repo structure\" requires, and because \"setup_revisions\" doesn't support\na custom callback for its ref-walk, that's not changeable.\n\nSo in the cases where a user specifies revs, \"repo structure\" does\nan initial ref-walk as part of \"setup_revisions\", and then a second\nref-walk in \"count_references\" in repo.c to count by reference type.\nFurther, if the user doesn't specify a revs parameter, \"setup_revisions\"\nis not called, so the \"count_references\" walk needs to add objects\nto the pending list. A parameter is added to \"count_references\"\nto allow it to distinguish the cases where the pending\nlist is already populated from the case where it needs to\npopulate it.\n\nSigned-off-by: Mark C. Chu-Carroll <markchucarroll@fastmail.com>\n---\n Documentation/git-repo.adoc |  31 +++++-\n builtin/repo.c              |  32 ++++--\n t/t1901-repo-structure.sh   | 208 +++++++++++++++++++++++++++++++++++-\n 3 files changed, 253 insertions(+), 18 deletions(-)\n\ndiff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc\nindex ed7d80c690..819202dc4e 100644\n--- a/Documentation/git-repo.adoc\n+++ b/Documentation/git-repo.adoc\n@@ -10,7 +10,7 @@ SYNOPSIS\n [synopsis]\n git repo info [--format=(lines|nul) | -z] [--all | <key>...]\n git repo info --keys [--format=(lines|nul) | -z]\n-git repo structure [--format=(table|lines|nul) | -z]\n+git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\n \n DESCRIPTION\n -----------\n@@ -56,7 +56,7 @@ supported:\n `nul`:::\n \tSimilar to `lines`, but using a _NUL_ character after each value.\n \n-`structure [--format=(table|lines|nul) | -z]`::\n+`structure [--format=(table|lines|nul) | -z] [<revs>...]`::\n \tRetrieve statistics about the current repository structure. The\n \tfollowing kinds of information are reported:\n +\n@@ -66,6 +66,11 @@ supported:\n * Total disk size of reachable objects by type\n * Largest reachable objects in the repository by type\n +\n+The set of objects counted can be filtered by specifying a collection\n+of revisions to select which objects will be counted. These parameters\n+follow the same syntax as the parameters to similar commands like\n+`git log`. Defaults to all objects reachable from a reference.\n++\n The output format can be chosen through the flag `--format`. Three formats are\n supported:\n +\n@@ -141,6 +146,28 @@ using the `nul` format:\n git repo info --format=nul layout.bare layout.shallow\n ------------\n \n+* Generates information about storage usage in the repository:\n++\n+------------\n+git repo structure\n+------------\n++\n+\n+* Generates information about storage usage in the repository omitting\n+the branch \"foo\":\n++\n+------------\n+git repo structure --all ^foo\n+------------\n++\n+* Generates information about repository objects reachable from\n+the references \"x\" and \"y\", but omitting anything that can\n+only be reached on a path including \"xchild\":\n++\n+------------\n+git repo structure x y ^xchild\n+------------\n++\n SEE ALSO\n --------\n linkgit:git-rev-parse[1]\ndiff --git a/builtin/repo.c b/builtin/repo.c\nindex 84e012f83f..f45dea06d5 100644\n--- a/builtin/repo.c\n+++ b/builtin/repo.c\n@@ -27,7 +27,7 @@\n \t\"git repo info --keys [--format=(lines|nul) | -z]\"\n \n #define REPO_STRUCTURE_USAGE \\\n-\t\"git repo structure [--format=(table|lines|nul) | -z]\"\n+\t\"git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\"\n \n static const char *const repo_usage[] = {\n \tREPO_INFO_USAGE,\n@@ -740,6 +740,7 @@ struct count_references_data {\n \tstruct ref_stats *stats;\n \tstruct rev_info *revs;\n \tstruct progress *progress;\n+\tbool add_to_pending;\n };\n \n static int count_references(const struct reference *ref, void *cb_data)\n@@ -766,10 +767,12 @@ static int count_references(const struct reference *ref, void *cb_data)\n \t}\n \n \t/*\n-\t * While iterating through references for counting, also add OIDs in\n+\t * While iterating through references for counting, if we didn't already\n+\t * populate the pending list in setup_revisions, also add OIDs in\n \t * preparation for the path walk.\n \t */\n-\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n+\tif (data->add_to_pending)\n+\t\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n \n \tref_count = get_total_reference_count(stats);\n \tdisplay_progress(data->progress, ref_count);\n@@ -780,11 +783,13 @@ static int count_references(const struct reference *ref, void *cb_data)\n static void structure_count_references(struct ref_stats *stats,\n \t\t\t\t       struct rev_info *revs,\n \t\t\t\t       struct repository *repo,\n-\t\t\t\t       int show_progress)\n+\t\t\t\t       int show_progress,\n+\t\t\t\t       bool add_to_pending)\n {\n \tstruct count_references_data data = {\n \t\t.stats = stats,\n \t\t.revs = revs,\n+\t\t.add_to_pending = add_to_pending\n \t};\n \n \tif (show_progress)\n@@ -935,6 +940,7 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \tstruct repo_structure stats = { 0 };\n \tstruct rev_info revs;\n \tint show_progress = -1;\n+\tbool included_revision_args = false;\n \tstruct option options[] = {\n \t\tOPT_CALLBACK_F(0, \"format\", &format, N_(\"format\"),\n \t\t\t       N_(\"output format\"),\n@@ -947,16 +953,20 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \t\tOPT_END()\n \t};\n \n-\targc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);\n-\tif (argc)\n-\t\tusage(_(\"too many arguments\"));\n-\n-\trepo_init_revisions(repo, &revs, prefix);\n-\n+\targc = parse_options(argc, argv, prefix, options, repo_structure_usage,\n+\t\t\t     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);\n \tif (show_progress < 0)\n \t\tshow_progress = isatty(2);\n \n-\tstructure_count_references(&stats.refs, &revs, repo, show_progress);\n+\trepo_init_revisions(repo, &revs, prefix);\n+\tif (argc > 1) {\n+\t\targc = setup_revisions(argc, argv, &revs, NULL);\n+\t\tincluded_revision_args = true;\n+\t\tif (argc > 1)\n+\t\t\tusage(_(\"too many arguments\"));\n+\t}\n+\n+\tstructure_count_references(&stats.refs, &revs, repo, show_progress, !included_revision_args);\n \tstructure_count_objects(&stats.objects, &revs, repo, show_progress);\n \n \tswitch (format) {\ndiff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\nindex 02cc2b594a..1d25ee14e5 100755\n--- a/t/t1901-repo-structure.sh\n+++ b/t/t1901-repo-structure.sh\n@@ -140,10 +140,208 @@ test_expect_success SHA1 'repository with references and objects' '\n \t\tgit repo structure >out 2>err &&\n \n \t\ttest_cmp expect out &&\n-\t\ttest_line_count = 0 err\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success SHA1 'repository with branches' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\t\tgit repo structure --format=lines >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=1046\n+\t\tobjects.trees.count=1006\n+\t\tobjects.blobs.count=1006\n+\t\tobjects.tags.count=1\n+\t\tobjects.commits.inflated_size=231976\n+\t\tobjects.trees.inflated_size=16578431\n+\t\tobjects.blobs.inflated_size=11962\n+\t\tobjects.tags.inflated_size=132\n+\t\tobjects.commits.disk_size=163722\n+\t\tobjects.trees.disk_size=284547\n+\t\tobjects.blobs.disk_size=21022\n+\t\tobjects.tags.disk_size=126\n+\t\tobjects.commits.max_size=223\n+\t\tobjects.commits.max_size_oid=0dc91eb18580102a3a216c8bfecedeba2b9f9b9a\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=132\n+\t\tobjects.tags.max_size_oid=4dae4f5954f5e6feb3577cfb1b181daa3fd3afd2\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=df6400c01440c329f1011669c4c26cc0c7852887\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by a positive rev' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=1025\n+\t\tobjects.trees.count=1005\n+\t\tobjects.blobs.count=1005\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=227371\n+\t\tobjects.trees.inflated_size=16578363\n+\t\tobjects.blobs.inflated_size=11958\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=160455\n+\t\tobjects.trees.disk_size=284462\n+\t\tobjects.blobs.disk_size=21003\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=223\n+\t\tobjects.commits.max_size_oid=0dc91eb18580102a3a216c8bfecedeba2b9f9b9a\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\tgit repo structure --format=lines grobble >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by both positive and negative revs' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=20\n+\t\tobjects.trees.count=1\n+\t\tobjects.blobs.count=1005\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=4411\n+\t\tobjects.trees.inflated_size=33063\n+\t\tobjects.blobs.inflated_size=11958\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=3122\n+\t\tobjects.trees.disk_size=53\n+\t\tobjects.blobs.disk_size=21003\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=221\n+\t\tobjects.commits.max_size_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\tgit repo structure --format=lines grobble ^master >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success 'filter by object type' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=0\n+\t\tobjects.trees.count=0\n+\t\tobjects.blobs.count=1006\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=0\n+\t\tobjects.trees.inflated_size=0\n+\t\tobjects.blobs.inflated_size=11962\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=0\n+\t\tobjects.trees.disk_size=0\n+\t\tobjects.blobs.disk_size=21022\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=0\n+\t\tobjects.commits.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.trees.max_size=0\n+\t\tobjects.trees.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=0\n+\t\tobjects.commits.max_parents_oid=0000000000000000000000000000000000000000\n+\t\tobjects.trees.max_entries=0\n+\t\tobjects.trees.max_entries_oid=0000000000000000000000000000000000000000\n+\t\tEOF\n+\t\tgit repo structure --format=lines --objects --all --filter=object:type=blob >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n \t)\n '\n \n+\n test_expect_success SHA1 'lines and nul format' '\n \ttest_when_finished \"rm -rf repo\" &&\n \tgit init repo &&\n@@ -186,13 +384,13 @@ test_expect_success SHA1 'lines and nul format' '\n \t\tgit repo structure --format=lines >out 2>err &&\n \n \t\ttest_cmp expect out &&\n-\t\ttest_line_count = 0 err &&\n+\t\ttest_must_be_empty err &&\n \n \t\tgit repo structure --format=nul >out 2>err &&\n \t\ttr \"\\012\\000\" \"=\\012\" <out >actual &&\n \n \t\ttest_cmp expect actual &&\n-\t\ttest_line_count = 0 err &&\n+\t\ttest_must_be_empty err &&\n \n \t\t# \"-z\", as a synonym to \"--format=nul\", participates in the\n \t\t# usual \"last one wins\" rule.\n@@ -200,7 +398,7 @@ test_expect_success SHA1 'lines and nul format' '\n \t\ttr \"\\012\\000\" \"=\\012\" <out >actual &&\n \n \t\ttest_cmp expect actual &&\n-\t\ttest_line_count = 0 err\n+\t\ttest_must_be_empty err\n \t)\n '\n \n@@ -220,7 +418,7 @@ test_expect_success 'progress meter option' '\n \t\tGIT_PROGRESS_DELAY=0 git repo structure --no-progress >out 2>err &&\n \n \t\ttest_file_not_empty out &&\n-\t\ttest_line_count = 0 err\n+\t\ttest_must_be_empty err\n \t)\n '\n \n-- \n2.53.0\n\n\n"},{"id":"555015","messageId":"as9yXVSdEh526Qi9@pks.im","threadId":"66388","inReplyTo":"20261013172849.1109478-4-markchucarroll@fastmail.com","subject":"Re: [PATCH v5 1/1] repo: add filtering options to \"repo structure\"","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-14T12:15:25Z","receivedAt":"2026-10-14T12:15:25Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Oct 13, 2026 at 01:28:51PM -0400, Mark C. Chu-Carroll wrote:\n> index 84e012f83f..f45dea06d5 100644\n> --- a/builtin/repo.c\n> +++ b/builtin/repo.c\n> @@ -947,16 +953,20 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n>  \t\tOPT_END()\n>  \t};\n>  \n> -\targc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);\n> -\tif (argc)\n> -\t\tusage(_(\"too many arguments\"));\n> -\n> -\trepo_init_revisions(repo, &revs, prefix);\n> -\n> +\targc = parse_options(argc, argv, prefix, options, repo_structure_usage,\n> +\t\t\t     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);\n>  \tif (show_progress < 0)\n>  \t\tshow_progress = isatty(2);\n>  \n> -\tstructure_count_references(&stats.refs, &revs, repo, show_progress);\n> +\trepo_init_revisions(repo, &revs, prefix);\n> +\tif (argc > 1) {\n> +\t\targc = setup_revisions(argc, argv, &revs, NULL);\n> +\t\tincluded_revision_args = true;\n> +\t\tif (argc > 1)\n> +\t\t\tusage(_(\"too many arguments\"));\n\nNit: it's not \"too many arguments\", it's unrecognized arguments here as\nthe number of arguments can theoretically be unlimited. Copying patterns\nfrom other builtins:\n\n\targc = setup_revisions(argc, argv, &revs, NULL);\n\tif (argc > 1)\n\t\treturn error(_(\"unrecognized argument: %s\"), argv[1]);\n\n> diff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\n> index 02cc2b594a..1d25ee14e5 100755\n> --- a/t/t1901-repo-structure.sh\n> +++ b/t/t1901-repo-structure.sh\n> @@ -140,10 +140,208 @@ test_expect_success SHA1 'repository with references and objects' '\n[snip]\n> +test_expect_success 'filter by object type' '\n> +\ttest_when_finished \"rm -rf repo\" &&\n> +\tgit init repo &&\n> +\t(\n> +\t\tcd repo &&\n> +\t\ttest_commit_bulk 1005 &&\n> +\t\tgit tag -a foo -m bar &&\n> +\n> +\t\toid=\"$(git rev-parse HEAD)\" &&\n> +\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n> +\t\tgit checkout -b grobble &&\n> +\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n> +\t\tgit checkout master &&\n> +\t\ttest_commit_bulk 20 &&\n> +\t\t# Also creates a commit, tree, and blob.\n> +\t\tgit notes add -m foo &&\n> +\n> +\t\tcat >expect <<-\\EOF &&\n> +\t\tobjects.commits.count=0\n> +\t\tobjects.trees.count=0\n> +\t\tobjects.blobs.count=1006\n> +\t\tobjects.tags.count=0\n> +\t\tobjects.commits.inflated_size=0\n> +\t\tobjects.trees.inflated_size=0\n> +\t\tobjects.blobs.inflated_size=11962\n> +\t\tobjects.tags.inflated_size=0\n> +\t\tobjects.commits.disk_size=0\n> +\t\tobjects.trees.disk_size=0\n> +\t\tobjects.blobs.disk_size=21022\n> +\t\tobjects.tags.disk_size=0\n> +\t\tobjects.commits.max_size=0\n> +\t\tobjects.commits.max_size_oid=0000000000000000000000000000000000000000\n> +\t\tobjects.trees.max_size=0\n> +\t\tobjects.trees.max_size_oid=0000000000000000000000000000000000000000\n> +\t\tobjects.blobs.max_size=13\n> +\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n> +\t\tobjects.tags.max_size=0\n> +\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n> +\t\tobjects.commits.max_parents=0\n> +\t\tobjects.commits.max_parents_oid=0000000000000000000000000000000000000000\n> +\t\tobjects.trees.max_entries=0\n> +\t\tobjects.trees.max_entries_oid=0000000000000000000000000000000000000000\n> +\t\tEOF\n> +\t\tgit repo structure --format=lines --objects --all --filter=object:type=blob >actual 2>err &&\n> +\t\ttest_grep \"^objects\" actual >actual.objects &&\n> +\t\ttest_cmp expect actual.objects &&\n> +\t\ttest_must_be_empty err\n>  \t)\n>  '\n>  \n> +\n>  test_expect_success SHA1 'lines and nul format' '\n>  \ttest_when_finished \"rm -rf repo\" &&\n>  \tgit init repo &&\n\nThere's a trailing newline being added here.\n\n> @@ -186,13 +384,13 @@ test_expect_success SHA1 'lines and nul format' '\n>  \t\tgit repo structure --format=lines >out 2>err &&\n>  \n>  \t\ttest_cmp expect out &&\n> -\t\ttest_line_count = 0 err &&\n> +\t\ttest_must_be_empty err &&\n>  \n>  \t\tgit repo structure --format=nul >out 2>err &&\n>  \t\ttr \"\\012\\000\" \"=\\012\" <out >actual &&\n>  \n>  \t\ttest_cmp expect actual &&\n> -\t\ttest_line_count = 0 err &&\n> +\t\ttest_must_be_empty err &&\n>  \n>  \t\t# \"-z\", as a synonym to \"--format=nul\", participates in the\n>  \t\t# usual \"last one wins\" rule.\n> @@ -200,7 +398,7 @@ test_expect_success SHA1 'lines and nul format' '\n>  \t\ttr \"\\012\\000\" \"=\\012\" <out >actual &&\n>  \n>  \t\ttest_cmp expect actual &&\n> -\t\ttest_line_count = 0 err\n> +\t\ttest_must_be_empty err\n>  \t)\n>  '\n>  \n> @@ -220,7 +418,7 @@ test_expect_success 'progress meter option' '\n>  \t\tGIT_PROGRESS_DELAY=0 git repo structure --no-progress >out 2>err &&\n>  \n>  \t\ttest_file_not_empty out &&\n> -\t\ttest_line_count = 0 err\n> +\t\ttest_must_be_empty err\n>  \t)\n>  '\n\nI'd drop these while-at-it changes. If you want to include them they\nshould be part of a preparatory commit.\n\nBut that's all I've got now, other than those nits I'm happy with this\nversion. Thanks!\n\nPatrick\n\n"},{"id":"555149","messageId":"DM5HQ9U1JWFE.28OMPLQUD2E7P@fastmail.com","threadId":"66388","inReplyTo":"as9yXVSdEh526Qi9@pks.im","subject":"Re: [PATCH v5 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-15T14:44:13Z","receivedAt":"2026-10-15T14:44:13Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"On Wed Oct 14, 2026 at 8:15 AM EDT, Patrick Steinhardt wrote:\n> On Tue, Oct 13, 2026 at 01:28:51PM -0400, Mark C. Chu-Carroll wrote:\n>> index 84e012f83f..f45dea06d5 100644\n>> --- a/builtin/repo.c\n>> +++ b/builtin/repo.c\n>> @@ -947,16 +953,20 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n>>  \t\tOPT_END()\n>  \t};\n>> ...\n>> +\t\tif (argc > 1)\n>> +\t\t\tusage(_(\"too many arguments\"));\n>\n> Nit: it's not \"too many arguments\", it's unrecognized arguments here as\n> the number of arguments can theoretically be unlimited. Copying patterns\n> from other builtins:\n>\n> \targc = setup_revisions(argc, argv, &revs, NULL);\n> \tif (argc > 1)\n> \t\treturn error(_(\"unrecognized argument: %s\"), argv[1]);\n\nRight. I was just keeping the original error message; but since we're now\ntaking a potentially unbounded list of rev args, that message no longer\nmakes sense.\n\n>> diff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\n>> index 02cc2b594a..1d25ee14e5 100755\n>> --- a/t/t1901-repo-structure.sh\n>> +++ b/t/t1901-repo-structure.sh\n>> @@ -140,10 +140,208 @@ test_expect_success SHA1 'repository with references and objects' '\n> [snip]\n> ...\n>> +\t\ttest_must_be_empty err\n>>  \t)\n>>  '\n>>  \n>> +\n>>  test_expect_success SHA1 'lines and nul format' '\n>>  \ttest_when_finished \"rm -rf repo\" &&\n>>  \tgit init repo &&\n>\n> There's a trailing newline being added here.\n\nSorry. I've got some vision issues, and as a result, it's difficult\nfor me to see whitespace - one space or one newline versus two is\npretty much invisible for me. \n\n\n>> @@ -186,13 +384,13 @@ test_expect_success SHA1 'lines and nul format' '\n>\n> I'd drop these while-at-it changes. If you want to include them they\n> should be part of a preparatory commit.\n\nWill drop. My reflex is to change all instances of something after\na comment like this.\n\n  -Mark\n\n\n-- \nMark Craig Chu-Carroll (@MarkChuCarroll at gitlab)\n*** Software Tools/Math Geek - Software Engineer at Gitlab\n*** Work Email: mcarroll@gitlab.com / markchucarroll@fastmail.com\n*** Personal Blog: http://goodmath.org/blog / Personal email: markcc@gmail.com\n\n\n"},{"id":"555150","messageId":"20261015144559.3652143-3-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20261013172849.1109478-2-markchucarroll@fastmail.com","subject":"[PATCH v6 0/1] repo: add revision filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-15T14:46:00Z","receivedAt":"2026-10-15T14:46:00Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"\"git repo structure\" provides a collection of useful information\nabout the information stored in a repo. In particular, it's\nvaluable for diagnosing performance issues caused by large objects\nstored in a repo.\n\nThe current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to get\ninformation about the specific part of the repo that's exhibiting\na problem.\n\nAdd the option to specify a set of revs. If revs are included,\nthen the set of objects processed will be limited based on the\nrev specification; otherwise, all objects will be processed.\n\nDifferences from v5:\n- Address minor review issues.\n\nMark C. Chu-Carroll (1):\n  repo: add filtering options to \"repo structure\"\n\n Documentation/git-repo.adoc |  31 +++++-\n builtin/repo.c              |  32 ++++--\n t/t1901-repo-structure.sh   | 197 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 247 insertions(+), 13 deletions(-)\n\n-- \n2.53.0\n\n\n"},{"id":"555151","messageId":"20261015144559.3652143-5-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20261015144559.3652143-3-markchucarroll@fastmail.com","subject":"[PATCH v6 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-15T14:46:02Z","receivedAt":"2026-10-15T14:46:02Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"The current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to\nfilter this information to get focused data about the specific\npart of the repo that's exhibiting a problem.\n\nUpdate \"git repo structure\" to use rev expressions\nto filter the set of objects to be processed.\n\nThis implementation makes an awkward trade-off involving\n\"setup_revisions\" which results in doing the ref-walk twice when\nrevisions are specified on the command line. In order to accept standard\nthe standard revs parameters, it uses `setup_revisions`, which does a\nref walk and populates the pending objects list that will be used by\n\"repo structure\". But this ref walk doesn't count refs in the way that\n\"repo structure\" requires, and because \"setup_revisions\" doesn't support\na custom callback for its ref-walk, that's not changeable.\n\nSo in the cases where a user specifies revs, \"repo structure\" does\nan initial ref-walk as part of \"setup_revisions\", and then a second\nref-walk in \"count_references\" in repo.c to count by reference type.\nFurther, if the user doesn't specify a revs parameter, \"setup_revisions\"\nis not called, so the \"count_references\" walk needs to add objects\nto the pending list. A parameter is added to \"count_references\"\nto allow it to distinguish the cases where the pending\nlist is already populated from the case where it needs to\npopulate it.\n\nSigned-off-by: Mark C. Chu-Carroll <markchucarroll@fastmail.com>\n---\n Documentation/git-repo.adoc |  31 +++++-\n builtin/repo.c              |  32 ++++--\n t/t1901-repo-structure.sh   | 197 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 247 insertions(+), 13 deletions(-)\n\ndiff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc\nindex ed7d80c690..819202dc4e 100644\n--- a/Documentation/git-repo.adoc\n+++ b/Documentation/git-repo.adoc\n@@ -10,7 +10,7 @@ SYNOPSIS\n [synopsis]\n git repo info [--format=(lines|nul) | -z] [--all | <key>...]\n git repo info --keys [--format=(lines|nul) | -z]\n-git repo structure [--format=(table|lines|nul) | -z]\n+git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\n \n DESCRIPTION\n -----------\n@@ -56,7 +56,7 @@ supported:\n `nul`:::\n \tSimilar to `lines`, but using a _NUL_ character after each value.\n \n-`structure [--format=(table|lines|nul) | -z]`::\n+`structure [--format=(table|lines|nul) | -z] [<revs>...]`::\n \tRetrieve statistics about the current repository structure. The\n \tfollowing kinds of information are reported:\n +\n@@ -66,6 +66,11 @@ supported:\n * Total disk size of reachable objects by type\n * Largest reachable objects in the repository by type\n +\n+The set of objects counted can be filtered by specifying a collection\n+of revisions to select which objects will be counted. These parameters\n+follow the same syntax as the parameters to similar commands like\n+`git log`. Defaults to all objects reachable from a reference.\n++\n The output format can be chosen through the flag `--format`. Three formats are\n supported:\n +\n@@ -141,6 +146,28 @@ using the `nul` format:\n git repo info --format=nul layout.bare layout.shallow\n ------------\n \n+* Generates information about storage usage in the repository:\n++\n+------------\n+git repo structure\n+------------\n++\n+\n+* Generates information about storage usage in the repository omitting\n+the branch \"foo\":\n++\n+------------\n+git repo structure --all ^foo\n+------------\n++\n+* Generates information about repository objects reachable from\n+the references \"x\" and \"y\", but omitting anything that can\n+only be reached on a path including \"xchild\":\n++\n+------------\n+git repo structure x y ^xchild\n+------------\n++\n SEE ALSO\n --------\n linkgit:git-rev-parse[1]\ndiff --git a/builtin/repo.c b/builtin/repo.c\nindex 84e012f83f..78638c2dcd 100644\n--- a/builtin/repo.c\n+++ b/builtin/repo.c\n@@ -27,7 +27,7 @@\n \t\"git repo info --keys [--format=(lines|nul) | -z]\"\n \n #define REPO_STRUCTURE_USAGE \\\n-\t\"git repo structure [--format=(table|lines|nul) | -z]\"\n+\t\"git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\"\n \n static const char *const repo_usage[] = {\n \tREPO_INFO_USAGE,\n@@ -740,6 +740,7 @@ struct count_references_data {\n \tstruct ref_stats *stats;\n \tstruct rev_info *revs;\n \tstruct progress *progress;\n+\tbool add_to_pending;\n };\n \n static int count_references(const struct reference *ref, void *cb_data)\n@@ -766,10 +767,12 @@ static int count_references(const struct reference *ref, void *cb_data)\n \t}\n \n \t/*\n-\t * While iterating through references for counting, also add OIDs in\n+\t * While iterating through references for counting, if we didn't already\n+\t * populate the pending list in setup_revisions, also add OIDs in\n \t * preparation for the path walk.\n \t */\n-\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n+\tif (data->add_to_pending)\n+\t\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n \n \tref_count = get_total_reference_count(stats);\n \tdisplay_progress(data->progress, ref_count);\n@@ -780,11 +783,13 @@ static int count_references(const struct reference *ref, void *cb_data)\n static void structure_count_references(struct ref_stats *stats,\n \t\t\t\t       struct rev_info *revs,\n \t\t\t\t       struct repository *repo,\n-\t\t\t\t       int show_progress)\n+\t\t\t\t       int show_progress,\n+\t\t\t\t       bool add_to_pending)\n {\n \tstruct count_references_data data = {\n \t\t.stats = stats,\n \t\t.revs = revs,\n+\t\t.add_to_pending = add_to_pending\n \t};\n \n \tif (show_progress)\n@@ -935,6 +940,7 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \tstruct repo_structure stats = { 0 };\n \tstruct rev_info revs;\n \tint show_progress = -1;\n+\tbool included_revision_args = false;\n \tstruct option options[] = {\n \t\tOPT_CALLBACK_F(0, \"format\", &format, N_(\"format\"),\n \t\t\t       N_(\"output format\"),\n@@ -947,16 +953,20 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \t\tOPT_END()\n \t};\n \n-\targc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);\n-\tif (argc)\n-\t\tusage(_(\"too many arguments\"));\n-\n-\trepo_init_revisions(repo, &revs, prefix);\n-\n+\targc = parse_options(argc, argv, prefix, options, repo_structure_usage,\n+\t\t\t     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);\n \tif (show_progress < 0)\n \t\tshow_progress = isatty(2);\n \n-\tstructure_count_references(&stats.refs, &revs, repo, show_progress);\n+\trepo_init_revisions(repo, &revs, prefix);\n+\tif (argc > 1) {\n+\t\targc = setup_revisions(argc, argv, &revs, NULL);\n+\t\tincluded_revision_args = true;\n+\t\tif (argc > 1)\n+\t\t\treturn error(_(\"unrecognized argument: %s\"), argv[1]);\n+\t}\n+\n+\tstructure_count_references(&stats.refs, &revs, repo, show_progress, !included_revision_args);\n \tstructure_count_objects(&stats.objects, &revs, repo, show_progress);\n \n \tswitch (format) {\ndiff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\nindex 02cc2b594a..4e5e4a0a7a 100755\n--- a/t/t1901-repo-structure.sh\n+++ b/t/t1901-repo-structure.sh\n@@ -144,6 +144,203 @@ test_expect_success SHA1 'repository with references and objects' '\n \t)\n '\n \n+test_expect_success SHA1 'repository with branches' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\t\tgit repo structure --format=lines >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=1046\n+\t\tobjects.trees.count=1006\n+\t\tobjects.blobs.count=1006\n+\t\tobjects.tags.count=1\n+\t\tobjects.commits.inflated_size=231976\n+\t\tobjects.trees.inflated_size=16578431\n+\t\tobjects.blobs.inflated_size=11962\n+\t\tobjects.tags.inflated_size=132\n+\t\tobjects.commits.disk_size=163722\n+\t\tobjects.trees.disk_size=284547\n+\t\tobjects.blobs.disk_size=21022\n+\t\tobjects.tags.disk_size=126\n+\t\tobjects.commits.max_size=223\n+\t\tobjects.commits.max_size_oid=0dc91eb18580102a3a216c8bfecedeba2b9f9b9a\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=132\n+\t\tobjects.tags.max_size_oid=4dae4f5954f5e6feb3577cfb1b181daa3fd3afd2\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=df6400c01440c329f1011669c4c26cc0c7852887\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by a positive rev' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=1025\n+\t\tobjects.trees.count=1005\n+\t\tobjects.blobs.count=1005\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=227371\n+\t\tobjects.trees.inflated_size=16578363\n+\t\tobjects.blobs.inflated_size=11958\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=160455\n+\t\tobjects.trees.disk_size=284462\n+\t\tobjects.blobs.disk_size=21003\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=223\n+\t\tobjects.commits.max_size_oid=0dc91eb18580102a3a216c8bfecedeba2b9f9b9a\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\tgit repo structure --format=lines grobble >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by both positive and negative revs' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=20\n+\t\tobjects.trees.count=1\n+\t\tobjects.blobs.count=1005\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=4411\n+\t\tobjects.trees.inflated_size=33063\n+\t\tobjects.blobs.inflated_size=11958\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=3122\n+\t\tobjects.trees.disk_size=53\n+\t\tobjects.blobs.disk_size=21003\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=221\n+\t\tobjects.commits.max_size_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\tgit repo structure --format=lines grobble ^master >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success 'filter by object type' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=0\n+\t\tobjects.trees.count=0\n+\t\tobjects.blobs.count=1006\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=0\n+\t\tobjects.trees.inflated_size=0\n+\t\tobjects.blobs.inflated_size=11962\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=0\n+\t\tobjects.trees.disk_size=0\n+\t\tobjects.blobs.disk_size=21022\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=0\n+\t\tobjects.commits.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.trees.max_size=0\n+\t\tobjects.trees.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=0\n+\t\tobjects.commits.max_parents_oid=0000000000000000000000000000000000000000\n+\t\tobjects.trees.max_entries=0\n+\t\tobjects.trees.max_entries_oid=0000000000000000000000000000000000000000\n+\t\tEOF\n+\t\tgit repo structure --format=lines --objects --all --filter=object:type=blob >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n test_expect_success SHA1 'lines and nul format' '\n \ttest_when_finished \"rm -rf repo\" &&\n \tgit init repo &&\n-- \n2.53.0\n\n\n"},{"id":"555153","messageId":"85a904ec-a478-4d47-b4ab-37817c5f67c7@app.fastmail.com","threadId":"66388","inReplyTo":"20261015144559.3652143-5-markchucarroll@fastmail.com","subject":"Re: [PATCH v6 1/1] repo: add filtering options to \"repo structure\"","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-10-15T15:12:47Z","receivedAt":"2026-10-15T15:12:47Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Thu, Oct 15, 2026, at 16:46, Mark C. Chu-Carroll wrote:\n>[snip]\n> revisions are specified on the command line. In order to accept standard\n> the standard revs parameters, it uses `setup_revisions`, which does a\n\ns/standard the standard/the standard/ ?\n\n> ref walk and populates the pending objects list that will be used by\n> \"repo structure\". But this ref walk doesn't count refs in the way that\n> \"repo structure\" requires, and because \"setup_revisions\" doesn't support\n> a custom callback for its ref-walk, that's not changeable.\n>[snip]\n\n"},{"id":"555159","messageId":"atD2uH1pPJxH7pgR@pks.im","threadId":"66388","inReplyTo":"DM5HQ9U1JWFE.28OMPLQUD2E7P@fastmail.com","subject":"Re: [PATCH v5 1/1] repo: add filtering options to \"repo structure\"","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-15T15:52:24Z","receivedAt":"2026-10-15T15:52:24Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Oct 15, 2026 at 10:44:13AM -0400, Mark C. Chu-Carroll wrote:\n> On Wed Oct 14, 2026 at 8:15 AM EDT, Patrick Steinhardt wrote:\n> > On Tue, Oct 13, 2026 at 01:28:51PM -0400, Mark C. Chu-Carroll wrote:\n> >> diff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\n> >> index 02cc2b594a..1d25ee14e5 100755\n> >> --- a/t/t1901-repo-structure.sh\n> >> +++ b/t/t1901-repo-structure.sh\n> >> @@ -140,10 +140,208 @@ test_expect_success SHA1 'repository with references and objects' '\n> >> @@ -186,13 +384,13 @@ test_expect_success SHA1 'lines and nul format' '\n> >\n> > I'd drop these while-at-it changes. If you want to include them they\n> > should be part of a preparatory commit.\n> \n> Will drop. My reflex is to change all instances of something after\n> a comment like this.\n\nI think that's not the worst reflex to have, but in that case those\nshould go into a preparatory commit.\n\nPatrick\n\n"},{"id":"555161","messageId":"DM5KKQ5ARTE6.12QH6KBE69HUY@fastmail.com","threadId":"66388","inReplyTo":"85a904ec-a478-4d47-b4ab-37817c5f67c7@app.fastmail.com","subject":"Re: [PATCH v6 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-15T16:58:01Z","receivedAt":"2026-10-15T16:58:01Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"On Thu Oct 15, 2026 at 11:12 AM EDT, Kristoffer Haugsbakk wrote:\n> On Thu, Oct 15, 2026, at 16:46, Mark C. Chu-Carroll wrote:\n>>[snip]\n>> revisions are specified on the command line. In order to accept standard\n>> the standard revs parameters, it uses `setup_revisions`, which does a\n>\n> s/standard the standard/the standard/ ?\n\nArgh. \n\n\n\n-- \nMark Craig Chu-Carroll (@MarkChuCarroll at gitlab)\n*** Software Tools/Math Geek - Software Engineer at Gitlab\n*** Work Email: mcarroll@gitlab.com / markchucarroll@fastmail.com\n*** Personal Blog: http://goodmath.org/blog / Personal email: markcc@gmail.com\n\n\n"},{"id":"555164","messageId":"20261015170342.39967-1-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20261015144559.3652143-3-markchucarroll@fastmail.com","subject":"[PATCH v7 0/1] repo: add revision filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-15T17:03:41Z","receivedAt":"2026-10-15T17:03:41Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"\"git repo structure\" provides a collection of useful information\nabout the information stored in a repo. In particular, it's\nvaluable for diagnosing performance issues caused by large objects\nstored in a repo.\n\nThe current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to get\ninformation about the specific part of the repo that's exhibiting\na problem.\n\nAdd the option to specify a set of revs. If revs are included,\nthen the set of objects processed will be limited based on the\nrev specification; otherwise, all objects will be processed.\n\nDifferences from v6:\n- Fix word duplication in commit message.\n\n\nMark C. Chu-Carroll (1):\n  repo: add filtering options to \"repo structure\"\n\n Documentation/git-repo.adoc |  31 +++++-\n builtin/repo.c              |  32 ++++--\n t/t1901-repo-structure.sh   | 197 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 247 insertions(+), 13 deletions(-)\n\n-- \n2.53.0\n\n\n"},{"id":"555165","messageId":"20261015170342.39967-2-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20261015170342.39967-1-markchucarroll@fastmail.com","subject":"[PATCH v7 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-15T17:03:42Z","receivedAt":"2026-10-15T17:03:42Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"The current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to\nfilter this information to get focused data about the specific\npart of the repo that's exhibiting a problem.\n\nUpdate \"git repo structure\" to use rev expressions\nto filter the set of objects to be processed.\n\nThis implementation makes an awkward trade-off involving\n\"setup_revisions\" which results in doing the ref-walk twice when\nrevisions are specified on the command line. In order to accept\nthe standard revs parameters, it uses `setup_revisions`, which does a\nref walk and populates the pending objects list that will be used by\n\"repo structure\". But this ref walk doesn't count refs in the way that\n\"repo structure\" requires, and because \"setup_revisions\" doesn't support\na custom callback for its ref-walk, that's not changeable.\n\nSo in the cases where a user specifies revs, \"repo structure\" does\nan initial ref-walk as part of \"setup_revisions\", and then a second\nref-walk in \"count_references\" in repo.c to count by reference type.\nFurther, if the user doesn't specify a revs parameter, \"setup_revisions\"\nis not called, so the \"count_references\" walk needs to add objects\nto the pending list. A parameter is added to \"count_references\"\nto allow it to distinguish the cases where the pending\nlist is already populated from the case where it needs to\npopulate it.\n\nSigned-off-by: Mark C. Chu-Carroll <markchucarroll@fastmail.com>\n---\n Documentation/git-repo.adoc |  31 +++++-\n builtin/repo.c              |  32 ++++--\n t/t1901-repo-structure.sh   | 197 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 247 insertions(+), 13 deletions(-)\n\ndiff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc\nindex ed7d80c690..819202dc4e 100644\n--- a/Documentation/git-repo.adoc\n+++ b/Documentation/git-repo.adoc\n@@ -10,7 +10,7 @@ SYNOPSIS\n [synopsis]\n git repo info [--format=(lines|nul) | -z] [--all | <key>...]\n git repo info --keys [--format=(lines|nul) | -z]\n-git repo structure [--format=(table|lines|nul) | -z]\n+git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\n \n DESCRIPTION\n -----------\n@@ -56,7 +56,7 @@ supported:\n `nul`:::\n \tSimilar to `lines`, but using a _NUL_ character after each value.\n \n-`structure [--format=(table|lines|nul) | -z]`::\n+`structure [--format=(table|lines|nul) | -z] [<revs>...]`::\n \tRetrieve statistics about the current repository structure. The\n \tfollowing kinds of information are reported:\n +\n@@ -66,6 +66,11 @@ supported:\n * Total disk size of reachable objects by type\n * Largest reachable objects in the repository by type\n +\n+The set of objects counted can be filtered by specifying a collection\n+of revisions to select which objects will be counted. These parameters\n+follow the same syntax as the parameters to similar commands like\n+`git log`. Defaults to all objects reachable from a reference.\n++\n The output format can be chosen through the flag `--format`. Three formats are\n supported:\n +\n@@ -141,6 +146,28 @@ using the `nul` format:\n git repo info --format=nul layout.bare layout.shallow\n ------------\n \n+* Generates information about storage usage in the repository:\n++\n+------------\n+git repo structure\n+------------\n++\n+\n+* Generates information about storage usage in the repository omitting\n+the branch \"foo\":\n++\n+------------\n+git repo structure --all ^foo\n+------------\n++\n+* Generates information about repository objects reachable from\n+the references \"x\" and \"y\", but omitting anything that can\n+only be reached on a path including \"xchild\":\n++\n+------------\n+git repo structure x y ^xchild\n+------------\n++\n SEE ALSO\n --------\n linkgit:git-rev-parse[1]\ndiff --git a/builtin/repo.c b/builtin/repo.c\nindex 84e012f83f..78638c2dcd 100644\n--- a/builtin/repo.c\n+++ b/builtin/repo.c\n@@ -27,7 +27,7 @@\n \t\"git repo info --keys [--format=(lines|nul) | -z]\"\n \n #define REPO_STRUCTURE_USAGE \\\n-\t\"git repo structure [--format=(table|lines|nul) | -z]\"\n+\t\"git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\"\n \n static const char *const repo_usage[] = {\n \tREPO_INFO_USAGE,\n@@ -740,6 +740,7 @@ struct count_references_data {\n \tstruct ref_stats *stats;\n \tstruct rev_info *revs;\n \tstruct progress *progress;\n+\tbool add_to_pending;\n };\n \n static int count_references(const struct reference *ref, void *cb_data)\n@@ -766,10 +767,12 @@ static int count_references(const struct reference *ref, void *cb_data)\n \t}\n \n \t/*\n-\t * While iterating through references for counting, also add OIDs in\n+\t * While iterating through references for counting, if we didn't already\n+\t * populate the pending list in setup_revisions, also add OIDs in\n \t * preparation for the path walk.\n \t */\n-\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n+\tif (data->add_to_pending)\n+\t\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n \n \tref_count = get_total_reference_count(stats);\n \tdisplay_progress(data->progress, ref_count);\n@@ -780,11 +783,13 @@ static int count_references(const struct reference *ref, void *cb_data)\n static void structure_count_references(struct ref_stats *stats,\n \t\t\t\t       struct rev_info *revs,\n \t\t\t\t       struct repository *repo,\n-\t\t\t\t       int show_progress)\n+\t\t\t\t       int show_progress,\n+\t\t\t\t       bool add_to_pending)\n {\n \tstruct count_references_data data = {\n \t\t.stats = stats,\n \t\t.revs = revs,\n+\t\t.add_to_pending = add_to_pending\n \t};\n \n \tif (show_progress)\n@@ -935,6 +940,7 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \tstruct repo_structure stats = { 0 };\n \tstruct rev_info revs;\n \tint show_progress = -1;\n+\tbool included_revision_args = false;\n \tstruct option options[] = {\n \t\tOPT_CALLBACK_F(0, \"format\", &format, N_(\"format\"),\n \t\t\t       N_(\"output format\"),\n@@ -947,16 +953,20 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \t\tOPT_END()\n \t};\n \n-\targc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);\n-\tif (argc)\n-\t\tusage(_(\"too many arguments\"));\n-\n-\trepo_init_revisions(repo, &revs, prefix);\n-\n+\targc = parse_options(argc, argv, prefix, options, repo_structure_usage,\n+\t\t\t     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);\n \tif (show_progress < 0)\n \t\tshow_progress = isatty(2);\n \n-\tstructure_count_references(&stats.refs, &revs, repo, show_progress);\n+\trepo_init_revisions(repo, &revs, prefix);\n+\tif (argc > 1) {\n+\t\targc = setup_revisions(argc, argv, &revs, NULL);\n+\t\tincluded_revision_args = true;\n+\t\tif (argc > 1)\n+\t\t\treturn error(_(\"unrecognized argument: %s\"), argv[1]);\n+\t}\n+\n+\tstructure_count_references(&stats.refs, &revs, repo, show_progress, !included_revision_args);\n \tstructure_count_objects(&stats.objects, &revs, repo, show_progress);\n \n \tswitch (format) {\ndiff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\nindex 02cc2b594a..4e5e4a0a7a 100755\n--- a/t/t1901-repo-structure.sh\n+++ b/t/t1901-repo-structure.sh\n@@ -144,6 +144,203 @@ test_expect_success SHA1 'repository with references and objects' '\n \t)\n '\n \n+test_expect_success SHA1 'repository with branches' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\t\tgit repo structure --format=lines >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=1046\n+\t\tobjects.trees.count=1006\n+\t\tobjects.blobs.count=1006\n+\t\tobjects.tags.count=1\n+\t\tobjects.commits.inflated_size=231976\n+\t\tobjects.trees.inflated_size=16578431\n+\t\tobjects.blobs.inflated_size=11962\n+\t\tobjects.tags.inflated_size=132\n+\t\tobjects.commits.disk_size=163722\n+\t\tobjects.trees.disk_size=284547\n+\t\tobjects.blobs.disk_size=21022\n+\t\tobjects.tags.disk_size=126\n+\t\tobjects.commits.max_size=223\n+\t\tobjects.commits.max_size_oid=0dc91eb18580102a3a216c8bfecedeba2b9f9b9a\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=132\n+\t\tobjects.tags.max_size_oid=4dae4f5954f5e6feb3577cfb1b181daa3fd3afd2\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=df6400c01440c329f1011669c4c26cc0c7852887\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by a positive rev' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=1025\n+\t\tobjects.trees.count=1005\n+\t\tobjects.blobs.count=1005\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=227371\n+\t\tobjects.trees.inflated_size=16578363\n+\t\tobjects.blobs.inflated_size=11958\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=160455\n+\t\tobjects.trees.disk_size=284462\n+\t\tobjects.blobs.disk_size=21003\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=223\n+\t\tobjects.commits.max_size_oid=0dc91eb18580102a3a216c8bfecedeba2b9f9b9a\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\tgit repo structure --format=lines grobble >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by both positive and negative revs' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=20\n+\t\tobjects.trees.count=1\n+\t\tobjects.blobs.count=1005\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=4411\n+\t\tobjects.trees.inflated_size=33063\n+\t\tobjects.blobs.inflated_size=11958\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=3122\n+\t\tobjects.trees.disk_size=53\n+\t\tobjects.blobs.disk_size=21003\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=221\n+\t\tobjects.commits.max_size_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\tgit repo structure --format=lines grobble ^master >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success 'filter by object type' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=0\n+\t\tobjects.trees.count=0\n+\t\tobjects.blobs.count=1006\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=0\n+\t\tobjects.trees.inflated_size=0\n+\t\tobjects.blobs.inflated_size=11962\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=0\n+\t\tobjects.trees.disk_size=0\n+\t\tobjects.blobs.disk_size=21022\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=0\n+\t\tobjects.commits.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.trees.max_size=0\n+\t\tobjects.trees.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=0\n+\t\tobjects.commits.max_parents_oid=0000000000000000000000000000000000000000\n+\t\tobjects.trees.max_entries=0\n+\t\tobjects.trees.max_entries_oid=0000000000000000000000000000000000000000\n+\t\tEOF\n+\t\tgit repo structure --format=lines --objects --all --filter=object:type=blob >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n test_expect_success SHA1 'lines and nul format' '\n \ttest_when_finished \"rm -rf repo\" &&\n \tgit init repo &&\n-- \n2.53.0\n\n\n"},{"id":"555166","messageId":"20261015170518.48395-2-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20261015144559.3652143-3-markchucarroll@fastmail.com","subject":"[PATCH v7 0/1] repo: add revision filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-15T17:05:18Z","receivedAt":"2026-10-15T17:05:18Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"\"git repo structure\" provides a collection of useful information\nabout the information stored in a repo. In particular, it's\nvaluable for diagnosing performance issues caused by large objects\nstored in a repo.\n\nThe current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to get\ninformation about the specific part of the repo that's exhibiting\na problem.\n\nAdd the option to specify a set of revs. If revs are included,\nthen the set of objects processed will be limited based on the\nrev specification; otherwise, all objects will be processed.\n\nDifferences from v6:\n- Fix word duplication in commit message.\n\n\nMark C. Chu-Carroll (1):\n  repo: add filtering options to \"repo structure\"\n\n Documentation/git-repo.adoc |  31 +++++-\n builtin/repo.c              |  32 ++++--\n t/t1901-repo-structure.sh   | 197 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 247 insertions(+), 13 deletions(-)\n\n-- \n2.53.0\n\n\n"},{"id":"555167","messageId":"20261015170518.48395-4-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20261015170518.48395-2-markchucarroll@fastmail.com","subject":"[PATCH v7 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-15T17:05:20Z","receivedAt":"2026-10-15T17:05:20Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"The current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to\nfilter this information to get focused data about the specific\npart of the repo that's exhibiting a problem.\n\nUpdate \"git repo structure\" to use rev expressions\nto filter the set of objects to be processed.\n\nThis implementation makes an awkward trade-off involving\n\"setup_revisions\" which results in doing the ref-walk twice when\nrevisions are specified on the command line. In order to accept\nthe standard revs parameters, it uses `setup_revisions`, which does a\nref walk and populates the pending objects list that will be used by\n\"repo structure\". But this ref walk doesn't count refs in the way that\n\"repo structure\" requires, and because \"setup_revisions\" doesn't support\na custom callback for its ref-walk, that's not changeable.\n\nSo in the cases where a user specifies revs, \"repo structure\" does\nan initial ref-walk as part of \"setup_revisions\", and then a second\nref-walk in \"count_references\" in repo.c to count by reference type.\nFurther, if the user doesn't specify a revs parameter, \"setup_revisions\"\nis not called, so the \"count_references\" walk needs to add objects\nto the pending list. A parameter is added to \"count_references\"\nto allow it to distinguish the cases where the pending\nlist is already populated from the case where it needs to\npopulate it.\n\nSigned-off-by: Mark C. Chu-Carroll <markchucarroll@fastmail.com>\n---\n Documentation/git-repo.adoc |  31 +++++-\n builtin/repo.c              |  32 ++++--\n t/t1901-repo-structure.sh   | 197 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 247 insertions(+), 13 deletions(-)\n\ndiff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc\nindex ed7d80c690..819202dc4e 100644\n--- a/Documentation/git-repo.adoc\n+++ b/Documentation/git-repo.adoc\n@@ -10,7 +10,7 @@ SYNOPSIS\n [synopsis]\n git repo info [--format=(lines|nul) | -z] [--all | <key>...]\n git repo info --keys [--format=(lines|nul) | -z]\n-git repo structure [--format=(table|lines|nul) | -z]\n+git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\n \n DESCRIPTION\n -----------\n@@ -56,7 +56,7 @@ supported:\n `nul`:::\n \tSimilar to `lines`, but using a _NUL_ character after each value.\n \n-`structure [--format=(table|lines|nul) | -z]`::\n+`structure [--format=(table|lines|nul) | -z] [<revs>...]`::\n \tRetrieve statistics about the current repository structure. The\n \tfollowing kinds of information are reported:\n +\n@@ -66,6 +66,11 @@ supported:\n * Total disk size of reachable objects by type\n * Largest reachable objects in the repository by type\n +\n+The set of objects counted can be filtered by specifying a collection\n+of revisions to select which objects will be counted. These parameters\n+follow the same syntax as the parameters to similar commands like\n+`git log`. Defaults to all objects reachable from a reference.\n++\n The output format can be chosen through the flag `--format`. Three formats are\n supported:\n +\n@@ -141,6 +146,28 @@ using the `nul` format:\n git repo info --format=nul layout.bare layout.shallow\n ------------\n \n+* Generates information about storage usage in the repository:\n++\n+------------\n+git repo structure\n+------------\n++\n+\n+* Generates information about storage usage in the repository omitting\n+the branch \"foo\":\n++\n+------------\n+git repo structure --all ^foo\n+------------\n++\n+* Generates information about repository objects reachable from\n+the references \"x\" and \"y\", but omitting anything that can\n+only be reached on a path including \"xchild\":\n++\n+------------\n+git repo structure x y ^xchild\n+------------\n++\n SEE ALSO\n --------\n linkgit:git-rev-parse[1]\ndiff --git a/builtin/repo.c b/builtin/repo.c\nindex 84e012f83f..78638c2dcd 100644\n--- a/builtin/repo.c\n+++ b/builtin/repo.c\n@@ -27,7 +27,7 @@\n \t\"git repo info --keys [--format=(lines|nul) | -z]\"\n \n #define REPO_STRUCTURE_USAGE \\\n-\t\"git repo structure [--format=(table|lines|nul) | -z]\"\n+\t\"git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\"\n \n static const char *const repo_usage[] = {\n \tREPO_INFO_USAGE,\n@@ -740,6 +740,7 @@ struct count_references_data {\n \tstruct ref_stats *stats;\n \tstruct rev_info *revs;\n \tstruct progress *progress;\n+\tbool add_to_pending;\n };\n \n static int count_references(const struct reference *ref, void *cb_data)\n@@ -766,10 +767,12 @@ static int count_references(const struct reference *ref, void *cb_data)\n \t}\n \n \t/*\n-\t * While iterating through references for counting, also add OIDs in\n+\t * While iterating through references for counting, if we didn't already\n+\t * populate the pending list in setup_revisions, also add OIDs in\n \t * preparation for the path walk.\n \t */\n-\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n+\tif (data->add_to_pending)\n+\t\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n \n \tref_count = get_total_reference_count(stats);\n \tdisplay_progress(data->progress, ref_count);\n@@ -780,11 +783,13 @@ static int count_references(const struct reference *ref, void *cb_data)\n static void structure_count_references(struct ref_stats *stats,\n \t\t\t\t       struct rev_info *revs,\n \t\t\t\t       struct repository *repo,\n-\t\t\t\t       int show_progress)\n+\t\t\t\t       int show_progress,\n+\t\t\t\t       bool add_to_pending)\n {\n \tstruct count_references_data data = {\n \t\t.stats = stats,\n \t\t.revs = revs,\n+\t\t.add_to_pending = add_to_pending\n \t};\n \n \tif (show_progress)\n@@ -935,6 +940,7 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \tstruct repo_structure stats = { 0 };\n \tstruct rev_info revs;\n \tint show_progress = -1;\n+\tbool included_revision_args = false;\n \tstruct option options[] = {\n \t\tOPT_CALLBACK_F(0, \"format\", &format, N_(\"format\"),\n \t\t\t       N_(\"output format\"),\n@@ -947,16 +953,20 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \t\tOPT_END()\n \t};\n \n-\targc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);\n-\tif (argc)\n-\t\tusage(_(\"too many arguments\"));\n-\n-\trepo_init_revisions(repo, &revs, prefix);\n-\n+\targc = parse_options(argc, argv, prefix, options, repo_structure_usage,\n+\t\t\t     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);\n \tif (show_progress < 0)\n \t\tshow_progress = isatty(2);\n \n-\tstructure_count_references(&stats.refs, &revs, repo, show_progress);\n+\trepo_init_revisions(repo, &revs, prefix);\n+\tif (argc > 1) {\n+\t\targc = setup_revisions(argc, argv, &revs, NULL);\n+\t\tincluded_revision_args = true;\n+\t\tif (argc > 1)\n+\t\t\treturn error(_(\"unrecognized argument: %s\"), argv[1]);\n+\t}\n+\n+\tstructure_count_references(&stats.refs, &revs, repo, show_progress, !included_revision_args);\n \tstructure_count_objects(&stats.objects, &revs, repo, show_progress);\n \n \tswitch (format) {\ndiff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\nindex 02cc2b594a..4e5e4a0a7a 100755\n--- a/t/t1901-repo-structure.sh\n+++ b/t/t1901-repo-structure.sh\n@@ -144,6 +144,203 @@ test_expect_success SHA1 'repository with references and objects' '\n \t)\n '\n \n+test_expect_success SHA1 'repository with branches' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\t\tgit repo structure --format=lines >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=1046\n+\t\tobjects.trees.count=1006\n+\t\tobjects.blobs.count=1006\n+\t\tobjects.tags.count=1\n+\t\tobjects.commits.inflated_size=231976\n+\t\tobjects.trees.inflated_size=16578431\n+\t\tobjects.blobs.inflated_size=11962\n+\t\tobjects.tags.inflated_size=132\n+\t\tobjects.commits.disk_size=163722\n+\t\tobjects.trees.disk_size=284547\n+\t\tobjects.blobs.disk_size=21022\n+\t\tobjects.tags.disk_size=126\n+\t\tobjects.commits.max_size=223\n+\t\tobjects.commits.max_size_oid=0dc91eb18580102a3a216c8bfecedeba2b9f9b9a\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=132\n+\t\tobjects.tags.max_size_oid=4dae4f5954f5e6feb3577cfb1b181daa3fd3afd2\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=df6400c01440c329f1011669c4c26cc0c7852887\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by a positive rev' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=1025\n+\t\tobjects.trees.count=1005\n+\t\tobjects.blobs.count=1005\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=227371\n+\t\tobjects.trees.inflated_size=16578363\n+\t\tobjects.blobs.inflated_size=11958\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=160455\n+\t\tobjects.trees.disk_size=284462\n+\t\tobjects.blobs.disk_size=21003\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=223\n+\t\tobjects.commits.max_size_oid=0dc91eb18580102a3a216c8bfecedeba2b9f9b9a\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\tgit repo structure --format=lines grobble >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by both positive and negative revs' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=20\n+\t\tobjects.trees.count=1\n+\t\tobjects.blobs.count=1005\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=4411\n+\t\tobjects.trees.inflated_size=33063\n+\t\tobjects.blobs.inflated_size=11958\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=3122\n+\t\tobjects.trees.disk_size=53\n+\t\tobjects.blobs.disk_size=21003\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=221\n+\t\tobjects.commits.max_size_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\tgit repo structure --format=lines grobble ^master >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success 'filter by object type' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=0\n+\t\tobjects.trees.count=0\n+\t\tobjects.blobs.count=1006\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=0\n+\t\tobjects.trees.inflated_size=0\n+\t\tobjects.blobs.inflated_size=11962\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=0\n+\t\tobjects.trees.disk_size=0\n+\t\tobjects.blobs.disk_size=21022\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=0\n+\t\tobjects.commits.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.trees.max_size=0\n+\t\tobjects.trees.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=0\n+\t\tobjects.commits.max_parents_oid=0000000000000000000000000000000000000000\n+\t\tobjects.trees.max_entries=0\n+\t\tobjects.trees.max_entries_oid=0000000000000000000000000000000000000000\n+\t\tEOF\n+\t\tgit repo structure --format=lines --objects --all --filter=object:type=blob >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n test_expect_success SHA1 'lines and nul format' '\n \ttest_when_finished \"rm -rf repo\" &&\n \tgit init repo &&\n-- \n2.53.0\n\n\n"},{"id":"555208","messageId":"atG2ukqpl5pA6V0H@pks.im","threadId":"66388","inReplyTo":"20261015170518.48395-2-markchucarroll@fastmail.com","subject":"Re: [PATCH v7 0/1] repo: add revision filtering options to \"repo structure\"","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-16T05:31:38Z","receivedAt":"2026-10-16T05:31:38Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Oct 15, 2026 at 01:05:18PM -0400, Mark C. Chu-Carroll wrote:\n> Differences from v6:\n> - Fix word duplication in commit message.\n\nThanks, this version looks good to me!\n\nPatrick\n\n"},{"id":"555236","messageId":"20261016133118.3659793-1-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20261015144559.3652143-3-markchucarroll@fastmail.com","subject":"[PATCH v7 0/1] repo: add revision filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-16T13:31:17Z","receivedAt":"2026-10-16T13:31:17Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"\"git repo structure\" provides a collection of useful information\nabout the information stored in a repo. In particular, it's\nvaluable for diagnosing performance issues caused by large objects\nstored in a repo.\n\nThe current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to get\ninformation about the specific part of the repo that's exhibiting\na problem.\n\nAdd the option to specify a set of revs. If revs are included,\nthen the set of objects processed will be limited based on the\nrev specification; otherwise, all objects will be processed.\n\nDifferences from v6:\n- Fix word duplication in commit message.\n\n\nMark C. Chu-Carroll (1):\n  repo: add filtering options to \"repo structure\"\n\n Documentation/git-repo.adoc |  31 +++++-\n builtin/repo.c              |  32 ++++--\n t/t1901-repo-structure.sh   | 197 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 247 insertions(+), 13 deletions(-)\n\n-- \n2.53.0\n\n\n"},{"id":"555237","messageId":"20261016133118.3659793-2-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20261016133118.3659793-1-markchucarroll@fastmail.com","subject":"[PATCH v7 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-16T13:31:18Z","receivedAt":"2026-10-16T13:31:18Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"The current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to\nfilter this information to get focused data about the specific\npart of the repo that's exhibiting a problem.\n\nUpdate \"git repo structure\" to use rev expressions\nto filter the set of objects to be processed.\n\nThis implementation makes an awkward trade-off involving\n\"setup_revisions\" which results in doing the ref-walk twice when\nrevisions are specified on the command line. In order to accept\nthe standard revs parameters, it uses `setup_revisions`, which does a\nref walk and populates the pending objects list that will be used by\n\"repo structure\". But this ref walk doesn't count refs in the way that\n\"repo structure\" requires, and because \"setup_revisions\" doesn't support\na custom callback for its ref-walk, that's not changeable.\n\nSo in the cases where a user specifies revs, \"repo structure\" does\nan initial ref-walk as part of \"setup_revisions\", and then a second\nref-walk in \"count_references\" in repo.c to count by reference type.\nFurther, if the user doesn't specify a revs parameter, \"setup_revisions\"\nis not called, so the \"count_references\" walk needs to add objects\nto the pending list. A parameter is added to \"count_references\"\nto allow it to distinguish the cases where the pending\nlist is already populated from the case where it needs to\npopulate it.\n\nSigned-off-by: Mark C. Chu-Carroll <markchucarroll@fastmail.com>\n---\n Documentation/git-repo.adoc |  31 +++++-\n builtin/repo.c              |  32 ++++--\n t/t1901-repo-structure.sh   | 197 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 247 insertions(+), 13 deletions(-)\n\ndiff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc\nindex ed7d80c690..819202dc4e 100644\n--- a/Documentation/git-repo.adoc\n+++ b/Documentation/git-repo.adoc\n@@ -10,7 +10,7 @@ SYNOPSIS\n [synopsis]\n git repo info [--format=(lines|nul) | -z] [--all | <key>...]\n git repo info --keys [--format=(lines|nul) | -z]\n-git repo structure [--format=(table|lines|nul) | -z]\n+git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\n \n DESCRIPTION\n -----------\n@@ -56,7 +56,7 @@ supported:\n `nul`:::\n \tSimilar to `lines`, but using a _NUL_ character after each value.\n \n-`structure [--format=(table|lines|nul) | -z]`::\n+`structure [--format=(table|lines|nul) | -z] [<revs>...]`::\n \tRetrieve statistics about the current repository structure. The\n \tfollowing kinds of information are reported:\n +\n@@ -66,6 +66,11 @@ supported:\n * Total disk size of reachable objects by type\n * Largest reachable objects in the repository by type\n +\n+The set of objects counted can be filtered by specifying a collection\n+of revisions to select which objects will be counted. These parameters\n+follow the same syntax as the parameters to similar commands like\n+`git log`. Defaults to all objects reachable from a reference.\n++\n The output format can be chosen through the flag `--format`. Three formats are\n supported:\n +\n@@ -141,6 +146,28 @@ using the `nul` format:\n git repo info --format=nul layout.bare layout.shallow\n ------------\n \n+* Generates information about storage usage in the repository:\n++\n+------------\n+git repo structure\n+------------\n++\n+\n+* Generates information about storage usage in the repository omitting\n+the branch \"foo\":\n++\n+------------\n+git repo structure --all ^foo\n+------------\n++\n+* Generates information about repository objects reachable from\n+the references \"x\" and \"y\", but omitting anything that can\n+only be reached on a path including \"xchild\":\n++\n+------------\n+git repo structure x y ^xchild\n+------------\n++\n SEE ALSO\n --------\n linkgit:git-rev-parse[1]\ndiff --git a/builtin/repo.c b/builtin/repo.c\nindex 84e012f83f..78638c2dcd 100644\n--- a/builtin/repo.c\n+++ b/builtin/repo.c\n@@ -27,7 +27,7 @@\n \t\"git repo info --keys [--format=(lines|nul) | -z]\"\n \n #define REPO_STRUCTURE_USAGE \\\n-\t\"git repo structure [--format=(table|lines|nul) | -z]\"\n+\t\"git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\"\n \n static const char *const repo_usage[] = {\n \tREPO_INFO_USAGE,\n@@ -740,6 +740,7 @@ struct count_references_data {\n \tstruct ref_stats *stats;\n \tstruct rev_info *revs;\n \tstruct progress *progress;\n+\tbool add_to_pending;\n };\n \n static int count_references(const struct reference *ref, void *cb_data)\n@@ -766,10 +767,12 @@ static int count_references(const struct reference *ref, void *cb_data)\n \t}\n \n \t/*\n-\t * While iterating through references for counting, also add OIDs in\n+\t * While iterating through references for counting, if we didn't already\n+\t * populate the pending list in setup_revisions, also add OIDs in\n \t * preparation for the path walk.\n \t */\n-\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n+\tif (data->add_to_pending)\n+\t\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n \n \tref_count = get_total_reference_count(stats);\n \tdisplay_progress(data->progress, ref_count);\n@@ -780,11 +783,13 @@ static int count_references(const struct reference *ref, void *cb_data)\n static void structure_count_references(struct ref_stats *stats,\n \t\t\t\t       struct rev_info *revs,\n \t\t\t\t       struct repository *repo,\n-\t\t\t\t       int show_progress)\n+\t\t\t\t       int show_progress,\n+\t\t\t\t       bool add_to_pending)\n {\n \tstruct count_references_data data = {\n \t\t.stats = stats,\n \t\t.revs = revs,\n+\t\t.add_to_pending = add_to_pending\n \t};\n \n \tif (show_progress)\n@@ -935,6 +940,7 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \tstruct repo_structure stats = { 0 };\n \tstruct rev_info revs;\n \tint show_progress = -1;\n+\tbool included_revision_args = false;\n \tstruct option options[] = {\n \t\tOPT_CALLBACK_F(0, \"format\", &format, N_(\"format\"),\n \t\t\t       N_(\"output format\"),\n@@ -947,16 +953,20 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \t\tOPT_END()\n \t};\n \n-\targc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);\n-\tif (argc)\n-\t\tusage(_(\"too many arguments\"));\n-\n-\trepo_init_revisions(repo, &revs, prefix);\n-\n+\targc = parse_options(argc, argv, prefix, options, repo_structure_usage,\n+\t\t\t     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);\n \tif (show_progress < 0)\n \t\tshow_progress = isatty(2);\n \n-\tstructure_count_references(&stats.refs, &revs, repo, show_progress);\n+\trepo_init_revisions(repo, &revs, prefix);\n+\tif (argc > 1) {\n+\t\targc = setup_revisions(argc, argv, &revs, NULL);\n+\t\tincluded_revision_args = true;\n+\t\tif (argc > 1)\n+\t\t\treturn error(_(\"unrecognized argument: %s\"), argv[1]);\n+\t}\n+\n+\tstructure_count_references(&stats.refs, &revs, repo, show_progress, !included_revision_args);\n \tstructure_count_objects(&stats.objects, &revs, repo, show_progress);\n \n \tswitch (format) {\ndiff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\nindex 02cc2b594a..4e5e4a0a7a 100755\n--- a/t/t1901-repo-structure.sh\n+++ b/t/t1901-repo-structure.sh\n@@ -144,6 +144,203 @@ test_expect_success SHA1 'repository with references and objects' '\n \t)\n '\n \n+test_expect_success SHA1 'repository with branches' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\t\tgit repo structure --format=lines >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=1046\n+\t\tobjects.trees.count=1006\n+\t\tobjects.blobs.count=1006\n+\t\tobjects.tags.count=1\n+\t\tobjects.commits.inflated_size=231976\n+\t\tobjects.trees.inflated_size=16578431\n+\t\tobjects.blobs.inflated_size=11962\n+\t\tobjects.tags.inflated_size=132\n+\t\tobjects.commits.disk_size=163722\n+\t\tobjects.trees.disk_size=284547\n+\t\tobjects.blobs.disk_size=21022\n+\t\tobjects.tags.disk_size=126\n+\t\tobjects.commits.max_size=223\n+\t\tobjects.commits.max_size_oid=0dc91eb18580102a3a216c8bfecedeba2b9f9b9a\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=132\n+\t\tobjects.tags.max_size_oid=4dae4f5954f5e6feb3577cfb1b181daa3fd3afd2\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=df6400c01440c329f1011669c4c26cc0c7852887\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by a positive rev' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=1025\n+\t\tobjects.trees.count=1005\n+\t\tobjects.blobs.count=1005\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=227371\n+\t\tobjects.trees.inflated_size=16578363\n+\t\tobjects.blobs.inflated_size=11958\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=160455\n+\t\tobjects.trees.disk_size=284462\n+\t\tobjects.blobs.disk_size=21003\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=223\n+\t\tobjects.commits.max_size_oid=0dc91eb18580102a3a216c8bfecedeba2b9f9b9a\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\tgit repo structure --format=lines grobble >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by both positive and negative revs' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=20\n+\t\tobjects.trees.count=1\n+\t\tobjects.blobs.count=1005\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=4411\n+\t\tobjects.trees.inflated_size=33063\n+\t\tobjects.blobs.inflated_size=11958\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=3122\n+\t\tobjects.trees.disk_size=53\n+\t\tobjects.blobs.disk_size=21003\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=221\n+\t\tobjects.commits.max_size_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\tgit repo structure --format=lines grobble ^master >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success 'filter by object type' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=0\n+\t\tobjects.trees.count=0\n+\t\tobjects.blobs.count=1006\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=0\n+\t\tobjects.trees.inflated_size=0\n+\t\tobjects.blobs.inflated_size=11962\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=0\n+\t\tobjects.trees.disk_size=0\n+\t\tobjects.blobs.disk_size=21022\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=0\n+\t\tobjects.commits.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.trees.max_size=0\n+\t\tobjects.trees.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=0\n+\t\tobjects.commits.max_parents_oid=0000000000000000000000000000000000000000\n+\t\tobjects.trees.max_entries=0\n+\t\tobjects.trees.max_entries_oid=0000000000000000000000000000000000000000\n+\t\tEOF\n+\t\tgit repo structure --format=lines --objects --all --filter=object:type=blob >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n test_expect_success SHA1 'lines and nul format' '\n \ttest_when_finished \"rm -rf repo\" &&\n \tgit init repo &&\n-- \n2.53.0\n\n\n"},{"id":"555295","messageId":"xmqq33u5c6z6.fsf@gitster.g","threadId":"66388","inReplyTo":"20261015170342.39967-2-markchucarroll@fastmail.com","subject":"Re: [PATCH v7 1/1] repo: add filtering options to \"repo structure\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-17T03:59:41Z","receivedAt":"2026-10-17T03:59:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Mark C. Chu-Carroll\" <markchucarroll@fastmail.com> writes:\n\n>  t/t1901-repo-structure.sh   | 197 ++++++++++++++++++++++++++++++++++++\n\nThis test is broken with SHA-256 and in Git 3.0.\n\n> +test_expect_success 'filter by object type' '\n\nThis hardcodes many 40 hexdigits constants, like ...\n\n> +\ttest_when_finished \"rm -rf repo\" &&\n> +\tgit init repo &&\n> +\t(\n> ...\n> +\t\tobjects.blobs.max_size=13\n> +\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n\n... this one, which is very specific to SHA-1.  Existing tests in\nthis file (like the one immediately after this one) protects such a\ntest with SHA1 prerequisite to avoid breaking in SHA-256\nenvironment, which is far from ideal but better than leaving it\nbroken.  In the longer term, we should strive to get rid of use of\nSHA1 prerequisites, as SHA-256 will be becoming the default in not\nso distant future versions of Git.\n\n>  test_expect_success SHA1 'lines and nul format' '\n>  \ttest_when_finished \"rm -rf repo\" &&\n>  \tgit init repo &&\n\nIf you choose to fix them, see recent effort by others for\ninspiration to make sure you can share and reuse most of this test\nbetween two supported hash functions, e.g. the discussion that lead\nto\n\n  https://lore.kernel.org/git/pull.2252.v4.git.1792012956734.gitgitgadget@gmail.com/\n\nbut you may choose to punt and just put your broken test under SHA1\nprerequisite to sweep the breakage under the rug just like other\nexisting tests in this file.\n\n\n\n"},{"id":"558745","messageId":"DMYL3TCBEMAJ.2MW8J9PLG9ZD@fastmail.com","threadId":"66388","inReplyTo":"xmqq33u5c6z6.fsf@gitster.g","subject":"Re: [PATCH v7 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-11-18T19:30:16Z","receivedAt":"2026-11-18T19:30:16Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"On Fri Oct 16, 2026 at 11:59 PM EDT, Junio C Hamano wrote:\n> \"Mark C. Chu-Carroll\" <markchucarroll@fastmail.com> writes:\n>\n>>  t/t1901-repo-structure.sh   | 197 ++++++++++++++++++++++++++++++++++++\n>\n> This test is broken with SHA-256 and in Git 3.0.\n>\n>> +test_expect_success 'filter by object type' '\n>\n> This hardcodes many 40 hexdigits constants, like ...\n>\n>> +\ttest_when_finished \"rm -rf repo\" &&\n>> +\tgit init repo &&\n>> +\t(\n>> ...\n>> +\t\tobjects.blobs.max_size=13\n>> +\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n>\n> ... this one, which is very specific to SHA-1.  Existing tests in\n> this file (like the one immediately after this one) protects such a\n> test with SHA1 prerequisite to avoid breaking in SHA-256\n> environment, which is far from ideal but better than leaving it\n> broken.  In the longer term, we should strive to get rid of use of\n> SHA1 prerequisites, as SHA-256 will be becoming the default in not\n> so distant future versions of Git.\n>\n>>  test_expect_success SHA1 'lines and nul format' '\n>>  \ttest_when_finished \"rm -rf repo\" &&\n>>  \tgit init repo &&\n>\n> If you choose to fix them, see recent effort by others for\n> inspiration to make sure you can share and reuse most of this test\n> between two supported hash functions, e.g. the discussion that lead\n> to\n>\n>   https://lore.kernel.org/git/pull.2252.v4.git.1792012956734.gitgitgadget@gmail.com/\n>\n> but you may choose to punt and just put your broken test under SHA1\n> prerequisite to sweep the breakage under the rug just like other\n> existing tests in this file.\n\nSorry for the delay in responding to this; I missed this message.\n\nI think that the best approach for now is to put this under SHA1,\nthen I'll take on updating all of the tests in this file to get rid \nofthe SHA1 prerequisite.\n\n      -Mark\n\n-- \nMark Craig Chu-Carroll (@MarkChuCarroll at gitlab)\n*** Software Tools/Math Geek - Software Engineer at Gitlab\n*** Work Email: mcarroll@gitlab.com / markchucarroll@fastmail.com\n*** Personal Blog: http://goodmath.org/blog / Personal email: markcc@gmail.com\n\n\n"},{"id":"558748","messageId":"20261118203519.2379494-1-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20261015144559.3652143-3-markchucarroll@fastmail.com","subject":"[PATCH v8 0/1] repo: add revision filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-11-18T20:35:18Z","receivedAt":"2026-11-18T20:35:18Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"\"git repo structure\" provides a collection of useful information\nabout the information stored in a repo. In particular, it's\nvaluable for diagnosing performance issues caused by large objects\nstored in a repo.\n\nThe current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to get\ninformation about the specific part of the repo that's exhibiting\na problem.\n\nAdd the option to specify a set of revs. If revs are included,\nthen the set of objects processed will be limited based on the\nrev specification; otherwise, all objects will be processed.\n\nDifferences from v7:\n- Add SHA1 prerequisite for new tests.\n\n\nMark C. Chu-Carroll (1):\n  repo: add filtering options to \"repo structure\"\n\n Documentation/git-repo.adoc |  31 +++++-\n builtin/repo.c              |  32 ++++--\n t/t1901-repo-structure.sh   | 197 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 247 insertions(+), 13 deletions(-)\n\n-- \n2.53.0\n\n\n"},{"id":"558749","messageId":"20261118203519.2379494-2-markchucarroll@fastmail.com","threadId":"66388","inReplyTo":"20261118203519.2379494-1-markchucarroll@fastmail.com","subject":"[PATCH v8 1/1] repo: add filtering options to \"repo structure\"","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-11-18T20:35:19Z","receivedAt":"2026-11-18T20:35:19Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"The current implementation of \"git repo stucture\" provides summary\ninformation about everything in the repository - all of the\nbranches, remotes, tags, stashes, and notes. But sometimes\nto properly diagnose a problem, it's useful to be able to\nfilter this information to get focused data about the specific\npart of the repo that's exhibiting a problem.\n\nUpdate \"git repo structure\" to use rev expressions\nto filter the set of objects to be processed.\n\nThis implementation makes an awkward trade-off involving\n\"setup_revisions\" which results in doing the ref-walk twice when\nrevisions are specified on the command line. In order to accept\nthe standard revs parameters, it uses `setup_revisions`, which does a\nref walk and populates the pending objects list that will be used by\n\"repo structure\". But this ref walk doesn't count refs in the way that\n\"repo structure\" requires, and because \"setup_revisions\" doesn't support\na custom callback for its ref-walk, that's not changeable.\n\nSo in the cases where a user specifies revs, \"repo structure\" does\nan initial ref-walk as part of \"setup_revisions\", and then a second\nref-walk in \"count_references\" in repo.c to count by reference type.\nFurther, if the user doesn't specify a revs parameter, \"setup_revisions\"\nis not called, so the \"count_references\" walk needs to add objects\nto the pending list. A parameter is added to \"count_references\"\nto allow it to distinguish the cases where the pending\nlist is already populated from the case where it needs to\npopulate it.\n\nSigned-off-by: Mark C. Chu-Carroll <markchucarroll@fastmail.com>\n---\n Documentation/git-repo.adoc |  31 +++++-\n builtin/repo.c              |  32 ++++--\n t/t1901-repo-structure.sh   | 197 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 247 insertions(+), 13 deletions(-)\n\ndiff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc\nindex ed7d80c690..819202dc4e 100644\n--- a/Documentation/git-repo.adoc\n+++ b/Documentation/git-repo.adoc\n@@ -10,7 +10,7 @@ SYNOPSIS\n [synopsis]\n git repo info [--format=(lines|nul) | -z] [--all | <key>...]\n git repo info --keys [--format=(lines|nul) | -z]\n-git repo structure [--format=(table|lines|nul) | -z]\n+git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\n \n DESCRIPTION\n -----------\n@@ -56,7 +56,7 @@ supported:\n `nul`:::\n \tSimilar to `lines`, but using a _NUL_ character after each value.\n \n-`structure [--format=(table|lines|nul) | -z]`::\n+`structure [--format=(table|lines|nul) | -z] [<revs>...]`::\n \tRetrieve statistics about the current repository structure. The\n \tfollowing kinds of information are reported:\n +\n@@ -66,6 +66,11 @@ supported:\n * Total disk size of reachable objects by type\n * Largest reachable objects in the repository by type\n +\n+The set of objects counted can be filtered by specifying a collection\n+of revisions to select which objects will be counted. These parameters\n+follow the same syntax as the parameters to similar commands like\n+`git log`. Defaults to all objects reachable from a reference.\n++\n The output format can be chosen through the flag `--format`. Three formats are\n supported:\n +\n@@ -141,6 +146,28 @@ using the `nul` format:\n git repo info --format=nul layout.bare layout.shallow\n ------------\n \n+* Generates information about storage usage in the repository:\n++\n+------------\n+git repo structure\n+------------\n++\n+\n+* Generates information about storage usage in the repository omitting\n+the branch \"foo\":\n++\n+------------\n+git repo structure --all ^foo\n+------------\n++\n+* Generates information about repository objects reachable from\n+the references \"x\" and \"y\", but omitting anything that can\n+only be reached on a path including \"xchild\":\n++\n+------------\n+git repo structure x y ^xchild\n+------------\n++\n SEE ALSO\n --------\n linkgit:git-rev-parse[1]\ndiff --git a/builtin/repo.c b/builtin/repo.c\nindex 84e012f83f..78638c2dcd 100644\n--- a/builtin/repo.c\n+++ b/builtin/repo.c\n@@ -27,7 +27,7 @@\n \t\"git repo info --keys [--format=(lines|nul) | -z]\"\n \n #define REPO_STRUCTURE_USAGE \\\n-\t\"git repo structure [--format=(table|lines|nul) | -z]\"\n+\t\"git repo structure [--format=(table|lines|nul) | -z] [<revs>...]\"\n \n static const char *const repo_usage[] = {\n \tREPO_INFO_USAGE,\n@@ -740,6 +740,7 @@ struct count_references_data {\n \tstruct ref_stats *stats;\n \tstruct rev_info *revs;\n \tstruct progress *progress;\n+\tbool add_to_pending;\n };\n \n static int count_references(const struct reference *ref, void *cb_data)\n@@ -766,10 +767,12 @@ static int count_references(const struct reference *ref, void *cb_data)\n \t}\n \n \t/*\n-\t * While iterating through references for counting, also add OIDs in\n+\t * While iterating through references for counting, if we didn't already\n+\t * populate the pending list in setup_revisions, also add OIDs in\n \t * preparation for the path walk.\n \t */\n-\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n+\tif (data->add_to_pending)\n+\t\tadd_pending_oid(data->revs, NULL, ref->oid, 0);\n \n \tref_count = get_total_reference_count(stats);\n \tdisplay_progress(data->progress, ref_count);\n@@ -780,11 +783,13 @@ static int count_references(const struct reference *ref, void *cb_data)\n static void structure_count_references(struct ref_stats *stats,\n \t\t\t\t       struct rev_info *revs,\n \t\t\t\t       struct repository *repo,\n-\t\t\t\t       int show_progress)\n+\t\t\t\t       int show_progress,\n+\t\t\t\t       bool add_to_pending)\n {\n \tstruct count_references_data data = {\n \t\t.stats = stats,\n \t\t.revs = revs,\n+\t\t.add_to_pending = add_to_pending\n \t};\n \n \tif (show_progress)\n@@ -935,6 +940,7 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \tstruct repo_structure stats = { 0 };\n \tstruct rev_info revs;\n \tint show_progress = -1;\n+\tbool included_revision_args = false;\n \tstruct option options[] = {\n \t\tOPT_CALLBACK_F(0, \"format\", &format, N_(\"format\"),\n \t\t\t       N_(\"output format\"),\n@@ -947,16 +953,20 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,\n \t\tOPT_END()\n \t};\n \n-\targc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);\n-\tif (argc)\n-\t\tusage(_(\"too many arguments\"));\n-\n-\trepo_init_revisions(repo, &revs, prefix);\n-\n+\targc = parse_options(argc, argv, prefix, options, repo_structure_usage,\n+\t\t\t     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);\n \tif (show_progress < 0)\n \t\tshow_progress = isatty(2);\n \n-\tstructure_count_references(&stats.refs, &revs, repo, show_progress);\n+\trepo_init_revisions(repo, &revs, prefix);\n+\tif (argc > 1) {\n+\t\targc = setup_revisions(argc, argv, &revs, NULL);\n+\t\tincluded_revision_args = true;\n+\t\tif (argc > 1)\n+\t\t\treturn error(_(\"unrecognized argument: %s\"), argv[1]);\n+\t}\n+\n+\tstructure_count_references(&stats.refs, &revs, repo, show_progress, !included_revision_args);\n \tstructure_count_objects(&stats.objects, &revs, repo, show_progress);\n \n \tswitch (format) {\ndiff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh\nindex 02cc2b594a..e901023cb9 100755\n--- a/t/t1901-repo-structure.sh\n+++ b/t/t1901-repo-structure.sh\n@@ -144,6 +144,203 @@ test_expect_success SHA1 'repository with references and objects' '\n \t)\n '\n \n+test_expect_success SHA1 'repository with branches' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\t\tgit repo structure --format=lines >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=1046\n+\t\tobjects.trees.count=1006\n+\t\tobjects.blobs.count=1006\n+\t\tobjects.tags.count=1\n+\t\tobjects.commits.inflated_size=231976\n+\t\tobjects.trees.inflated_size=16578431\n+\t\tobjects.blobs.inflated_size=11962\n+\t\tobjects.tags.inflated_size=132\n+\t\tobjects.commits.disk_size=163722\n+\t\tobjects.trees.disk_size=284547\n+\t\tobjects.blobs.disk_size=21022\n+\t\tobjects.tags.disk_size=126\n+\t\tobjects.commits.max_size=223\n+\t\tobjects.commits.max_size_oid=0dc91eb18580102a3a216c8bfecedeba2b9f9b9a\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=132\n+\t\tobjects.tags.max_size_oid=4dae4f5954f5e6feb3577cfb1b181daa3fd3afd2\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=df6400c01440c329f1011669c4c26cc0c7852887\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by a positive rev' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=1025\n+\t\tobjects.trees.count=1005\n+\t\tobjects.blobs.count=1005\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=227371\n+\t\tobjects.trees.inflated_size=16578363\n+\t\tobjects.blobs.inflated_size=11958\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=160455\n+\t\tobjects.trees.disk_size=284462\n+\t\tobjects.blobs.disk_size=21003\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=223\n+\t\tobjects.commits.max_size_oid=0dc91eb18580102a3a216c8bfecedeba2b9f9b9a\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\tgit repo structure --format=lines grobble >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by both positive and negative revs' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=20\n+\t\tobjects.trees.count=1\n+\t\tobjects.blobs.count=1005\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=4411\n+\t\tobjects.trees.inflated_size=33063\n+\t\tobjects.blobs.inflated_size=11958\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=3122\n+\t\tobjects.trees.disk_size=53\n+\t\tobjects.blobs.disk_size=21003\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=221\n+\t\tobjects.commits.max_size_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_size=33063\n+\t\tobjects.trees.max_size_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=1\n+\t\tobjects.commits.max_parents_oid=c1d3cb6c863e93a546c657ccecdf0f643d2e18af\n+\t\tobjects.trees.max_entries=1005\n+\t\tobjects.trees.max_entries_oid=60665251ab71dbd8c18d9bf2174f4ee0d58aa06c\n+\t\tEOF\n+\t\tgit repo structure --format=lines grobble ^master >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n+test_expect_success SHA1 'filter by object type' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit_bulk 1005 &&\n+\t\tgit tag -a foo -m bar &&\n+\n+\t\toid=\"$(git rev-parse HEAD)\" &&\n+\t\tgit update-ref refs/remotes/origin/foo \"$oid\" &&\n+\t\tgit checkout -b grobble &&\n+\t\ttest_commit_bulk --ref=refs/heads/grobble 20 &&\n+\t\tgit checkout master &&\n+\t\ttest_commit_bulk 20 &&\n+\t\t# Also creates a commit, tree, and blob.\n+\t\tgit notes add -m foo &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tobjects.commits.count=0\n+\t\tobjects.trees.count=0\n+\t\tobjects.blobs.count=1006\n+\t\tobjects.tags.count=0\n+\t\tobjects.commits.inflated_size=0\n+\t\tobjects.trees.inflated_size=0\n+\t\tobjects.blobs.inflated_size=11962\n+\t\tobjects.tags.inflated_size=0\n+\t\tobjects.commits.disk_size=0\n+\t\tobjects.trees.disk_size=0\n+\t\tobjects.blobs.disk_size=21022\n+\t\tobjects.tags.disk_size=0\n+\t\tobjects.commits.max_size=0\n+\t\tobjects.commits.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.trees.max_size=0\n+\t\tobjects.trees.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.blobs.max_size=13\n+\t\tobjects.blobs.max_size_oid=97d808e45116bf02103490294d3d46dad7a2ac62\n+\t\tobjects.tags.max_size=0\n+\t\tobjects.tags.max_size_oid=0000000000000000000000000000000000000000\n+\t\tobjects.commits.max_parents=0\n+\t\tobjects.commits.max_parents_oid=0000000000000000000000000000000000000000\n+\t\tobjects.trees.max_entries=0\n+\t\tobjects.trees.max_entries_oid=0000000000000000000000000000000000000000\n+\t\tEOF\n+\t\tgit repo structure --format=lines --objects --all --filter=object:type=blob >actual 2>err &&\n+\t\ttest_grep \"^objects\" actual >actual.objects &&\n+\t\ttest_cmp expect actual.objects &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n test_expect_success SHA1 'lines and nul format' '\n \ttest_when_finished \"rm -rf repo\" &&\n \tgit init repo &&\n-- \n2.53.0\n\n\n"},{"id":"558763","messageId":"xmqq7bi93i4h.fsf@gitster.g","threadId":"66388","inReplyTo":"20261118203519.2379494-2-markchucarroll@fastmail.com","subject":"Re: [PATCH v8 1/1] repo: add filtering options to \"repo structure\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-18T22:11:10Z","receivedAt":"2026-11-18T22:11:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Mark C. Chu-Carroll\" <markchucarroll@fastmail.com> writes:\n\n> +\t\tobjects.commits.disk_size=163722\n> +\t\tobjects.trees.disk_size=284547\n> +\t\tobjects.blobs.disk_size=21022\n> +\t\tobjects.tags.disk_size=126\n\nThis may not be a new problem, but hardcoding .disk_size would make\nthese tests unnecessarily brittle when you consider there are\ndifferent zlib implementations.\n\n"},{"id":"558764","messageId":"xmqq33sx3haz.fsf@gitster.g","threadId":"66388","inReplyTo":"20261118203519.2379494-2-markchucarroll@fastmail.com","subject":"Re: [PATCH v8 1/1] repo: add filtering options to \"repo structure\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-18T22:28:52Z","receivedAt":"2026-11-18T22:28:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Mark C. Chu-Carroll\" <markchucarroll@fastmail.com> writes:\n\n> The current implementation of \"git repo stucture\" provides summary\n> information about everything in the repository - all of the\n...\n\n> +\targc = parse_options(argc, argv, prefix, options, repo_structure_usage,\n> +\t\t\t     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);\n\nAre we willing to lose \"--\" from the command line?  For example, to\ncount only the commits that touch things under the t/ directory\nbetween master and grobble:\n\n    git repo stucture master..grobble -- t/\n\nmight be useful, but without PARSE_OPT_KEEP_DASHDASH, wouldn't you\nlose \"--\"?  If there are directories or files that happen to have\nthe same name as an existing revision, the users would need to be\nable to disambiguate them with \"--\".\n\n>  \tif (show_progress < 0)\n>  \t\tshow_progress = isatty(2);\n>  \n> +\trepo_init_revisions(repo, &revs, prefix);\n> +\tif (argc > 1) {\n> +\t\targc = setup_revisions(argc, argv, &revs, NULL);\n> +\t\tincluded_revision_args = true;\n\nThings like\n\n    git repo stucture --objects\n    git repo stucture --stdin\n    git repo stucture --end-of-options\n\nwould still count as (argc > 1) and cause setup_revisions() to be\ncalled, but we still have not received any positive (or negative)\nrevision to start traversing.  Should not included_revision_args be\ninitialized based on revs.rev_input_given or something?\n\n> +\t\tif (argc > 1)\n> +\t\t\treturn error(_(\"unrecognized argument: %s\"), argv[1]);\n\nThis leaks revs and resources held by it because release_revisions()\nhas not been called on it, which may not matter all that much as we\nwill exit soon.\n\n> +\t}\n> +\n> +\tstructure_count_references(&stats.refs, &revs, repo, show_progress, !included_revision_args);\n>  \tstructure_count_objects(&stats.objects, &revs, repo, show_progress);\n\n"}]}