diff mbox series

[2/2] config: let feature.experimental imply gc.cruftPacks=true

Message ID 20220803205721.3686361-3-emilyshaffer@google.com (mailing list archive)
State New, archived
Headers show
Series let feature.experimental imply gc.cruftPacks=true | expand

Commit Message

Emily Shaffer Aug. 3, 2022, 8:57 p.m. UTC
We are interested in exploring whether gc.cruftPacks=true should become
the default value; to determine whether it is safe to do so, let's
encourage more users to try it out. Users who have set
feature.experimental=true have already volunteered to try new and
possibly-breaking config changes, so let's try this new default with
that set of users.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
---
 Documentation/config/feature.txt |  2 ++
 builtin/gc.c                     |  6 ++++++
 t/t6500-gc.sh                    | 35 ++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)

Comments

Junio C Hamano Aug. 3, 2022, 10:05 p.m. UTC | #1
Emily Shaffer <emilyshaffer@google.com> writes:

> +* `gc.cruftPacks=true` reduces disk space used by unreachable objects during
> +garbage collection.

OK.

> diff --git a/builtin/gc.c b/builtin/gc.c
> index eeff2b760e..919cc508c5 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -136,6 +136,7 @@ static int gc_config_is_timestamp_never(const char *var)
>  static void gc_config(void)
>  {
>  	const char *value;
> +	int experimental = 0;
>  
>  	if (!git_config_get_value("gc.packrefs", &value)) {
>  		if (value && !strcmp(value, "notbare"))
> @@ -148,6 +149,11 @@ static void gc_config(void)
>  	    gc_config_is_timestamp_never("gc.reflogexpireunreachable"))
>  		prune_reflogs = 0;
>  
> +	/* feature.experimental implies gc.cruftPacks=true */
> +	git_config_get_bool("feature.experimental", &experimental);
> +	if (experimental)
> +		cruft_packs = 1;
> +

I suspect the whole thing can just be:

	git_config_get_bool("feature.experimental", &cruft_packs);

If there is no feature.experimental configuration, the call returns
non-zero (we do not check, though) without touching &cruft_packs, if
there is feature.experimental configuration, the call returns zero
(we do not check, though) and cruft_packs is set to either true
(when experimental) or false (otherwise).

And this whole thing happens before we inspect what the more
specific configuration gc.cruftPacks says, so...

> diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh
> index e4c2c3583d..4ab6750111 100755
> --- a/t/t6500-gc.sh
> +++ b/t/t6500-gc.sh
> @@ -238,6 +238,41 @@ test_expect_success 'gc.cruftPacks=true generates a cruft pack' '
>  	)
>  '
>  
> +test_expect_success 'feature.experimental=true generates a cruft pack' '
> +	git init crufts &&
> +	test_when_finished "rm -fr crufts" &&
> +	(
> +		cd crufts &&
> +		test_commit base &&
> +
> +		test_commit --no-tag foo &&
> +		test_commit --no-tag bar &&
> +		git reset HEAD^^ &&
> +
> +		git -c feature.experimental=true gc &&
> +
> +		cruft=$(basename $(ls .git/objects/pack/pack-*.mtimes) .mtimes) &&
> +		test_path_is_file .git/objects/pack/$cruft.pack
> +	)
> +'
> +
> +test_expect_success 'feature.experimental=false allows explicit cruft packs' '
> +	git init crufts &&
> +	test_when_finished "rm -fr crufts" &&
> +	(
> +		cd crufts &&
> +		test_commit base &&
> +
> +		test_commit --no-tag foo &&
> +		test_commit --no-tag bar &&
> +		git reset HEAD^^ &&
> +
> +		git -c gc.cruftPacks=true -c feature.experimental=false gc &&

OK.  

What is not tested is setting feature.experimental explicitly to
false without touching gc.cruftPacks does not use the cruft pack.
Derrick Stolee Aug. 4, 2022, 1:05 p.m. UTC | #2
On 8/3/2022 4:57 PM, Emily Shaffer wrote:

> +	/* feature.experimental implies gc.cruftPacks=true */
> +	git_config_get_bool("feature.experimental", &experimental);
> +	if (experimental)
> +		cruft_packs = 1;
> +

This should be grouped into prepare_repo_settings() in repo-settings.c
so we have a single place to see what is updated by feature.experimental.

Thanks,
-Stolee
Junio C Hamano Aug. 4, 2022, 4:10 p.m. UTC | #3
Derrick Stolee <derrickstolee@github.com> writes:

> On 8/3/2022 4:57 PM, Emily Shaffer wrote:
>
>> +	/* feature.experimental implies gc.cruftPacks=true */
>> +	git_config_get_bool("feature.experimental", &experimental);
>> +	if (experimental)
>> +		cruft_packs = 1;
>> +
>
> This should be grouped into prepare_repo_settings() in repo-settings.c
> so we have a single place to see what is updated by feature.experimental.

Excellent.  I forgot about that.  Thanks.
diff mbox series

Patch

diff --git a/Documentation/config/feature.txt b/Documentation/config/feature.txt
index cdecd04e5b..f029c422be 100644
--- a/Documentation/config/feature.txt
+++ b/Documentation/config/feature.txt
@@ -14,6 +14,8 @@  feature.experimental::
 +
 * `fetch.negotiationAlgorithm=skipping` may improve fetch negotiation times by
 skipping more commits at a time, reducing the number of round trips.
+* `gc.cruftPacks=true` reduces disk space used by unreachable objects during
+garbage collection.
 
 feature.manyFiles::
 	Enable config options that optimize for repos with many files in the
diff --git a/builtin/gc.c b/builtin/gc.c
index eeff2b760e..919cc508c5 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -136,6 +136,7 @@  static int gc_config_is_timestamp_never(const char *var)
 static void gc_config(void)
 {
 	const char *value;
+	int experimental = 0;
 
 	if (!git_config_get_value("gc.packrefs", &value)) {
 		if (value && !strcmp(value, "notbare"))
@@ -148,6 +149,11 @@  static void gc_config(void)
 	    gc_config_is_timestamp_never("gc.reflogexpireunreachable"))
 		prune_reflogs = 0;
 
+	/* feature.experimental implies gc.cruftPacks=true */
+	git_config_get_bool("feature.experimental", &experimental);
+	if (experimental)
+		cruft_packs = 1;
+
 	git_config_get_int("gc.aggressivewindow", &aggressive_window);
 	git_config_get_int("gc.aggressivedepth", &aggressive_depth);
 	git_config_get_int("gc.auto", &gc_auto_threshold);
diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh
index e4c2c3583d..4ab6750111 100755
--- a/t/t6500-gc.sh
+++ b/t/t6500-gc.sh
@@ -238,6 +238,41 @@  test_expect_success 'gc.cruftPacks=true generates a cruft pack' '
 	)
 '
 
+test_expect_success 'feature.experimental=true generates a cruft pack' '
+	git init crufts &&
+	test_when_finished "rm -fr crufts" &&
+	(
+		cd crufts &&
+		test_commit base &&
+
+		test_commit --no-tag foo &&
+		test_commit --no-tag bar &&
+		git reset HEAD^^ &&
+
+		git -c feature.experimental=true gc &&
+
+		cruft=$(basename $(ls .git/objects/pack/pack-*.mtimes) .mtimes) &&
+		test_path_is_file .git/objects/pack/$cruft.pack
+	)
+'
+
+test_expect_success 'feature.experimental=false allows explicit cruft packs' '
+	git init crufts &&
+	test_when_finished "rm -fr crufts" &&
+	(
+		cd crufts &&
+		test_commit base &&
+
+		test_commit --no-tag foo &&
+		test_commit --no-tag bar &&
+		git reset HEAD^^ &&
+
+		git -c gc.cruftPacks=true -c feature.experimental=false gc &&
+		cruft=$(basename $(ls .git/objects/pack/pack-*.mtimes) .mtimes) &&
+		test_path_is_file .git/objects/pack/$cruft.pack
+	)
+'
+
 run_and_wait_for_auto_gc () {
 	# We read stdout from gc for the side effect of waiting until the
 	# background gc process exits, closing its fd 9.  Furthermore, the