Skip to content

Commit

Permalink
survey: add --top=<N> option and config
Browse files Browse the repository at this point in the history
The 'git survey' builtin provides several detail tables, such as "top
files by on-disk size". The size of these tables defaults to 100,
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 <[email protected]>
  • Loading branch information
derrickstolee committed Nov 8, 2024
1 parent b70eee6 commit dd54ff7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Documentation/config/survey.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
--
22 changes: 14 additions & 8 deletions builtin/survey.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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;
};

Expand Down Expand Up @@ -552,6 +553,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);
}
Expand Down Expand Up @@ -796,8 +801,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"));
Expand All @@ -806,21 +809,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)
Expand Down Expand Up @@ -870,6 +873,7 @@ int cmd_survey(int argc, const char **argv, const char *prefix,
.opts = {
.verbose = 0,
.show_progress = -1, /* defaults to isatty(2) */
.top_nr = 100,

.refs.want_all_refs = -1,

Expand All @@ -885,6 +889,8 @@ int cmd_survey(int argc, const char **argv, const char *prefix,
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),

Expand Down

0 comments on commit dd54ff7

Please sign in to comment.