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 &&