Skip to content

Commit 56495fd

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 9ca91df commit 56495fd

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

Documentation/config/survey.adoc

+4-1
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-
--
11+
top::
12+
This integer value implies `--top=<N>`, specifying the
13+
number of entries in the detail tables.
14+
----

builtin/survey.c

+14-8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static struct survey_refs_wanted default_ref_options = {
4545
struct survey_opts {
4646
int verbose;
4747
int show_progress;
48+
int top_nr;
4849
struct survey_refs_wanted refs;
4950
};
5051

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

557562
return git_default_config(var, value, cctx, pvoid);
558563
}
@@ -797,8 +802,6 @@ static int survey_objects_path_walk_fn(const char *path,
797802

798803
static void initialize_report(struct survey_context *ctx)
799804
{
800-
const int top_limit = 100;
801-
802805
CALLOC_ARRAY(ctx->report.by_type, REPORT_TYPE_COUNT);
803806
ctx->report.by_type[REPORT_TYPE_COMMIT].label = xstrdup(_("Commits"));
804807
ctx->report.by_type[REPORT_TYPE_TREE].label = xstrdup(_("Trees"));
@@ -807,21 +810,21 @@ static void initialize_report(struct survey_context *ctx)
807810

808811
CALLOC_ARRAY(ctx->report.top_paths_by_count, REPORT_TYPE_COUNT);
809812
init_top_sizes(&ctx->report.top_paths_by_count[REPORT_TYPE_TREE],
810-
top_limit, _("TOP DIRECTORIES BY COUNT"), cmp_by_nr);
813+
ctx->opts.top_nr, _("TOP DIRECTORIES BY COUNT"), cmp_by_nr);
811814
init_top_sizes(&ctx->report.top_paths_by_count[REPORT_TYPE_BLOB],
812-
top_limit, _("TOP FILES BY COUNT"), cmp_by_nr);
815+
ctx->opts.top_nr, _("TOP FILES BY COUNT"), cmp_by_nr);
813816

814817
CALLOC_ARRAY(ctx->report.top_paths_by_disk, REPORT_TYPE_COUNT);
815818
init_top_sizes(&ctx->report.top_paths_by_disk[REPORT_TYPE_TREE],
816-
top_limit, _("TOP DIRECTORIES BY DISK SIZE"), cmp_by_disk_size);
819+
ctx->opts.top_nr, _("TOP DIRECTORIES BY DISK SIZE"), cmp_by_disk_size);
817820
init_top_sizes(&ctx->report.top_paths_by_disk[REPORT_TYPE_BLOB],
818-
top_limit, _("TOP FILES BY DISK SIZE"), cmp_by_disk_size);
821+
ctx->opts.top_nr, _("TOP FILES BY DISK SIZE"), cmp_by_disk_size);
819822

820823
CALLOC_ARRAY(ctx->report.top_paths_by_inflate, REPORT_TYPE_COUNT);
821824
init_top_sizes(&ctx->report.top_paths_by_inflate[REPORT_TYPE_TREE],
822-
top_limit, _("TOP DIRECTORIES BY INFLATED SIZE"), cmp_by_inflated_size);
825+
ctx->opts.top_nr, _("TOP DIRECTORIES BY INFLATED SIZE"), cmp_by_inflated_size);
823826
init_top_sizes(&ctx->report.top_paths_by_inflate[REPORT_TYPE_BLOB],
824-
top_limit, _("TOP FILES BY INFLATED SIZE"), cmp_by_inflated_size);
827+
ctx->opts.top_nr, _("TOP FILES BY INFLATED SIZE"), cmp_by_inflated_size);
825828
}
826829

827830
static void survey_phase_objects(struct survey_context *ctx)
@@ -873,6 +876,7 @@ int cmd_survey(int argc, const char **argv, const char *prefix,
873876
.opts = {
874877
.verbose = 0,
875878
.show_progress = -1, /* defaults to isatty(2) */
879+
.top_nr = 100,
876880

877881
.refs.want_all_refs = -1,
878882

@@ -888,6 +892,8 @@ int cmd_survey(int argc, const char **argv, const char *prefix,
888892
static struct option survey_options[] = {
889893
OPT__VERBOSE(&ctx.opts.verbose, N_("verbose output")),
890894
OPT_BOOL(0, "progress", &ctx.opts.show_progress, N_("show progress")),
895+
OPT_INTEGER('n', "top", &ctx.opts.top_nr,
896+
N_("number of entries to include in detail tables")),
891897

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

0 commit comments

Comments
 (0)