The concern reporting mechanism so far provides a
measure of concern based on heuristic values estimated
by analyzing a collection of (hopefully) representative
repositories. But for different projects/usecases, the
thresholds at which a value becomes concerning may vary.
Provide a mechanism using git config to allow users to
configure per-repo concern levels for "git repo structure"
concern reporting.
Signed-off-by: Mark C. Chu-Carroll <mark…@fastmail.com>
---
Documentation/config.adoc | 2 +
Documentation/config/repo.adoc | 65 +++++++++++++++++
Documentation/git-repo.adoc | 10 +++
builtin/repo.c | 79 +++++++++++++++++++-
t/t1901-repo-structure.sh | 161 +++++++++++++++++++++++++++++++++++++++++
5 files changed, 316 insertions(+), 1 deletion(-)
diff --git a/Documentation/config.adoc b/Documentation/config.adoc
index f67dcd2f8e..2652cafa41 100644
--- a/Documentation/config.adoc
+++ b/Documentation/config.adoc
@@ -570,6 +570,8 @@ include::config/repack.adoc[]
include::config/replay.adoc[]
+include::config/repo.adoc[]
+
include::config/rerere.adoc[]
include::config/revert.adoc[]
diff --git a/Documentation/config/repo.adoc b/Documentation/config/repo.adoc
new file mode 100644
index 0000000000..dd38a59561
--- /dev/null
+++ b/Documentation/config/repo.adoc
@@ -0,0 +1,65 @@
+`repo.concern.commit-count`::
+ Sets the value of the concern threshold for commit count.
+
+`repo.concern.tree-count`::
+ Sets the value of the concern threshold for tree count.
+
+`repo.concern.blob-count`::
+ Sets the value of the concern threshold for blob count.
+
+`repo.concern.tag-count`::
+ Sets the value of the concern threshold for tag count.
+
+`repo.concern.commit-size`::
+ Sets the value of the concern threshold for total commit size.
+
+`repo.concern.tree-size`::
+ Sets the value of the concern threshold for total tree size.
+
+`repo.concern.blob-size`::
+ Sets the value of the concern threshold for total blob size.
+
+`repo.concern.tag-size`::
+ Sets the value of the concern threshold for total tag size.
+
+`repo.concern.commit-inflated-size`::
+ Sets the value of the concern threshold for total size
+ of all inflated commits.
+
+`repo.concern.tree-inflated-size`::
+ Sets the value of the concern threshold for total size of
+ all inflated trees.
+
+`repo.concern.blob-inflated-size`::
+ Sets the value of the concern threshold for total size of
+ all inflated blobs.
+
+`repo.concern.tag-inflated-size`::
+ Sets the value of the concern threshold for the total size
+ of all inflated tags.
+
+`repo.concern.commit-largest`::
+ Sets the value of the concern threshold for the size of the largest
+ commit.
+
+`repo.concern.tree-largest`::
+ Sets the value of the concern threshold for the size of the
+ largest tree.
+
+`repo.concern.blob-largest`::
+ Sets the value of the concern threshold for the size of the
+ largest blob.
+
+`repo.concern.tag-largest`::
+ Sets the value of the concern threshold for the size of the
+ largest tag.
+
+Thresholds are actually computed using log values. But for human convenience,
+they're set as integer values. If the integer value supplied isn't a power of
+two, the actual value will be rounded to the nearest power of two. For example,
+if the value in the configuration setting is 80,000, the actual threshold will
+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.
diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index dd756309cd..7ada6a5c72 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -100,6 +100,8 @@ 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.
INFO KEYS
---------
@@ -153,6 +155,14 @@ using the `nul` format:
git repo info --format=nul layout.bare layout.shallow
------------
+CONFIGURATION
+-------------
+
+include::includes/cmd-config-section-all.adoc[]
+
+:git-repo: 1
+include::config/repo.adoc[]
+
SEE ALSO
--------
linkgit:git-rev-parse[1]
diff --git a/builtin/repo.c b/builtin/repo.c
index 699be6a3de..5f1d389c1d 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -2,6 +2,7 @@
#include "builtin.h"
#include "commit.h"
+#include "config.h"
#include "environment.h"
#include "hash.h"
#include "hex.h"
@@ -29,6 +30,8 @@
#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,
@@ -403,6 +406,25 @@ 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,
@@ -419,6 +441,57 @@ static size_t repo_structure_concern_level(enum concern_stat stat,
return 0;
}
+/*
+ * To make configuring thresholds as intuitive as possible, we set the
+ * 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.
+ */
+static size_t nearest_log2_value(size_t v)
+{
+ size_t logval, power_of_two_floor, mid;
+
+ if (!v)
+ return 0;
+ logval = log2u(v);
+ power_of_two_floor = (size_t)1 << logval;
+ mid = power_of_two_floor + power_of_two_floor / 2;
+ return v <= mid ? logval : logval + 1;
+}
+
+/*
+ * Concern thresholds aren't universal. We try to set reasonable default
+ * values, but projects may want to set these thresholds differently. To
+ * support that, they can set the thresholds for their project in the
+ * project's git config, in the section "repo.concern".
+ *
+ * A configured threshold of 0 disables concern reporting for that stat.
+ */
+static int config_concern_thresholds(const char *var, const char *value,
+ const struct config_context *ctx,
+ void *cb)
+{
+ 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.
*/
@@ -486,7 +559,7 @@ 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, ...)
@@ -1287,6 +1360,10 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
repo_init_revisions(repo, &revs, prefix);
+ if (show_concern)
+ repo_config(repo, config_concern_thresholds,
+ concern_thresholds);
+
if (show_progress < 0)
show_progress = isatty(2);
diff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh
index 02cc2b594a..bc440fa1db 100755
--- a/t/t1901-repo-structure.sh
+++ b/t/t1901-repo-structure.sh
@@ -144,6 +144,88 @@ test_expect_success SHA1 'repository with references and objects' '
)
'
+test_expect_success SHA1 'concern flagging' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ # differences between zlib and zlib-ng can cause this
+ # test to fail; so we just turn it off.
+ git config core.compression 0 &&
+ # configure thresholds to get concern indications
+ git config repo.concern.commit-count 120 &&
+ git config repo.concern.commit-size 16384 &&
+ git config repo.concern.tree-size 1024 &&
+ git config repo.concern.blob-size 256 &&
+ git config repo.concern.blob-inflated-size 1024 &&
+ git config repo.concern.tag-size 4 &&
+ git config repo.concern.commit-largest 16 &&
+ git config repo.concern.blob-largest 4 &&
+ test_commit_bulk 1005 &&
+ git tag -a foo -m bar &&
+ oid="$(git rev-parse HEAD)" &&
+ git update-ref refs/remotes/origin/foo "$oid" &&
+
+ # 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".
+ cat >expect <<-EOF &&
+ | Repository structure | Value | Concern |
+ | ------------------------- | ---------- | -------- |
+ | * References | | |
+ | * Count | 4 | |
+ | * Branches | 1 | |
+ | * Tags | 1 | |
+ | * Remotes | 1 | |
+ | * Others | 1 | |
+ | | | |
+ | * Reachable objects | | |
+ | * Count | 3.02 k | |
+ | * Commits | 1.01 k | ** |
+ | * Trees | 1.01 k | |
+ | * Blobs | 1.01 k | |
+ | * Tags | 1 | |
+ | * Inflated size | 16.03 MiB | |
+ | * Commits | 217.92 KiB | |
+ | * Trees | 15.81 MiB | |
+ | * Blobs | 11.68 KiB | *** |
+ | * Tags | 132 B | |
+ | * Disk size | $(object_type_disk_usage all true) | |
+ | * Commits | $(object_type_disk_usage commit true) | *** |
+ | * Trees | $(object_type_disk_usage tree true) | ******** |
+ | * Blobs | $(object_type_disk_usage blob true) | ****** |
+ | * Tags | $(object_type_disk_usage tag) B | ***** |
+ | | | |
+ | * Largest objects | | |
+ | * Commits | | |
+ | * Maximum size [1] | 223 B | *** |
+ | * Maximum parents [2] | 1 | |
+ | * Trees | | |
+ | * Maximum size [3] | 32.29 KiB | |
+ | * Maximum entries [4] | 1.01 k | |
+ | * Blobs | | |
+ | * Maximum size [5] | 13 B | * |
+ | * Tags | | |
+ | * Maximum size [6] | 132 B | |
+
+ [1] 0dc91eb18580102a3a216c8bfecedeba2b9f9b9a
+ [2] 0dc91eb18580102a3a216c8bfecedeba2b9f9b9a
+ [3] 60665251ab71dbd8c18d9bf2174f4ee0d58aa06c
+ [4] 60665251ab71dbd8c18d9bf2174f4ee0d58aa06c
+ [5] 97d808e45116bf02103490294d3d46dad7a2ac62
+ [6] 4dae4f5954f5e6feb3577cfb1b181daa3fd3afd2
+ EOF
+
+ git repo structure --concern >actual 2>err &&
+
+ test_cmp expect actual &&
+ test_line_count = 0 err
+ )
+'
+
test_expect_success SHA1 'lines and nul format' '
test_when_finished "rm -rf repo" &&
git init repo &&
@@ -204,6 +286,85 @@ test_expect_success SHA1 'lines and nul format' '
)
'
+test_expect_success SHA1 'lines format with concerns' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ # configure thresholds to get concern indications
+ git config core.compression 0 &&
+ git config repo.concern.commit-count 100 &&
+ git config repo.concern.commit-size 16384 &&
+ git config repo.concern.tree-size 1024 &&
+ git config repo.concern.blob-size 256 &&
+ git config repo.concern.blob-inflated-size 1024 &&
+ git config repo.concern.tag-size 4 &&
+ git config repo.concern.commit-largest 16 &&
+ git config repo.concern.blob-largest 4 &&
+ test_commit_bulk 1005 &&
+ git tag -a foo -m bar &&
+ oid="$(git rev-parse HEAD)" &&
+ git update-ref refs/remotes/origin/foo "$oid" &&
+
+ # 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".
+ cat >expect <<-EOF &&
+ objects.commits.count.concern_level=2
+ objects.trees.count.concern_level=0
+ objects.blobs.count.concern_level=0
+ objects.tags.count.concern_level=0
+ objects.commits.inflated_size.concern_level=0
+ objects.trees.inflated_size.concern_level=0
+ objects.blobs.inflated_size.concern_level=3
+ objects.tags.inflated_size.concern_level=0
+ objects.commits.disk_size.concern_level=3
+ objects.trees.disk_size.concern_level=8
+ objects.blobs.disk_size.concern_level=6
+ objects.tags.disk_size.concern_level=5
+ objects.commits.max_size.concern_level=3
+ objects.trees.max_size.concern_level=0
+ objects.blobs.max_size.concern_level=1
+ objects.tags.max_size.concern_level=0
+ EOF
+
+ git repo structure --concern --format=lines >actual 2>err &&
+ test_grep "concern_level" actual >actual-concerns &&
+ test_cmp expect actual-concerns &&
+ 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" &&
git init repo &&
--
2.53.0