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

[PATCH 2/5] repack-geometry: extract function to compute repacking split

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 5, 2026, 13:16 UTC
Message-ID
<20260105-pks-geometric-repack-with-promisors-v1-2-c4660573437e@pks.im>
In-Reply-To
<20260105-pks-geometric-repack-with-promisors-v1-0-c4660573437e@pks.im>

We're about to add a second caller that wants to compute the repacking split for a set of packfiles. Split out the function that computes this split to prepare for that.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 repack-geometry.c | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/repack-geometry.c b/repack-geometry.c
index b3e32cd07e..17e6652a91 100644
--- a/repack-geometry.c
+++ b/repack-geometry.c
@@ -78,33 +78,32 @@ void pack_geometry_init(struct pack_geometry *geometry,
 	strbuf_release(&buf);
 }
 
-void pack_geometry_split(struct pack_geometry *geometry)
+static uint32_t compute_pack_geometry_split(struct packed_git **pack, size_t pack_nr,
+					    int split_factor)
 {
 	uint32_t i;
 	uint32_t split;
 	off_t total_size = 0;
 
-	if (!geometry->pack_nr) {
-		geometry->split = geometry->pack_nr;
-		return;
-	}
+	if (!pack_nr)
+		return 0;
 
 	/*
 	 * First, count the number of packs (in descending order of size) which
 	 * already form a geometric progression.
 	 */
-	for (i = geometry->pack_nr - 1; i > 0; i--) {
-		struct packed_git *ours = geometry->pack[i];
-		struct packed_git *prev = geometry->pack[i - 1];
+	for (i = pack_nr - 1; i > 0; i--) {
+		struct packed_git *ours = pack[i];
+		struct packed_git *prev = pack[i - 1];
 
-		if (unsigned_mult_overflows(geometry->split_factor,
+		if (unsigned_mult_overflows(split_factor,
 					    pack_geometry_weight(prev)))
 			die(_("pack %s too large to consider in geometric "
 			      "progression"),
 			    prev->pack_name);
 
 		if (pack_geometry_weight(ours) <
-		    geometry->split_factor * pack_geometry_weight(prev))
+		    split_factor * pack_geometry_weight(prev))
 			break;
 	}
 
@@ -130,21 +129,19 @@ void pack_geometry_split(struct pack_geometry *geometry)
 	 * the geometric progression.
 	 */
 	for (i = 0; i < split; i++) {
-		struct packed_git *p = geometry->pack[i];
+		struct packed_git *p = pack[i];
 
 		if (unsigned_add_overflows(total_size, pack_geometry_weight(p)))
 			die(_("pack %s too large to roll up"), p->pack_name);
 		total_size += pack_geometry_weight(p);
 	}
-	for (i = split; i < geometry->pack_nr; i++) {
-		struct packed_git *ours = geometry->pack[i];
+	for (i = split; i < pack_nr; i++) {
+		struct packed_git *ours = pack[i];
 
-		if (unsigned_mult_overflows(geometry->split_factor,
-					    total_size))
+		if (unsigned_mult_overflows(split_factor, total_size))
 			die(_("pack %s too large to roll up"), ours->pack_name);
 
-		if (pack_geometry_weight(ours) <
-		    geometry->split_factor * total_size) {
+		if (pack_geometry_weight(ours) < split_factor * total_size) {
 			if (unsigned_add_overflows(total_size,
 						   pack_geometry_weight(ours)))
 				die(_("pack %s too large to roll up"),
@@ -156,7 +153,13 @@ void pack_geometry_split(struct pack_geometry *geometry)
 			break;
 	}
 
-	geometry->split = split;
+	return split;
+}
+
+void pack_geometry_split(struct pack_geometry *geometry)
+{
+	geometry->split = compute_pack_geometry_split(geometry->pack, geometry->pack_nr,
+						      geometry->split_factor);
 }
 
 struct packed_git *pack_geometry_preferred_pack(struct pack_geometry *geometry)
-- 
2.52.0.508.g883dcfc63e.dirty
Previous: Patrick SteinhardtNext: Toon Claes
Message 5 of 11 in “builtin/repack: make geometric repacking compatible with promisors”
  1. 0/5 builtin/repack: make geometric repacking compatible with promisorsPatrick Steinhardt, Jan 5, 2026
  2. 1/5 builtin/pack-objects: exclude promisor objects with "--stdin-packs"Patrick Steinhardt, Jan 5, 2026
  3. Taylor BlauJan 9, 2026
  4. Patrick SteinhardtJan 12, 2026
  5. 2/5 repack-geometry: extract function to compute repacking splitPatrick Steinhardt, Jan 5, 2026
  6. Toon ClaesJan 14, 2026
  7. 3/5 repack-promisor: extract function to finalize repackingPatrick Steinhardt, Jan 5, 2026
  8. 4/5 repack-promisor: extract function to remove redundant packsPatrick Steinhardt, Jan 5, 2026
  9. Taylor BlauJan 9, 2026
  10. 5/5 builtin/repack: handle promisor packs with geometric repackingPatrick Steinhardt, Jan 5, 2026
  11. Toon ClaesJan 14, 2026

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.