Skip to content

Commit

Permalink
survey: add option to request refs in refs/pull/ to the set
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
  • Loading branch information
jeffhostetler committed May 20, 2024
1 parent f4568fd commit 0710898
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Documentation/git-survey.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ only refs for the given options are added.
Add custom namespace ('refs/prefetch/') to the set. This namespace
is used by background/nightly 'git maintenance' to prefetch commits.

--pull::
Add custom namespace ('refs/pull/') to the set.

Large Item Selection
~~~~~~~~~~~~~~~~~~~~

Expand Down
27 changes: 21 additions & 6 deletions builtin/survey.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ struct survey_refs_wanted {
int want_detached;
int want_other; /* see FILTER_REFS_OTHERS -- refs/notes/, refs/stash/ */
int want_prefetch;
/*
* TODO consider adding flags for:
* refs/pull/
* refs/changes/
*/
int want_pull;
};

static struct strvec survey_vec_refs_wanted = STRVEC_INIT;
Expand All @@ -56,6 +52,7 @@ static struct survey_refs_wanted refs_if_unspecified = {
.want_detached = 0,
.want_other = 0,
.want_prefetch = 0,
.want_pull = 0,
};

struct survey_opts {
Expand Down Expand Up @@ -99,6 +96,7 @@ static struct survey_opts survey_opts = {
.refs.want_detached = -1,
.refs.want_other = -1,
.refs.want_prefetch = -1,
.refs.want_pull = -1,
};

/*
Expand All @@ -114,6 +112,11 @@ static void fixup_refs_wanted(void)

/*
* `--all-refs` overrides and enables everything.
*
* NEEDSWORK: Should this just register "refs/" to sweep up
* everything (standard and custom prefixes alike) and then
* use a hashmap to group and count them rather than predefined
* refs.cnt_<foo> fields?
*/
if (rw->want_all_refs == 1) {
rw->want_branches = 1;
Expand All @@ -122,6 +125,7 @@ static void fixup_refs_wanted(void)
rw->want_detached = 1;
rw->want_other = 1;
rw->want_prefetch = 1;
rw->want_pull = 1;
return;
}

Expand All @@ -134,7 +138,8 @@ static void fixup_refs_wanted(void)
rw->want_remotes == -1 &&
rw->want_detached == -1 &&
rw->want_other == -1 &&
rw->want_prefetch == -1) {
rw->want_prefetch == -1 &&
rw->want_pull == -1) {
*rw = refs_if_unspecified;
return;
}
Expand All @@ -159,6 +164,8 @@ static void fixup_refs_wanted(void)
rw->want_other = 0;
if (rw->want_prefetch == -1)
rw->want_prefetch = 0;
if (rw->want_pull == -1)
rw->want_pull = 0;
}

static struct option survey_options[] = {
Expand All @@ -173,6 +180,7 @@ static struct option survey_options[] = {
OPT_BOOL_F(0, "detached", &survey_opts.refs.want_detached, N_("include detached HEAD"), PARSE_OPT_NONEG),
OPT_BOOL_F(0, "other", &survey_opts.refs.want_other, N_("include notes and stash"), PARSE_OPT_NONEG),
OPT_BOOL_F(0, "prefetch", &survey_opts.refs.want_prefetch, N_("include prefetch"), PARSE_OPT_NONEG),
OPT_BOOL_F(0, "pull", &survey_opts.refs.want_pull, N_("include pull"), PARSE_OPT_NONEG),

OPT_INTEGER_F(0, "commit-parents", &survey_opts.show_largest_commits_by_nr_parents, N_("show N largest commits by nr-parents"), PARSE_OPT_NONEG),
OPT_INTEGER_F(0, "commit-sizes", &survey_opts.show_largest_commits_by_size_bytes, N_("show N largest commits by size in bytes"), PARSE_OPT_NONEG),
Expand Down Expand Up @@ -240,6 +248,7 @@ struct survey_stats_refs {
uint32_t cnt_detached;
uint32_t cnt_other;
uint32_t cnt_prefetch;
uint32_t cnt_pull;

uint32_t cnt_symref;

Expand Down Expand Up @@ -578,6 +587,8 @@ static void do_load_refs(struct ref_array *ref_array)
}
if (survey_opts.refs.want_prefetch)
strvec_push(&survey_vec_refs_wanted, "refs/prefetch/");
if (survey_opts.refs.want_pull)
strvec_push(&survey_vec_refs_wanted, "refs/pull/");

filter.name_patterns = survey_vec_refs_wanted.v;
filter.ignore_case = 0;
Expand Down Expand Up @@ -880,6 +891,8 @@ static void do_calc_stats_refs(struct ref_array *ref_array)
case FILTER_REFS_OTHERS:
if (starts_with(p->refname, "refs/prefetch/"))
prs->cnt_prefetch++;
else if (starts_with(p->refname, "refs/pull/"))
prs->cnt_pull++;
else
prs->cnt_other++;
break;
Expand Down Expand Up @@ -1125,6 +1138,8 @@ static void survey_json(struct json_writer *jw, int pretty)
*/
if (survey_opts.refs.want_prefetch)
jw_object_intmax(jw, "prefetch", prs->cnt_prefetch);
if (survey_opts.refs.want_pull)
jw_object_intmax(jw, "pull", prs->cnt_pull);

/*
* SymRefs are somewhat orthogonal to
Expand Down

0 comments on commit 0710898

Please sign in to comment.