survey: add --top=<N> option and config

The 'git survey' builtin provides several detail tables, such as "top
files by on-disk size". The size of these tables defaults to 10,
currently.

Allow the user to specify this number via a new --top=<N> option or the
new survey.top config key.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Derrick Stolee 2024-09-23 15:38:25 -04:00 committed by Johannes Schindelin
parent dd6e9bee69
commit b41b5400f4
2 changed files with 17 additions and 8 deletions

View File

@ -8,4 +8,7 @@ survey.*::
This boolean value implies the `--[no-]verbose` option.
progress::
This boolean value implies the `--[no-]progress` option.
top::
This integer value implies `--top=<N>`, specifying the
number of entries in the detail tables.
--

View File

@ -40,6 +40,7 @@ static struct survey_refs_wanted default_ref_options = {
struct survey_opts {
int verbose;
int show_progress;
int top_nr;
struct survey_refs_wanted refs;
};
@ -548,6 +549,10 @@ static int survey_load_config_cb(const char *var, const char *value,
ctx->opts.show_progress = git_config_bool(var, value);
return 0;
}
if (!strcmp(var, "survey.top")) {
ctx->opts.top_nr = git_config_bool(var, value);
return 0;
}
return git_default_config(var, value, cctx, pvoid);
}
@ -793,8 +798,6 @@ static int survey_objects_path_walk_fn(const char *path,
static void initialize_report(struct survey_context *ctx)
{
const int top_limit = 100;
CALLOC_ARRAY(ctx->report.by_type, REPORT_TYPE_COUNT);
ctx->report.by_type[REPORT_TYPE_COMMIT].label = xstrdup(_("Commits"));
ctx->report.by_type[REPORT_TYPE_TREE].label = xstrdup(_("Trees"));
@ -803,21 +806,21 @@ static void initialize_report(struct survey_context *ctx)
CALLOC_ARRAY(ctx->report.top_paths_by_count, REPORT_TYPE_COUNT);
init_top_sizes(&ctx->report.top_paths_by_count[REPORT_TYPE_TREE],
top_limit, _("TOP DIRECTORIES BY COUNT"), cmp_by_nr);
ctx->opts.top_nr, _("TOP DIRECTORIES BY COUNT"), cmp_by_nr);
init_top_sizes(&ctx->report.top_paths_by_count[REPORT_TYPE_BLOB],
top_limit, _("TOP FILES BY COUNT"), cmp_by_nr);
ctx->opts.top_nr, _("TOP FILES BY COUNT"), cmp_by_nr);
CALLOC_ARRAY(ctx->report.top_paths_by_disk, REPORT_TYPE_COUNT);
init_top_sizes(&ctx->report.top_paths_by_disk[REPORT_TYPE_TREE],
top_limit, _("TOP DIRECTORIES BY DISK SIZE"), cmp_by_disk_size);
ctx->opts.top_nr, _("TOP DIRECTORIES BY DISK SIZE"), cmp_by_disk_size);
init_top_sizes(&ctx->report.top_paths_by_disk[REPORT_TYPE_BLOB],
top_limit, _("TOP FILES BY DISK SIZE"), cmp_by_disk_size);
ctx->opts.top_nr, _("TOP FILES BY DISK SIZE"), cmp_by_disk_size);
CALLOC_ARRAY(ctx->report.top_paths_by_inflate, REPORT_TYPE_COUNT);
init_top_sizes(&ctx->report.top_paths_by_inflate[REPORT_TYPE_TREE],
top_limit, _("TOP DIRECTORIES BY INFLATED SIZE"), cmp_by_inflated_size);
ctx->opts.top_nr, _("TOP DIRECTORIES BY INFLATED SIZE"), cmp_by_inflated_size);
init_top_sizes(&ctx->report.top_paths_by_inflate[REPORT_TYPE_BLOB],
top_limit, _("TOP FILES BY INFLATED SIZE"), cmp_by_inflated_size);
ctx->opts.top_nr, _("TOP FILES BY INFLATED SIZE"), cmp_by_inflated_size);
}
static void survey_phase_objects(struct survey_context *ctx)
@ -868,6 +871,7 @@ int cmd_survey(int argc, const char **argv, const char *prefix, struct repositor
.opts = {
.verbose = 0,
.show_progress = -1, /* defaults to isatty(2) */
.top_nr = 10,
.refs.want_all_refs = -1,
@ -883,6 +887,8 @@ int cmd_survey(int argc, const char **argv, const char *prefix, struct repositor
static struct option survey_options[] = {
OPT__VERBOSE(&ctx.opts.verbose, N_("verbose output")),
OPT_BOOL(0, "progress", &ctx.opts.show_progress, N_("show progress")),
OPT_INTEGER('n', "top", &ctx.opts.top_nr,
N_("number of entries to include in detail tables")),
OPT_BOOL_F(0, "all-refs", &ctx.opts.refs.want_all_refs, N_("include all refs"), PARSE_OPT_NONEG),