mirror of
https://github.com/git-for-windows/git.git
synced 2026-07-13 01:59:04 -05:00
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=<N>` 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 <johannes.schindelin@gmx.de>
This commit is contained in:
committed by
Git for Windows Build Agent
parent
22b20242a3
commit
b23aa33398
@@ -515,6 +515,8 @@ include::config/remotes.adoc[]
|
||||
|
||||
include::config/repack.adoc[]
|
||||
|
||||
include::config/repo.adoc[]
|
||||
|
||||
include::config/rerere.adoc[]
|
||||
|
||||
include::config/revert.adoc[]
|
||||
|
||||
11
Documentation/config/repo.adoc
Normal file
11
Documentation/config/repo.adoc
Normal file
@@ -0,0 +1,11 @@
|
||||
repo.structure.*::
|
||||
These variables adjust the default behavior of the
|
||||
`git repo structure` command.
|
||||
+
|
||||
--
|
||||
top::
|
||||
This integer value implies `--top=<N>`, specifying the
|
||||
number of largest paths to report in each detail table.
|
||||
Must be non-negative; defaults to `0`, which disables the
|
||||
detail tables.
|
||||
--
|
||||
@@ -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"));
|
||||
|
||||
@@ -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 &&
|
||||
|
||||
Reference in New Issue
Block a user