"git repo structure" computes a set of statistics that are useful for
diagnosing performance issues in a git repository. But for a typical
user who hasn't encountered any issues yet, it can be difficult to
interpret the data - when should a value be considered concerning?
This patchset introduces a feature to "git repo structure" that reports
on how concerning certain measures of storage structure are for a
repository. In table mode, concern is displayed as a column containing
a number of stars indicating the degree of concern; in line or nul mode,
concerns are displayed as additional lines with a numeric value. This
provides a functionality equivalent to the concern column provided
by "git-sizer", although the implementation is different.
To select defaults for the thresholds where a value becomes concern,
a (hopefully) representative selection of repositories were analyzed.
Based on empirical exploration of the data, the measurement that seemed
closest to accurately assessing when a repository's structure becomes
concerning was based on the base 2 logarithm of the value. Across all of
the sample repositories, for all of the measurements, the point at which
things become concerning was when a base 2 logarithm of a statistic's
value was more than 1 standard deviation from the mean of the log_2
values of that stastistic in the sample set. Based on this, the concern
threshold was set for each of the measures.
While this seems like a reasonable approach for setting default
thresholds, it's obviously still very ad-hoc. It's likely that over
time, the default values will evolve; and in any case, some projects
will want to set their own thresholds. To allow that, this includes
support for configuring the thresholds on a per-repository basis.
Overview of the change:
* The first commit adds the command-line option "--concern", and creates the basic implementation of concern reporting.
* The next commit adds configurability for the concern thresholds.
Signed-off-by: Mark C. Chu-Carroll <mark…@fastmail.com>
---
Changes in v6:
- Revamp the data structures used for configurable concern
levels in accord with review comments.
- Uniformly use size_t for concern values.
- Link to v5: https://patch.msgid.link/2026…@fastmail.com
Changes in v5:
- whitespace fixes
- change configuration values to make them more intuitive.
- fix cut-and-paste error
- fix location-of-deallocation error of strbuf in table generation
- removed invalid concern for tag-refs.
- fix integer typing in concern computation and table generation.
- Link to v4: https://patch.msgid.link/2026…@fastmail.com
Changes in v4:
- Reworked the history; the previous round had a history-rewrite error.
- Removed the duplication of configuration keys for the concern thresholds.
- Changed the prefix of the config keys.
- readability/quality of life naming changes.
- Link to v3: https://patch.msgid.link/2026…@fastmail.com
Changes in v3:
- Merge the documentation commit backwards into the other two commits.
- Link to v2: https://patch.msgid.link/2026…@fastmail.com
Changes in v2:
- Fix memory leak in concern string generation.
- Fix CI/CD test issue involving zlib versions.
- Updating the naming of the config value prefix.
- Link to v1: https://patch.msgid.link/2026…@fastmail.com
To: g…@vger.kernel.org
---
Mark C. Chu-Carroll (2):
repo: add level of concern reporting
repo: make concern thresholds configurable
Documentation/config.adoc | 2 +
Documentation/config/repo.adoc | 65 ++++++
Documentation/git-repo.adoc | 26 ++-
builtin/repo.c | 449 +++++++++++++++++++++++++++++++++++++++--
t/t1901-repo-structure.sh | 161 +++++++++++++++
5 files changed, 682 insertions(+), 21 deletions(-)
Range-diff versus v5:
1: fd88e8f4c6 ! 1: e596991a4c repo: add level of concern reporting
@@ Documentation/git-repo.adoc: supported:
`-z` is an alias for `--format=nul`.
++
+To make it easier to know when one of the values is something that
-+users should be concerned about, adding '--concern' will provide a
-+level of concern to be added to the output. In 'table' mode, this will
++users should be concerned about, adding `--concern` will provide a
++level of concern to be added to the output. In `table` mode, this will
+be a table column indicating the level of concern as a number of stars;
+in `lines` or `nul` mode, a `concern_level` line will be added for each
+statistic with a numeric value.
@@ Documentation/git-repo.adoc: supported:
## builtin/repo.c ##
@@
- #define USE_THE_REPOSITORY_VARIABLE
-
-+#include "git-compat-util.h"
- #include "builtin.h"
- #include "commit.h"
-+#include "config.h"
- #include "environment.h"
- #include "hash.h"
- #include "hex.h"
-@@
- #include "tree.h"
- #include "tree-walk.h"
- #include "utf8.h"
-+#include "wrapper.h"
-
- #define REPO_INFO_USAGE \
- "git repo info [--format=(lines|nul) | -z] [--all | <key>...]", \
"git repo info --keys [--format=(lines|nul) | -z]"
#define REPO_STRUCTURE_USAGE \
- "git repo structure [--format=(table|lines|nul) | -z]"
+ "git repo structure [--format=(table|lines|nul) | -z] [--[no-]concern]"
-+
-+#define REPO_STRUCTURE_CONFIG_PREFIX "repo.concern."
static const char *const repo_usage[] = {
REPO_INFO_USAGE,
@@ builtin/repo.c: struct stats_table {
int value_col_width;
int unit_col_width;
+ size_t max_concern_value;
-+};
-+
+ };
+
+/*
+ * For computing level of concern about a stat, we need to have some
+ * baseline values. For each of these, we define a minimum level
@@ builtin/repo.c: struct stats_table {
+ * value and standard deviation (sigma) for each statistic over the collection.
+ * The threshold for each metric is then set at mean(log_2) + sigma.
+ */
-+struct concern_stat_threshold {
-+ const char *name;
-+ size_t threshold;
- };
-
-+#define CONCERN_STAT_COMMIT_COUNT "commit-count"
-+#define CONCERN_STAT_TREE_COUNT "tree-count"
-+#define CONCERN_STAT_BLOB_COUNT "blob-count"
-+#define CONCERN_STAT_TAG_COUNT "tag-count"
-+#define CONCERN_STAT_COMMIT_SIZE "commit-size"
-+#define CONCERN_STAT_TREE_SIZE "tree-size"
-+#define CONCERN_STAT_BLOB_SIZE "blob-size"
-+#define CONCERN_STAT_TAG_SIZE "tag-size"
-+#define CONCERN_STAT_COMMIT_LARGEST "commit-largest"
-+#define CONCERN_STAT_TREE_LARGEST "tree-largest"
-+#define CONCERN_STAT_BLOB_LARGEST "blob-largest"
-+#define CONCERN_STAT_TAG_LARGEST "tag-largest"
-+#define CONCERN_STAT_COMMIT_INFLATED_SIZE "commit-inflated-size"
-+#define CONCERN_STAT_TREE_INFLATED_SIZE "tree-inflated-size"
-+#define CONCERN_STAT_BLOB_INFLATED_SIZE "blob-inflated-size"
-+#define CONCERN_STAT_TAG_INFLATED_SIZE "tag-inflated-size"
++enum concern_stat {
++ CONCERN_STAT_COMMIT_COUNT = 0,
++ CONCERN_STAT_TREE_COUNT,
++ CONCERN_STAT_BLOB_COUNT,
++ CONCERN_STAT_TAG_COUNT,
++ CONCERN_STAT_COMMIT_SIZE,
++ CONCERN_STAT_TREE_SIZE,
++ CONCERN_STAT_BLOB_SIZE,
++ CONCERN_STAT_TAG_SIZE,
++ CONCERN_STAT_COMMIT_LARGEST,
++ CONCERN_STAT_TREE_LARGEST,
++ CONCERN_STAT_BLOB_LARGEST,
++ CONCERN_STAT_TAG_LARGEST,
++ CONCERN_STAT_COMMIT_INFLATED_SIZE,
++ CONCERN_STAT_TREE_INFLATED_SIZE,
++ CONCERN_STAT_BLOB_INFLATED_SIZE,
++ CONCERN_STAT_TAG_INFLATED_SIZE,
++ CONCERN_STAT_NR
++};
+
-+static struct concern_stat_threshold repo_structure_concern_thresholds[] = {
-+ { .name = CONCERN_STAT_COMMIT_COUNT, .threshold = 19 },
-+ { .name = CONCERN_STAT_TREE_COUNT, .threshold = 21 },
-+ { .name = CONCERN_STAT_BLOB_COUNT, .threshold = 22 },
-+ { .name = CONCERN_STAT_TAG_COUNT, .threshold = 15 },
-+ { .name = CONCERN_STAT_COMMIT_SIZE, .threshold = 28 },
-+ { .name = CONCERN_STAT_TREE_SIZE, .threshold = 27 },
-+ { .name = CONCERN_STAT_BLOB_SIZE, .threshold = 36 },
-+ { .name = CONCERN_STAT_TAG_SIZE, .threshold = 18 },
-+ { .name = CONCERN_STAT_COMMIT_LARGEST, .threshold = 18 },
-+ { .name = CONCERN_STAT_TREE_LARGEST, .threshold = 18 },
-+ { .name = CONCERN_STAT_BLOB_LARGEST, .threshold = 26 },
-+ { .name = CONCERN_STAT_TAG_LARGEST, .threshold = 15 },
-+ { .name = CONCERN_STAT_COMMIT_INFLATED_SIZE, .threshold = 28 },
-+ { .name = CONCERN_STAT_TREE_INFLATED_SIZE, .threshold = 32 },
-+ { .name = CONCERN_STAT_BLOB_INFLATED_SIZE, .threshold = 34 },
-+ { .name = CONCERN_STAT_TAG_INFLATED_SIZE, .threshold = 25 },
-+ { 0 }
++static size_t concern_thresholds[CONCERN_STAT_NR] = {
++ [CONCERN_STAT_COMMIT_COUNT] = 19,
++ [CONCERN_STAT_TREE_COUNT] = 21,
++ [CONCERN_STAT_BLOB_COUNT] = 22,
++ [CONCERN_STAT_TAG_COUNT] = 15,
++ [CONCERN_STAT_COMMIT_SIZE] = 28,
++ [CONCERN_STAT_TREE_SIZE] = 27,
++ [CONCERN_STAT_BLOB_SIZE] = 36,
++ [CONCERN_STAT_TAG_SIZE] = 18,
++ [CONCERN_STAT_COMMIT_LARGEST] = 18,
++ [CONCERN_STAT_TREE_LARGEST] = 18,
++ [CONCERN_STAT_BLOB_LARGEST] = 26,
++ [CONCERN_STAT_TAG_LARGEST] = 15,
++ [CONCERN_STAT_COMMIT_INFLATED_SIZE] = 28,
++ [CONCERN_STAT_TREE_INFLATED_SIZE] = 32,
++ [CONCERN_STAT_BLOB_INFLATED_SIZE] = 34,
++ [CONCERN_STAT_TAG_INFLATED_SIZE] = 25,
+};
+
-+static int get_concern_threshold(const char *name, struct concern_stat_threshold *thresholds)
++static size_t repo_structure_concern_level(enum concern_stat stat,
++ size_t value,
++ const size_t *thresholds,
++ bool show_concern)
+{
-+ for (size_t i = 0; thresholds[i].name; i++) {
-+ if (!strcmp(thresholds[i].name, name))
-+ return thresholds[i].threshold;
-+ }
-+ return -1;
-+}
++ size_t log_value;
+
-+static int repo_structure_concern_level(const char *concern_name,
-+ size_t value,
-+ struct concern_stat_threshold *thresholds,
-+ bool show_concern)
-+{
-+ if (show_concern) {
-+ size_t log_value;
-+ const int threshold = get_concern_threshold(concern_name, thresholds);
-+ if (threshold < 0)
-+ BUG("unexpected repository stat threshold: '%s'", concern_name);
-+ log_value = (size_t)log2u(value);
-+ if (log_value > (size_t)threshold)
-+ return log_value - threshold;
-+ else
-+ return 0;
-+ } else {
++ if (!show_concern)
+ return 0;
-+ }
++
++ log_value = log2u(value);
++ if (log_value > thresholds[stat])
++ return log_value - thresholds[stat];
++ return 0;
+}
+
/*
@@ builtin/repo.c: static void stats_table_setup_structure(struct stats_table *tabl
- stats_table_count_addf(table, refs->tags, " * %s", _("Tags"));
- stats_table_count_addf(table, refs->remotes, " * %s", _("Remotes"));
- stats_table_count_addf(table, refs->others, " * %s", _("Others"));
--
+ stats_table_count_addf(table, ref_total, CONCERN_STAT_VALUE_NONE,
+ " * %s", _("Count"));
+ stats_table_count_addf(table, refs->branches, CONCERN_STAT_VALUE_NONE,
+ " * %s", _("Branches"));
-+ stats_table_count_addf(table, refs->tags,
-+ CONCERN_STAT_VALUE_NONE,
++ stats_table_count_addf(table, refs->tags, CONCERN_STAT_VALUE_NONE,
+ " * %s", _("Tags"));
+ stats_table_count_addf(table, refs->remotes, CONCERN_STAT_VALUE_NONE,
+ " * %s", _("Remotes"));
+ stats_table_count_addf(table, refs->others, CONCERN_STAT_VALUE_NONE,
+ " * %s", _("Others"));
+
object_count_total = get_total_object_values(&objects->type_counts);
stats_table_addf(table, "");
stats_table_addf(table, "* %s", _("Reachable objects"));
@@ builtin/repo.c: static void stats_table_setup_structure(struct stats_table *tabl
+ repo_structure_concern_level(
+ CONCERN_STAT_COMMIT_COUNT,
+ objects->type_counts.commits,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
" * %s", _("Commits"));
stats_table_count_addf(table, objects->type_counts.trees,
+ repo_structure_concern_level(
+ CONCERN_STAT_TREE_COUNT,
+ objects->type_counts.trees,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
" * %s", _("Trees"));
stats_table_count_addf(table, objects->type_counts.blobs,
+ repo_structure_concern_level(
+ CONCERN_STAT_BLOB_COUNT,
+ objects->type_counts.blobs,
-+ repo_structure_concern_thresholds,
-+ show_concern),
++ concern_thresholds,
++ show_concern),
" * %s", _("Blobs"));
stats_table_count_addf(table, objects->type_counts.tags,
+ repo_structure_concern_level(
+ CONCERN_STAT_TAG_COUNT,
+ objects->type_counts.tags,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
" * %s", _("Tags"));
@@ builtin/repo.c: static void stats_table_setup_structure(struct stats_table *tabl
+ repo_structure_concern_level(
+ CONCERN_STAT_COMMIT_INFLATED_SIZE,
+ objects->inflated_sizes.commits,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
" * %s", _("Commits"));
stats_table_size_addf(table, objects->inflated_sizes.trees,
+ repo_structure_concern_level(
+ CONCERN_STAT_TREE_INFLATED_SIZE,
+ objects->inflated_sizes.trees,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
" * %s", _("Trees"));
stats_table_size_addf(table, objects->inflated_sizes.blobs,
+ repo_structure_concern_level(
+ CONCERN_STAT_BLOB_INFLATED_SIZE,
+ objects->inflated_sizes.blobs,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
" * %s", _("Blobs"));
stats_table_size_addf(table, objects->inflated_sizes.tags,
+ repo_structure_concern_level(
+ CONCERN_STAT_TAG_INFLATED_SIZE,
+ objects->inflated_sizes.tags,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
" * %s", _("Tags"));
@@ builtin/repo.c: static void stats_table_setup_structure(struct stats_table *tabl
+ repo_structure_concern_level(
+ CONCERN_STAT_COMMIT_SIZE,
+ objects->disk_sizes.commits,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
" * %s", _("Commits"));
stats_table_size_addf(table, objects->disk_sizes.trees,
+ repo_structure_concern_level(
+ CONCERN_STAT_TREE_SIZE,
+ objects->disk_sizes.trees,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
" * %s", _("Trees"));
stats_table_size_addf(table, objects->disk_sizes.blobs,
+ repo_structure_concern_level(
+ CONCERN_STAT_BLOB_SIZE,
+ objects->disk_sizes.blobs,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
" * %s", _("Blobs"));
stats_table_size_addf(table, objects->disk_sizes.tags,
+ repo_structure_concern_level(
+ CONCERN_STAT_TAG_SIZE,
+ objects->disk_sizes.tags,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
" * %s", _("Tags"));
@@ builtin/repo.c: static void stats_table_setup_structure(struct stats_table *tabl
+ repo_structure_concern_level(
+ CONCERN_STAT_COMMIT_LARGEST,
+ objects->largest.commit_size.value,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
" * %s", _("Maximum size"));
stats_table_object_count_addf(table,
@@ builtin/repo.c: static void stats_table_setup_structure(struct stats_table *tabl
+ repo_structure_concern_level(
+ CONCERN_STAT_TREE_LARGEST,
+ objects->largest.tree_size.value,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
" * %s", _("Maximum size"));
-+
stats_table_object_count_addf(table,
-- &objects->largest.tree_entries.oid,
-- objects->largest.tree_entries.value,
-- " * %s", _("Maximum entries"));
-+ &objects->largest.tree_entries.oid,
-+ objects->largest.tree_entries.value,
-+ CONCERN_STAT_VALUE_NONE,
-+ " * %s", _("Maximum entries"));
+ &objects->largest.tree_entries.oid,
+ objects->largest.tree_entries.value,
++ CONCERN_STAT_VALUE_NONE,
+ " * %s", _("Maximum entries"));
stats_table_addf(table, " * %s", _("Blobs"));
stats_table_object_size_addf(table,
&objects->largest.blob_size.oid,
@@ builtin/repo.c: static void stats_table_setup_structure(struct stats_table *tabl
+ repo_structure_concern_level(
+ CONCERN_STAT_BLOB_LARGEST,
+ objects->largest.blob_size.value,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
" * %s", _("Maximum size"));
stats_table_addf(table, " * %s", _("Tags"));
@@ builtin/repo.c: static void stats_table_setup_structure(struct stats_table *tabl
+ repo_structure_concern_level(
+ CONCERN_STAT_TAG_LARGEST,
+ objects->largest.tag_size.value,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
" * %s", _("Maximum size"));
}
@@ builtin/repo.c: static void stats_table_print_structure(const struct stats_table
int value_col_width = table->value_col_width;
int unit_col_width = table->unit_col_width;
+ const char *concern_col_title = _("Concern");
-+ const size_t concern_title_width = strlen(concern_col_title);
-+ size_t concern_col_width = (table->max_concern_value > concern_title_width) ? table->max_concern_value : concern_title_width;
++ size_t concern_col_width = utf8_strwidth(concern_col_title);
struct string_list_item *item;
struct strbuf buf = STRBUF_INIT;
+ struct strbuf concern_str = STRBUF_INIT;
@@ builtin/repo.c: static void stats_table_print_structure(const struct stats_table
name_col_width = title_name_width;
if (title_value_width > value_col_width + unit_col_width + 1)
value_col_width = title_value_width - unit_col_width;
--
++ if (table->max_concern_value > concern_col_width)
++ concern_col_width = table->max_concern_value;
+
strbuf_addstr(&buf, "| ");
strbuf_utf8_align(&buf, ALIGN_LEFT, name_col_width + INDEX_WIDTH,
- name_col_title);
@@ builtin/repo.c: static void stats_table_print_structure(const struct stats_table *table)
strbuf_utf8_align(&buf, ALIGN_LEFT,
value_col_width + unit_col_width + 1, value_col_title);
@@ builtin/repo.c: static void stats_table_print_structure(const struct stats_table
+ if (show_concern) {
+ strbuf_addch(&buf, ' ');
+ strbuf_utf8_align(&buf, ALIGN_LEFT, concern_col_width,
-+ concern_col_title);
++ concern_col_title);
+ strbuf_addstr(&buf, " |");
+ }
printf("%s\n", buf.buf);
@@ builtin/repo.c: static void stats_table_print_structure(const struct stats_table
+ printf(" |");
+ if (show_concern) {
+ putchar(' ');
-+ for (size_t i = 0; i < concern_col_width; i++) {
++ for (size_t i = 0; i < concern_col_width; i++)
+ putchar('-');
-+ }
+ printf(" |");
+ }
+ putchar('\n');
@@ builtin/repo.c: static void stats_table_print_structure(const struct stats_table
strbuf_addstr(&buf, " |");
+ if (show_concern) {
+ strbuf_addch(&buf, ' ');
-+ strbuf_utf8_align(&buf, ALIGN_LEFT, concern_col_width, concern_str.buf);
++ strbuf_utf8_align(&buf, ALIGN_LEFT, concern_col_width,
++ concern_str.buf);
+ strbuf_addstr(&buf, " |");
+ }
printf("%s\n", buf.buf);
}
@@ builtin/repo.c: static void stats_table_print_structure(const struct stats_table *table)
- for_each_string_list_item(item, &table->annotations)
printf("%s\n", item->string);
}
--
+
+ strbuf_release(&concern_str);
strbuf_release(&buf);
}
@@ builtin/repo.c: static void print_object_data(const char *key, char key_delim,
print_keyvalue("references.branches.count", key_delim,
stats->refs.branches, value_delim);
@@ builtin/repo.c: static void structure_keyvalue_print(struct repo_structure *stats,
- stats->refs.remotes, value_delim);
- print_keyvalue("references.others.count", key_delim,
- stats->refs.others, value_delim);
--
+
print_keyvalue("objects.commits.count", key_delim,
stats->objects.type_counts.commits, value_delim);
+ if (show_concern)
@@ builtin/repo.c: static void structure_keyvalue_print(struct repo_structure *stat
+ repo_structure_concern_level(
+ CONCERN_STAT_COMMIT_COUNT,
+ stats->objects.type_counts.commits,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
+ value_delim);
print_keyvalue("objects.trees.count", key_delim,
@@ builtin/repo.c: static void structure_keyvalue_print(struct repo_structure *stat
+ repo_structure_concern_level(
+ CONCERN_STAT_TREE_COUNT,
+ stats->objects.type_counts.trees,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
+ value_delim);
print_keyvalue("objects.blobs.count", key_delim,
@@ builtin/repo.c: static void structure_keyvalue_print(struct repo_structure *stat
+ repo_structure_concern_level(
+ CONCERN_STAT_BLOB_COUNT,
+ stats->objects.type_counts.blobs,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
-+ value_delim);
++ value_delim);
print_keyvalue("objects.tags.count", key_delim,
-- stats->objects.type_counts.tags, value_delim);
--
-+ stats->objects.type_counts.tags, value_delim);
+ stats->objects.type_counts.tags, value_delim);
+ if (show_concern)
+ print_keyvalue("objects.tags.count.concern_level", key_delim,
+ repo_structure_concern_level(
+ CONCERN_STAT_TAG_COUNT,
+ stats->objects.type_counts.tags,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
+ value_delim);
+
print_keyvalue("objects.commits.inflated_size", key_delim,
-- stats->objects.inflated_sizes.commits, value_delim);
-+ stats->objects.inflated_sizes.commits, value_delim);
+ stats->objects.inflated_sizes.commits, value_delim);
+ if (show_concern)
+ print_keyvalue("objects.commits.inflated_size.concern_level", key_delim,
+ repo_structure_concern_level(
+ CONCERN_STAT_COMMIT_INFLATED_SIZE,
+ stats->objects.inflated_sizes.commits,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
+ value_delim);
print_keyvalue("objects.trees.inflated_size", key_delim,
-- stats->objects.inflated_sizes.trees, value_delim);
-+ stats->objects.inflated_sizes.trees, value_delim);
+ stats->objects.inflated_sizes.trees, value_delim);
+ if (show_concern)
+ print_keyvalue("objects.trees.inflated_size.concern_level", key_delim,
+ repo_structure_concern_level(
-+ CONCERN_STAT_TREE_INFLATED_SIZE,
-+ stats->objects.inflated_sizes.trees,
-+ repo_structure_concern_thresholds,
-+ show_concern),
++ CONCERN_STAT_TREE_INFLATED_SIZE,
++ stats->objects.inflated_sizes.trees,
++ concern_thresholds,
++ show_concern),
+ value_delim);
print_keyvalue("objects.blobs.inflated_size", key_delim,
stats->objects.inflated_sizes.blobs, value_delim);
@@ builtin/repo.c: static void structure_keyvalue_print(struct repo_structure *stat
+ repo_structure_concern_level(
+ CONCERN_STAT_BLOB_INFLATED_SIZE,
+ stats->objects.inflated_sizes.blobs,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
+ value_delim);
print_keyvalue("objects.tags.inflated_size", key_delim,
stats->objects.inflated_sizes.tags, value_delim);
--
+ if (show_concern)
+ print_keyvalue("objects.tags.inflated_size.concern_level", key_delim,
+ repo_structure_concern_level(
+ CONCERN_STAT_TAG_INFLATED_SIZE,
+ stats->objects.inflated_sizes.tags,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
+ value_delim);
+
print_keyvalue("objects.commits.disk_size", key_delim,
stats->objects.disk_sizes.commits, value_delim);
+ if (show_concern)
@@ builtin/repo.c: static void structure_keyvalue_print(struct repo_structure *stat
+ repo_structure_concern_level(
+ CONCERN_STAT_COMMIT_SIZE,
+ stats->objects.disk_sizes.commits,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
+ value_delim);
print_keyvalue("objects.trees.disk_size", key_delim,
@@ builtin/repo.c: static void structure_keyvalue_print(struct repo_structure *stat
+ repo_structure_concern_level(
+ CONCERN_STAT_TREE_SIZE,
+ stats->objects.disk_sizes.trees,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
+ value_delim);
print_keyvalue("objects.blobs.disk_size", key_delim,
@@ builtin/repo.c: static void structure_keyvalue_print(struct repo_structure *stat
+ repo_structure_concern_level(
+ CONCERN_STAT_BLOB_SIZE,
+ stats->objects.disk_sizes.blobs,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
-+ value_delim);
++ value_delim);
print_keyvalue("objects.tags.disk_size", key_delim,
stats->objects.disk_sizes.tags, value_delim);
--
+ if (show_concern)
+ print_keyvalue("objects.tags.disk_size.concern_level", key_delim,
+ repo_structure_concern_level(
+ CONCERN_STAT_TAG_SIZE,
+ stats->objects.disk_sizes.tags,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
-+ value_delim);
++ value_delim);
+
print_object_data("objects.commits.max_size", key_delim,
&stats->objects.largest.commit_size, value_delim);
+ if (show_concern)
@@ builtin/repo.c: static void structure_keyvalue_print(struct repo_structure *stat
+ repo_structure_concern_level(
+ CONCERN_STAT_COMMIT_LARGEST,
+ stats->objects.largest.commit_size.value,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
+ value_delim);
print_object_data("objects.trees.max_size", key_delim,
@@ builtin/repo.c: static void structure_keyvalue_print(struct repo_structure *stat
+ repo_structure_concern_level(
+ CONCERN_STAT_TREE_LARGEST,
+ stats->objects.largest.tree_size.value,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
+ value_delim);
print_object_data("objects.blobs.max_size", key_delim,
@@ builtin/repo.c: static void structure_keyvalue_print(struct repo_structure *stat
+ repo_structure_concern_level(
+ CONCERN_STAT_BLOB_LARGEST,
+ stats->objects.largest.blob_size.value,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
+ value_delim);
print_object_data("objects.tags.max_size", key_delim,
-- &stats->objects.largest.tag_size, value_delim);
--
-+ &stats->objects.largest.tag_size, value_delim);
+ &stats->objects.largest.tag_size, value_delim);
+ if (show_concern)
+ print_keyvalue("objects.tags.max_size.concern_level", key_delim,
+ repo_structure_concern_level(
+ CONCERN_STAT_TAG_LARGEST,
+ stats->objects.largest.tag_size.value,
-+ repo_structure_concern_thresholds,
++ concern_thresholds,
+ show_concern),
+ value_delim);
+
print_object_data("objects.commits.max_parents", key_delim,
&stats->objects.largest.parent_count, value_delim);
- print_object_data("objects.trees.max_entries", key_delim,
- &stats->objects.largest.tree_entries, value_delim);
--
- fflush(stdout);
- }
-
@@ builtin/repo.c: static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
struct repo_structure stats = { 0 };
struct rev_info revs;
int show_progress = -1;
+ int show_concern = 0;
-+
struct option options[] = {
OPT_CALLBACK_F(0, "format", &format, N_("format"),
N_("output format"),
@@ builtin/repo.c: static int cmd_repo_structure(int argc, const char **argv, const
OPT_END()
};
- argc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);
- if (argc)
- usage(_("too many arguments"));
--
- repo_init_revisions(repo, &revs, prefix);
-
- if (show_progress < 0)
@@ builtin/repo.c: static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
switch (format) {
@@ builtin/repo.c: static int cmd_repo_structure(int argc, const char **argv, const
break;
default:
BUG("invalid output format");
-
- ## t/t1901-repo-structure.sh ##
-@@ t/t1901-repo-structure.sh: test_expect_success 'empty repository' '
- | * Tags | |
- | * Maximum size | 0 B |
- EOF
--
- git repo structure >out 2>err &&
-
- test_cmp expect out &&
2: 3ce7cfb04e ! 2: 44fa8e0e35 repo: make concern thresholds configurable
@@ Commit message
Signed-off-by: Mark C. Chu-Carroll <mark…@fastmail.com>
+ ## Documentation/config.adoc ##
+@@ Documentation/config.adoc: include::config/repack.adoc[]
+
+ include::config/replay.adoc[]
+
++include::config/repo.adoc[]
++
+ include::config/rerere.adoc[]
+
+ include::config/revert.adoc[]
+
## Documentation/config/repo.adoc (new) ##
@@
+`repo.concern.commit-count`::
@@ Documentation/config/repo.adoc (new)
+be set to 65536; if instead, the value from the configuration was set to
+100,000, the threshold will be set to 131,072.
+
++Setting a threshold to 0 disables concern reporting for the corresponding
++statistic.
## Documentation/git-repo.adoc ##
-@@ Documentation/git-repo.adoc: statistic value. The value is considered concerning if it exceeds a heuristicall
+@@ Documentation/git-repo.adoc: The level of concern for each statistic is computed using the log_2 of the
+ statistic value. The value is considered concerning if it exceeds a heuristically
chosen threshold value; the degree of concern is the difference between the
log_2 of the value, and the log_2 of the corresponding threshold.
+++
++The threshold values are configurable; see the CONFIGURATION section below.
-+The threshold values are configurable; see the configuration section below.
-+
INFO KEYS
---------
- In order to obtain a set of values from `git repo info`, you should provide
@@ Documentation/git-repo.adoc: using the `nul` format:
git repo info --format=nul layout.bare layout.shallow
------------
@@ Documentation/git-repo.adoc: using the `nul` format:
+
+:git-repo: 1
+include::config/repo.adoc[]
-+
+
SEE ALSO
--------
linkgit:git-rev-parse[1]
## builtin/repo.c ##
-@@ builtin/repo.c: static int repo_structure_concern_level(const char *concern_name,
- const int threshold = get_concern_threshold(concern_name, thresholds);
- if (threshold < 0)
- BUG("unexpected repository stat threshold: '%s'", concern_name);
-+ if (!threshold)
-+ return 0;
- log_value = (size_t)log2u(value);
- if (log_value > (size_t)threshold)
- return log_value - threshold;
-@@ builtin/repo.c: static int repo_structure_concern_level(const char *concern_name,
- }
+@@
+
+ #include "builtin.h"
+ #include "commit.h"
++#include "config.h"
+ #include "environment.h"
+ #include "hash.h"
+ #include "hex.h"
+@@
+ #define REPO_STRUCTURE_USAGE \
+ "git repo structure [--format=(table|lines|nul) | -z] [--[no-]concern]"
+
++static const char *rs_concern_prefix = "repo.concern.";
++
+ static const char *const repo_usage[] = {
+ REPO_INFO_USAGE,
+ REPO_STRUCTURE_USAGE,
+@@ builtin/repo.c: static size_t concern_thresholds[CONCERN_STAT_NR] = {
+ [CONCERN_STAT_TAG_INFLATED_SIZE] = 25,
+ };
+
++static const char *concern_stat_names[CONCERN_STAT_NR] = {
++ [CONCERN_STAT_COMMIT_COUNT] = "commit-count",
++ [CONCERN_STAT_TREE_COUNT] = "tree-count",
++ [CONCERN_STAT_BLOB_COUNT] = "blob-count",
++ [CONCERN_STAT_TAG_COUNT] = "tag-count",
++ [CONCERN_STAT_COMMIT_SIZE] = "commit-size",
++ [CONCERN_STAT_TREE_SIZE] = "tree-size",
++ [CONCERN_STAT_BLOB_SIZE] = "blob-size",
++ [CONCERN_STAT_TAG_SIZE] = "tag-size",
++ [CONCERN_STAT_COMMIT_LARGEST] = "commit-largest",
++ [CONCERN_STAT_TREE_LARGEST] = "tree-largest",
++ [CONCERN_STAT_BLOB_LARGEST] = "blob-largest",
++ [CONCERN_STAT_TAG_LARGEST] = "tag-largest",
++ [CONCERN_STAT_COMMIT_INFLATED_SIZE] = "commit-inflated-size",
++ [CONCERN_STAT_TREE_INFLATED_SIZE] = "tree-inflated-size",
++ [CONCERN_STAT_BLOB_INFLATED_SIZE] = "blob-inflated-size",
++ [CONCERN_STAT_TAG_INFLATED_SIZE] = "tag-inflated-size",
++};
++
+ static size_t repo_structure_concern_level(enum concern_stat stat,
+ size_t value,
+ const size_t *thresholds,
+@@ builtin/repo.c: static size_t repo_structure_concern_level(enum concern_stat stat,
+ return 0;
}
+/*
@@ builtin/repo.c: static int repo_structure_concern_level(const char *concern_name
+ * internal threshold value to the _nearest_ power of two to the value
+ * the user specified. So if they set a threshold to 500, we should use
+ * a log value of 9, but log2u would return 8.
-+ *
-+ * A threshold value of 0 means "never flag concerns for this stat".
+ */
+static size_t nearest_log2_value(size_t v)
+{
+ size_t logval, power_of_two_floor, mid;
++
+ if (!v)
+ return 0;
-+ logval = (size_t)log2u(v);
++ logval = log2u(v);
+ power_of_two_floor = (size_t)1 << logval;
-+ mid = (power_of_two_floor + (power_of_two_floor << 1)) / 2;
-+ return (v <= mid) ? logval : (logval + 1);
++ mid = power_of_two_floor + power_of_two_floor / 2;
++ return v <= mid ? logval : logval + 1;
+}
+
+/*
@@ builtin/repo.c: static int repo_structure_concern_level(const char *concern_name
+ * support that, they can set the thresholds for their project in the
+ * project's git config, in the section "repo.concern".
+ *
-+ * This is used by repo_config; the call site is guarded by show_concern,
-+ * so the global threshold array is only modified when --concern is requested,
-+ * and that will happen at most once.
++ * A configured threshold of 0 disables concern reporting for that stat.
+ */
-+static int config_concern_thresholds(const char *config_val_name,
-+ const char *str_val,
++static int config_concern_thresholds(const char *var, const char *value,
+ const struct config_context *ctx,
+ void *cb)
+{
-+ struct concern_stat_threshold *thresholds = cb;
-+ const char *concern_name;
-+ if (skip_prefix(config_val_name, REPO_STRUCTURE_CONFIG_PREFIX, &concern_name)) {
-+ for (int i = 0; thresholds[i].name; i++) {
-+ if (!strcmp(thresholds[i].name, concern_name)) {
-+ int threshold = git_config_int(concern_name, str_val, ctx->kvi);
-+ if (threshold < 0) {
-+ warning(_("invalid concern threshold '%d': value must be 0 or more"),
-+ threshold);
-+ return 0;
-+ }
-+ thresholds[i].threshold = nearest_log2_value(threshold);
-+ return 0;
-+ }
-+ }
-+ warning(_("invalid concern threshold name: '%s'"), concern_name);
++ size_t *thresholds = cb;
++ const char *name;
++
++ if (!skip_prefix(var, rs_concern_prefix, &name))
++ return 0;
++
++ for (size_t i = 0; i < CONCERN_STAT_NR; i++) {
++ size_t threshold;
++
++ if (strcmp(concern_stat_names[i], name))
++ continue;
++
++ threshold = git_config_size_t(var, value, ctx->kvi);
++ thresholds[i] = threshold ? nearest_log2_value(threshold) : SIZE_MAX;
++ return 0;
+ }
++
++ warning(_("invalid concern threshold name: '%s'"), name);
+ return 0;
+}
+
/*
* Holds column data that gets stored for each row.
*/
+@@ builtin/repo.c: static void stats_table_addf(struct stats_table *table, const char *format, ...)
+ * Define a symbol for 'no concern value for this stat'; this will
+ * make the code below easier to read.
+ */
+-#define CONCERN_STAT_VALUE_NONE 0
++static const size_t CONCERN_STAT_VALUE_NONE = 0;
+
+ static void stats_table_count_addf(struct stats_table *table, size_t value,
+ size_t concern, const char *format, ...)
@@ builtin/repo.c: static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
- usage(_("too many arguments"));
+
repo_init_revisions(repo, &revs, prefix);
+ if (show_concern)
-+ repo_config(repo, &config_concern_thresholds,
-+ &repo_structure_concern_thresholds);
++ repo_config(repo, config_concern_thresholds,
++ concern_thresholds);
+
if (show_progress < 0)
show_progress = isatty(2);
@@ t/t1901-repo-structure.sh: test_expect_success SHA1 'repository with references
+ # Also creates a commit, tree, and blob.
+ git notes add -m foo &&
+
-+
+ # The tags disk size is handled specially due to the
+ # git-rev-list(1) --disk-usage=human option printing the full
+ # "byte/bytes" unit string instead of just "B".
@@ t/t1901-repo-structure.sh: test_expect_success SHA1 'lines and nul format' '
+ git config repo.concern.tag-size 4 &&
+ git config repo.concern.commit-largest 16 &&
+ git config repo.concern.blob-largest 4 &&
-+ touch configured &&
+ test_commit_bulk 1005 &&
+ git tag -a foo -m bar &&
+ oid="$(git rev-parse HEAD)" &&
@@ t/t1901-repo-structure.sh: test_expect_success SHA1 'lines and nul format' '
+ # Also creates a commit, tree, and blob.
+ git notes add -m foo &&
+
-+
+ # The tags disk size is handled specially due to the
+ # git-rev-list(1) --disk-usage=human option printing the full
+ # "byte/bytes" unit string instead of just "B".
@@ t/t1901-repo-structure.sh: test_expect_success SHA1 'lines and nul format' '
+ test_line_count = 0 err
+ )
+'
++
++test_expect_success 'concern threshold of 0 disables concern' '
++ test_when_finished "rm -rf repo" &&
++ git init repo &&
++ (
++ cd repo &&
++ test_commit_bulk 10 &&
++ git config repo.concern.commit-count 2 &&
++ git repo structure --concern --format=lines >actual 2>err &&
++ test_grep "^objects.commits.count.concern_level=2$" actual &&
++ git config repo.concern.commit-count 0 &&
++ git repo structure --concern --format=lines >actual 2>err &&
++ test_grep "^objects.commits.count.concern_level=0$" actual &&
++ test_line_count = 0 err
++ )
++'
++
++test_expect_success 'unknown concern threshold name warns' '
++ test_when_finished "rm -rf repo" &&
++ git init repo &&
++ (
++ cd repo &&
++ git config repo.concern.no-such-stat 5 &&
++ git repo structure --concern --format=lines >actual 2>err &&
++ test_grep "invalid concern threshold name: .no-such-stat." err
++ )
++'
+
test_expect_success 'progress meter option' '
test_when_finished "rm -rf repo" &&
---
base-commit: 3bc0341126508f78f5869cbfc0005e987efdf0c7
change-id: 20261019-b4-repo-structure-concern-f1d6f6326095
[PATCH v6 0/2] repo: add degree-of-concern reporting to structure
- From
- mark…@fastmail.com ("Mark C. Chu-Carroll")
- Organization
- Usenet Network
- Message-ID
- <2026…@fastmail.com>
- Date
- Newsgroups
- linux.kernel.git