Skip to content

Commit b9ef61a

Browse files
committed
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 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 <stolee@gmail.com>
1 parent 20f0542 commit b9ef61a

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

Documentation/config/survey.txt

+3
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ survey.*::
88
This boolean value implies the `--[no-]verbose` option.
99
progress::
1010
This boolean value implies the `--[no-]progress` option.
11+
top::
12+
This integer value implies `--top=<N>`, specifying the
13+
number of entries in the detail tables.
1114
--

builtin/survey.c

+14-8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static struct survey_refs_wanted default_ref_options = {
4444
struct survey_opts {
4545
int verbose;
4646
int show_progress;
47+
int top_nr;
4748
struct survey_refs_wanted refs;
4849
};
4950

@@ -552,6 +553,10 @@ static int survey_load_config_cb(const char *var, const char *value,
552553
ctx->opts.show_progress = git_config_bool(var, value);
553554
return 0;
554555
}
556+
if (!strcmp(var, "survey.top")) {
557+
ctx->opts.top_nr = git_config_bool(var, value);
558+
return 0;
559+
}
555560

556561
return git_default_config(var, value, cctx, pvoid);
557562
}
@@ -796,8 +801,6 @@ static int survey_objects_path_walk_fn(const char *path,
796801

797802
static void initialize_report(struct survey_context *ctx)
798803
{
799-
const int top_limit = 100;
800-
801804
CALLOC_ARRAY(ctx->report.by_type, REPORT_TYPE_COUNT);
802805
ctx->report.by_type[REPORT_TYPE_COMMIT].label = xstrdup(_("Commits"));
803806
ctx->report.by_type[REPORT_TYPE_TREE].label = xstrdup(_("Trees"));
@@ -806,21 +809,21 @@ static void initialize_report(struct survey_context *ctx)
806809

807810
CALLOC_ARRAY(ctx->report.top_paths_by_count, REPORT_TYPE_COUNT);
808811
init_top_sizes(&ctx->report.top_paths_by_count[REPORT_TYPE_TREE],
809-
top_limit, _("TOP DIRECTORIES BY COUNT"), cmp_by_nr);
812+
ctx->opts.top_nr, _("TOP DIRECTORIES BY COUNT"), cmp_by_nr);
810813
init_top_sizes(&ctx->report.top_paths_by_count[REPORT_TYPE_BLOB],
811-
top_limit, _("TOP FILES BY COUNT"), cmp_by_nr);
814+
ctx->opts.top_nr, _("TOP FILES BY COUNT"), cmp_by_nr);
812815

813816
CALLOC_ARRAY(ctx->report.top_paths_by_disk, REPORT_TYPE_COUNT);
814817
init_top_sizes(&ctx->report.top_paths_by_disk[REPORT_TYPE_TREE],
815-
top_limit, _("TOP DIRECTORIES BY DISK SIZE"), cmp_by_disk_size);
818+
ctx->opts.top_nr, _("TOP DIRECTORIES BY DISK SIZE"), cmp_by_disk_size);
816819
init_top_sizes(&ctx->report.top_paths_by_disk[REPORT_TYPE_BLOB],
817-
top_limit, _("TOP FILES BY DISK SIZE"), cmp_by_disk_size);
820+
ctx->opts.top_nr, _("TOP FILES BY DISK SIZE"), cmp_by_disk_size);
818821

819822
CALLOC_ARRAY(ctx->report.top_paths_by_inflate, REPORT_TYPE_COUNT);
820823
init_top_sizes(&ctx->report.top_paths_by_inflate[REPORT_TYPE_TREE],
821-
top_limit, _("TOP DIRECTORIES BY INFLATED SIZE"), cmp_by_inflated_size);
824+
ctx->opts.top_nr, _("TOP DIRECTORIES BY INFLATED SIZE"), cmp_by_inflated_size);
822825
init_top_sizes(&ctx->report.top_paths_by_inflate[REPORT_TYPE_BLOB],
823-
top_limit, _("TOP FILES BY INFLATED SIZE"), cmp_by_inflated_size);
826+
ctx->opts.top_nr, _("TOP FILES BY INFLATED SIZE"), cmp_by_inflated_size);
824827
}
825828

826829
static void survey_phase_objects(struct survey_context *ctx)
@@ -870,6 +873,7 @@ int cmd_survey(int argc, const char **argv, const char *prefix,
870873
.opts = {
871874
.verbose = 0,
872875
.show_progress = -1, /* defaults to isatty(2) */
876+
.top_nr = 100,
873877

874878
.refs.want_all_refs = -1,
875879

@@ -885,6 +889,8 @@ int cmd_survey(int argc, const char **argv, const char *prefix,
885889
static struct option survey_options[] = {
886890
OPT__VERBOSE(&ctx.opts.verbose, N_("verbose output")),
887891
OPT_BOOL(0, "progress", &ctx.opts.show_progress, N_("show progress")),
892+
OPT_INTEGER('n', "top", &ctx.opts.top_nr,
893+
N_("number of entries to include in detail tables")),
888894

889895
OPT_BOOL_F(0, "all-refs", &ctx.opts.refs.want_all_refs, N_("include all refs"), PARSE_OPT_NONEG),
890896

0 commit comments

Comments
 (0)