git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 04/10] builtin/maintenance: make the geometric factor configurable

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 24, 2025, 06:57 UTC
Message-ID
<20251024-pks-maintenance-geometric-strategy-v3-4-9b5b3bdb4387@pks.im>
In-Reply-To
<20251024-pks-maintenance-geometric-strategy-v3-0-9b5b3bdb4387@pks.im>

The geometric repacking task uses a factor of two for its geometric sequence, meaning that each next pack must contain at least twice as many objects as the next-smaller one. In some cases it may be helpful to configure this factor though to reduce the number of packfile merges even further, e.g. in very big repositories. But while git-repack(1) itself supports doing this, the maintenance task does not give us a way to tune it.

Introduce a new "maintenance.geometric-repack.splitFactor" configuration to plug this gap.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Documentation/config/maintenance.adoc |  5 +++++
 builtin/gc.c                          |  9 ++++++++-
 t/t7900-maintenance.sh                | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/Documentation/config/maintenance.adoc b/Documentation/config/maintenance.adoc
index 26dc5de423f..45fdafc2c63 100644
--- a/Documentation/config/maintenance.adoc
+++ b/Documentation/config/maintenance.adoc
@@ -86,6 +86,11 @@ maintenance.geometric-repack.auto::
 	objects that would be written into a new packfile. The default value is
 	100.
 
+maintenance.geometric-repack.splitFactor::
+	This integer config option controls the factor used for the geometric
+	sequence. See the `--geometric=` option in linkgit:git-repack[1] for
+	more details. Defaults to `2`.
+
 maintenance.reflog-expire.auto::
 	This integer config option controls how often the `reflog-expire` task
 	should be run as part of `git maintenance run --auto`. If zero, then
diff --git a/builtin/gc.c b/builtin/gc.c
index 2c9ecd464d2..fb1a82e0304 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1582,6 +1582,9 @@ static int maintenance_task_geometric_repack(struct maintenance_run_opts *opts,
 	struct child_process child = CHILD_PROCESS_INIT;
 	int ret;
 
+	repo_config_get_int(the_repository, "maintenance.geometric-repack.splitFactor",
+			    &geometry.split_factor);
+
 	existing_packs.repo = the_repository;
 	existing_packs_collect(&existing_packs, &kept_packs);
 	pack_geometry_init(&geometry, &existing_packs, &po_args);
@@ -1591,7 +1594,8 @@ static int maintenance_task_geometric_repack(struct maintenance_run_opts *opts,
 
 	strvec_pushl(&child.args, "repack", "-d", "-l", NULL);
 	if (geometry.split < geometry.pack_nr)
-		strvec_push(&child.args, "--geometric=2");
+		strvec_pushf(&child.args, "--geometric=%d",
+			     geometry.split_factor);
 	else
 		add_repack_all_option(cfg, NULL, &child.args);
 	if (opts->quiet)
@@ -1632,6 +1636,9 @@ static int geometric_repack_auto_condition(struct gc_config *cfg UNUSED)
 	if (auto_value < 0)
 		return 1;
 
+	repo_config_get_int(the_repository, "maintenance.geometric-repack.splitFactor",
+			    &geometry.split_factor);
+
 	existing_packs.repo = the_repository;
 	existing_packs_collect(&existing_packs, &kept_packs);
 	pack_geometry_init(&geometry, &existing_packs, &po_args);
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index ace0ba83002..e0352fd1965 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -603,6 +603,38 @@ test_expect_success 'geometric repacking with --auto' '
 	)
 '
 
+test_expect_success 'geometric repacking honors configured split factor' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		git config set maintenance.auto false &&
+
+		# Create three different packs with 9, 2 and 1 object, respectively.
+		# This is done so that only a subset of packs would be merged
+		# together so that we can verify that `git repack` receives the
+		# correct geometric factor.
+		for i in $(test_seq 9)
+		do
+			echo first-$i | git hash-object -w --stdin -t blob || return 1
+		done &&
+		git repack --geometric=2 -d &&
+
+		for i in $(test_seq 2)
+		do
+			echo second-$i | git hash-object -w --stdin -t blob || return 1
+		done &&
+		git repack --geometric=2 -d &&
+
+		echo third | git hash-object -w --stdin -t blob &&
+		git repack --geometric=2 -d &&
+
+		test_geometric_repack_needed false splitFactor=2 &&
+		test_geometric_repack_needed true splitFactor=3 &&
+		test_subcommand git repack -d -l --geometric=3 --quiet --write-midx <trace2.txt
+	)
+'
+
 test_expect_success 'pack-refs task' '
 	for n in $(test_seq 1 5)
 	do
