From b23aa33398025804773a137e7cb3ffcd32090bec Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 6 Jun 2026 00:23:37 +0200 Subject: [PATCH] repo: read the `--top` default from `repo.structure.top` `git survey` exposes its `--top` default via `survey.top` so that a site or per-repository operator can switch the detail tables on once and have every subsequent invocation include them. Mirror that ergonomics for `git repo structure` so that, as `git survey`'s functionality is folded into `git repo structure`, the configuration side of the migration story stays equivalent. Add a small `git_config_int` callback bound to `repo.structure.top` and invoke it before `parse_options()`, so a `--top=` on the command line cleanly overrides the configured default (including `--top=0` to opt out of the detail tables when configuration enables them). Reject negative configured values with the same wording as the command-line guard, since `git_config_int()` happily returns negative integers. Document the new variable in a fresh `Documentation/config/repo.adoc` and wire it into the alphabetical includes in `Documentation/config.adoc` between `repack.adoc` and `rerere.adoc`. Cover the precedence behaviour with a t1901 test: a configured value enables the tables by default, and a command-line `--top=0` suppresses them again. Note that the reported paths respect the `core.quotePath` setting. Assisted-by: Opus 4.7 Signed-off-by: Johannes Schindelin --- Documentation/config.adoc | 2 ++ Documentation/config/repo.adoc | 11 +++++++++++ builtin/repo.c | 19 +++++++++++++++++++ t/t1901-repo-structure.sh | 17 +++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 Documentation/config/repo.adoc diff --git a/Documentation/config.adoc b/Documentation/config.adoc index a8d8fb282e..bf6c73582e 100644 --- a/Documentation/config.adoc +++ b/Documentation/config.adoc @@ -515,6 +515,8 @@ include::config/remotes.adoc[] include::config/repack.adoc[] +include::config/repo.adoc[] + include::config/rerere.adoc[] include::config/revert.adoc[] diff --git a/Documentation/config/repo.adoc b/Documentation/config/repo.adoc new file mode 100644 index 0000000000..7f8cd63296 --- /dev/null +++ b/Documentation/config/repo.adoc @@ -0,0 +1,11 @@ +repo.structure.*:: + These variables adjust the default behavior of the + `git repo structure` command. ++ +-- + top:: + This integer value implies `--top=`, specifying the + number of largest paths to report in each detail table. + Must be non-negative; defaults to `0`, which disables the + detail tables. +-- diff --git a/builtin/repo.c b/builtin/repo.c index 6da126b129..5b7dbc5094 100644 --- a/builtin/repo.c +++ b/builtin/repo.c @@ -2,6 +2,7 @@ #include "builtin.h" #include "commit.h" +#include "config.h" #include "environment.h" #include "hash.h" #include "hex.h" @@ -1185,6 +1186,22 @@ static void structure_count_objects(struct object_stats *stats, stop_progress(&data.progress); } +static int repo_structure_config_cb(const char *var, const char *value, + const struct config_context *cctx, + void *cb) +{ + int *top_nr = cb; + + if (!strcmp(var, "repo.structure.top")) { + *top_nr = git_config_int(var, value, cctx->kvi); + if (*top_nr < 0) + die(_("repo.structure.top must be non-negative")); + return 0; + } + + return git_default_config(var, value, cctx, NULL); +} + static int cmd_repo_structure(int argc, const char **argv, const char *prefix, struct repository *repo) { @@ -1216,6 +1233,8 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix, OPT_END() }; + repo_config(repo, repo_structure_config_cb, &top_nr); + argc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0); if (argc) usage(_("too many arguments")); diff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh index ade3275392..fd18da2150 100755 --- a/t/t1901-repo-structure.sh +++ b/t/t1901-repo-structure.sh @@ -313,6 +313,23 @@ test_expect_success '--top rejects negative values' ' test_grep "must be non-negative" err ' +test_expect_success 'repo.structure.top supplies the default for --top' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + test_commit foo && + + git -c repo.structure.top=2 \ + repo structure --format=lines >with-config && + grep "^objects.blobs.top.by_count.1.path=" with-config && + + git -c repo.structure.top=2 \ + repo structure --format=lines --top=0 >cli-override && + ! grep "\.top\." cli-override + ) +' + test_expect_success 'git repo structure -h shows only repo structure usage' ' test_must_fail git repo structure -h >actual && test_grep "git repo structure" actual &&