Skip to contentSkip to conversation

builtin/maintenance: accept "none" as a maintenance strategy

PATCH In review David Lin 3 participants 3 messages Jul 29 – Aug 4

lore
Share & tools
lore

David Lin

author
#0 lore raw

PATCH 1/1 builtin/maintenance: accept "none" as a maintenance strategy

Commit d465be2327 (builtin/maintenance: don't silently ignore invalid strategy, 2025-10-24) changed scheduled maintenance to error on an unknown maintenance strategy instead of silently defaulting to the none strategy.

However, parse_maintenance_strategy() does not recognize none, so Git rejects a valid and documented strategy that can be used to override an existing strategy and disable maintenance tasks.

Accept none as a valid maintenance strategy and add tests to ensure it's accepted.

---
 builtin/gc.c           | 2 ++
 t/t7900-maintenance.sh | 3 +++
 2 files changed, 5 insertions(+)
builtin/gc.c +2 -0
index 46999a99ab..3d1e39d46a 100644
@@ -1922,6 +1922,8 @@ static const struct maintenance_strategy geometric_strategy = {
 
 static struct maintenance_strategy parse_maintenance_strategy(const char *name)
 {
+	if (!strcasecmp(name, "none"))
+		return none_strategy;
 	if (!strcasecmp(name, "incremental"))
 		return incremental_strategy;
 	if (!strcasecmp(name, "gc"))
t/t7900-maintenance.sh +3 -0
index a8d691719d..130c971b15 100755
@@ -1022,6 +1022,9 @@ test_expect_success 'maintenance.strategy is respected' '
 		test_must_fail git -c maintenance.strategy=unknown maintenance run 2>err &&
 		test_grep "unknown maintenance strategy: .unknown." err &&
 
+		test_strategy none </dev/null &&
+		test_strategy none --schedule=weekly </dev/null &&
+
 		test_strategy incremental <<-\EOF &&
 		git pack-refs --all --prune
 		git reflog expire --all

base-commit: 13c7afec212fc97ce257d15601659314c6673d6c

Signature · 1 line
2.54.0
#1 lore raw

David Lin <[email protected]> writes:

The author identity uses an @gmail.com address, but the sign-off uses a different address. Assuming the preferred address is the one used in the sign-off, you can 'lie' about the author identity by starting the body of the message with an 'in-body From:' line:

From: David Lin <[email protected]>

This must be written without indentation and followed by a blank line before the true first line of the message body.

Quoted 47 lines

Commit d465be2327 (builtin/maintenance: don't silently ignore invalid strategy, 2025-10-24) changed scheduled maintenance to error on an unknown maintenance strategy instead of silently defaulting to the none strategy.

However, parse_maintenance_strategy() does not recognize none, so Git rejects a valid and documented strategy that can be used to override an existing strategy and disable maintenance tasks.

Accept none as a valid maintenance strategy and add tests to ensure it's accepted.

---
 builtin/gc.c           | 2 ++
 t/t7900-maintenance.sh | 3 +++
 2 files changed, 5 insertions(+)
builtin/gc.c +2 -0
index 46999a99ab..3d1e39d46a 100644
@@ -1922,6 +1922,8 @@ static const struct maintenance_strategy geometric_strategy = {
 
 static struct maintenance_strategy parse_maintenance_strategy(const char *name)
 {
+	if (!strcasecmp(name, "none"))
+		return none_strategy;
 	if (!strcasecmp(name, "incremental"))
 		return incremental_strategy;
 	if (!strcasecmp(name, "gc"))
t/t7900-maintenance.sh +3 -0
index a8d691719d..130c971b15 100755
@@ -1022,6 +1022,9 @@ test_expect_success 'maintenance.strategy is respected' '
 		test_must_fail git -c maintenance.strategy=unknown maintenance run 2>err &&
 		test_grep "unknown maintenance strategy: .unknown." err &&
 
+		test_strategy none </dev/null &&
+		test_strategy none --schedule=weekly </dev/null &&
+
 		test_strategy incremental <<-\EOF &&
 		git pack-refs --all --prune
 		git reflog expire --all

base-commit: 13c7afec212fc97ce257d15601659314c6673d6c

#2 lore raw
In reply to David Lin
Quoted 8 lines · David Lin

Commit d465be2327 (builtin/maintenance: don't silently ignore invalid strategy, 2025-10-24) changed scheduled maintenance to error on an unknown maintenance strategy instead of silently defaulting to the none strategy.

However, parse_maintenance_strategy() does not recognize none, so Git rejects a valid and documented strategy that can be used to override an existing strategy and disable maintenance tasks.

Oh, indeed.

Quoted 2 lines

Accept none as a valid maintenance strategy and add tests to ensure it's accepted.

Makes sense. You can of course achieve the same thing by disabling maintenance altogether, but it's a documented thing and users thus rightfully expect the "none" strategy to exist.

builtin/gc.c static const struct maintenance_strategy geometric_strategy = { · line 1929

Quoted 13 lines
builtin/gc.c +2 -0
index 46999a99ab..3d1e39d46a 100644
@@ -1922,6 +1922,8 @@ static const struct maintenance_strategy geometric_strategy = {
 
 static struct maintenance_strategy parse_maintenance_strategy(const char *name)
 {
+	if (!strcasecmp(name, "none"))
+		return none_strategy;
 	if (!strcasecmp(name, "incremental"))
 		return incremental_strategy;
 	if (!strcasecmp(name, "gc"))

Yup, looks obviously correct.

Quoted 5 lines
t/t7900-maintenance.sh +0 -0
index a8d691719d..130c971b15 100755

t/t7900-maintenance.sh test_expect_success 'maintenance.strategy is respected' ' · line 1030

Quoted 9 lines
t/t7900-maintenance.sh +3 -0
@@ -1022,6 +1022,9 @@ test_expect_success 'maintenance.strategy is respected' '
 		test_must_fail git -c maintenance.strategy=unknown maintenance run 2>err &&
 		test_grep "unknown maintenance strategy: .unknown." err &&
 
+		test_strategy none </dev/null &&
+		test_strategy none --schedule=weekly </dev/null &&
+
 		test_strategy incremental <<-\EOF &&
 		git pack-refs --all --prune
 		git reflog expire --all

And test looks obviously correct to me, too.

So other than Junio's remark about the SOB this patch looks good to me. Thanks!

Patrick