-- 
2.51.1.930.gacf6e81ea2.dirty
Previous: Jeff KingNext: Patrick Steinhardt
Message 47 of 69 in “builtin/maintenance: introduce "geometric" strategy”
  1. 0/8 builtin/maintenance: introduce "geometric" strategyPatrick Steinhardt, Oct 16, 2025
  2. 1/8 builtin/gc: remove global `repack` variablePatrick Steinhardt, Oct 16, 2025
  3. Justin ToblerOct 16, 2025
  4. Taylor BlauOct 17, 2025
  5. 2/8 builtin/gc: make `too_many_loose_objects()` reusable without GC configPatrick Steinhardt, Oct 16, 2025
  6. Junio C HamanoOct 16, 2025
  7. 3/8 builtin/maintenance: introduce "geometric-repack" taskPatrick Steinhardt, Oct 16, 2025
  8. Justin ToblerOct 16, 2025
  9. Patrick SteinhardtOct 17, 2025
  10. Taylor BlauOct 17, 2025
  11. Patrick SteinhardtOct 21, 2025
  12. Taylor BlauOct 23, 2025
  13. Patrick SteinhardtOct 24, 2025
  14. 4/8 builtin/maintenance: don't silently ignore invalid strategyPatrick Steinhardt, Oct 16, 2025
  15. 5/8 builtin/maintenance: run maintenance tasks depending on typePatrick Steinhardt, Oct 16, 2025
  16. 6/8 builtin/maintenance: extend "maintenance.strategy" to manual maintenancePatrick Steinhardt, Oct 16, 2025
  17. 7/8 builtin/maintenance: make "gc" strategy accessiblePatrick Steinhardt, Oct 16, 2025
  18. 8/8 builtin/maintenance: introduce "geometric" strategyPatrick Steinhardt, Oct 16, 2025
  19. 0/9 builtin/maintenance: introduce "geometric" strategyPatrick Steinhardt, Oct 21, 2025
  20. 1/9 builtin/gc: remove global `repack` variablePatrick Steinhardt, Oct 21, 2025
  21. 2/9 builtin/gc: make `too_many_loose_objects()` reusable without GC configPatrick Steinhardt, Oct 21, 2025
  22. 3/9 builtin/maintenance: introduce "geometric-repack" taskPatrick Steinhardt, Oct 21, 2025
  23. Taylor BlauOct 23, 2025
  24. Patrick SteinhardtOct 24, 2025
  25. 4/9 builtin/maintenance: make the geometric factor configurablePatrick Steinhardt, Oct 21, 2025
  26. Taylor BlauOct 23, 2025
  27. Patrick SteinhardtOct 24, 2025
  28. Taylor BlauOct 24, 2025
  29. 5/9 builtin/maintenance: don't silently ignore invalid strategyPatrick Steinhardt, Oct 21, 2025
  30. Taylor BlauOct 23, 2025
  31. 6/9 builtin/maintenance: run maintenance tasks depending on typePatrick Steinhardt, Oct 21, 2025
  32. Taylor BlauOct 23, 2025
  33. 7/9 builtin/maintenance: extend "maintenance.strategy" to manual maintenancePatrick Steinhardt, Oct 21, 2025
  34. 8/9 builtin/maintenance: make "gc" strategy accessiblePatrick Steinhardt, Oct 21, 2025
  35. 9/9 builtin/maintenance: introduce "geometric" strategyPatrick Steinhardt, Oct 21, 2025
  36. Taylor BlauOct 23, 2025
  37. Patrick SteinhardtOct 24, 2025
  38. Junio C HamanoOct 23, 2025
  39. Taylor BlauOct 23, 2025
  40. 00/10 builtin/maintenance: introduce "geometric" strategyPatrick Steinhardt, Oct 24, 2025
  41. 01/10 builtin/gc: remove global `repack` variablePatrick Steinhardt, Oct 24, 2025
  42. 02/10 builtin/gc: make `too_many_loose_objects()` reusable without GC configPatrick Steinhardt, Oct 24, 2025
  43. 03/10 builtin/maintenance: introduce "geometric-repack" taskPatrick Steinhardt, Oct 24, 2025
  44. Jeff KingOct 25, 2025
  45. Patrick SteinhardtOct 27, 2025
  46. Jeff KingOct 27, 2025
  47. 04/10 builtin/maintenance: make the geometric factor configurablePatrick Steinhardt, Oct 24, 2025
  48. 05/10 builtin/maintenance: don't silently ignore invalid strategyPatrick Steinhardt, Oct 24, 2025
  49. 06/10 builtin/maintenance: improve readability of strategiesPatrick Steinhardt, Oct 24, 2025
  50. 07/10 builtin/maintenance: run maintenance tasks depending on typePatrick Steinhardt, Oct 24, 2025
  51. 08/10 builtin/maintenance: extend "maintenance.strategy" to manual maintenancePatrick Steinhardt, Oct 24, 2025
  52. 09/10 builtin/maintenance: make "gc" strategy accessiblePatrick Steinhardt, Oct 24, 2025
  53. 10/10 builtin/maintenance: introduce "geometric" strategyPatrick Steinhardt, Oct 24, 2025
  54. Taylor BlauOct 24, 2025
  55. Junio C HamanoOct 24, 2025
  56. 00/10 builtin/maintenance: introduce "geometric" strategyPatrick Steinhardt, Oct 27, 2025
  57. 01/10 builtin/gc: remove global `repack` variablePatrick Steinhardt, Oct 27, 2025
  58. 02/10 builtin/gc: make `too_many_loose_objects()` reusable without GC configPatrick Steinhardt, Oct 27, 2025
  59. 03/10 builtin/maintenance: introduce "geometric-repack" taskPatrick Steinhardt, Oct 27, 2025
  60. 04/10 builtin/maintenance: make the geometric factor configurablePatrick Steinhardt, Oct 27, 2025
  61. 05/10 builtin/maintenance: don't silently ignore invalid strategyPatrick Steinhardt, Oct 27, 2025
  62. 06/10 builtin/maintenance: improve readability of strategiesPatrick Steinhardt, Oct 27, 2025
  63. 07/10 builtin/maintenance: run maintenance tasks depending on typePatrick Steinhardt, Oct 27, 2025
  64. 08/10 builtin/maintenance: extend "maintenance.strategy" to manual maintenancePatrick Steinhardt, Oct 27, 2025
  65. 09/10 builtin/maintenance: make "gc" strategy accessiblePatrick Steinhardt, Oct 27, 2025
  66. 10/10 builtin/maintenance: introduce "geometric" strategyPatrick Steinhardt, Oct 27, 2025
  67. Junio C HamanoOct 27, 2025
  68. Patrick SteinhardtOct 27, 2025
  69. Junio C HamanoOct 27, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.