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

[PATCH v2 11/49] repack: introduce new compilation unit

From
Taylor Blau <me@ttaylorr.com>
Date
Oct 15, 2025, 22:27 UTC
Message-ID
<87f2903e757f37cabad073077c9ba177f7418433.1760567210.git.me@ttaylorr.com>
In-Reply-To
<cover.1760567210.git.me@ttaylorr.com>

Over the years, builtin/repack.c has turned into a grab-bag of functionality powering the 'git repack' builtin. Among its many capabilities, it:

 - can build and spawn 'git pack-objects' commands, which in turn
   generate new packs
 - has infrastructure to manage the set of existing packs in a
   repository
 - has infrastructure to split a sequence of packs into a geometric
   progression based on object size
 - can manage both generating and combining cruft packs together
 - can write new MIDXs
to name a few.

As a result, this builtin has accumulated a lot of code, making adding new functionality difficult. In the future, 'repack' will learn how to manage a chain of incremental MIDXs, adding yet more functionality into the builtin.

As a prerequisite step, let's first move some of the functionality in the builtin into its own repack.[ch].

This will be done over the course of many steps, since there are many individual components, some of which will end up in other, yet-to-exist compilation units of their own. Some of the code movement here is also non-trivial, so performing it in individual steps will make it easier to verify.

Let's start by migrating 'struct pack_objects_args' (and the related corresponding pack_objects_args_release() function) into repack.h, and teach both the Makefile and Meson how to build the new compilation unit.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 Makefile         |  1 +
 builtin/repack.c | 25 +------------------------
 meson.build      |  1 +
 repack.c         | 11 +++++++++++
 repack.h         | 23 +++++++++++++++++++++++
 5 files changed, 37 insertions(+), 24 deletions(-)
 create mode 100644 repack.c
 create mode 100644 repack.h
diff --git a/Makefile b/Makefile
index 7ea149598d..58fc05030b 100644
--- a/Makefile
+++ b/Makefile
@@ -1249,6 +1249,7 @@ LIB_OBJS += refs/packed-backend.o
 LIB_OBJS += refs/ref-cache.o
 LIB_OBJS += refspec.o
 LIB_OBJS += remote.o
+LIB_OBJS += repack.o
 LIB_OBJS += replace-object.o
 LIB_OBJS += repo-settings.o
 LIB_OBJS += repository.o
diff --git a/builtin/repack.c b/builtin/repack.c
index 0d35f15b4b..6dfcb3327e 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -19,6 +19,7 @@
 #include "prune-packed.h"
 #include "odb.h"
 #include "promisor-remote.h"
+#include "repack.h"
 #include "shallow.h"
 #include "pack.h"
 #include "pack-bitmap.h"
@@ -53,21 +54,6 @@ static const char incremental_bitmap_conflict_error[] = N_(
 "--no-write-bitmap-index or disable the pack.writeBitmaps configuration."
 );
 
-struct pack_objects_args {
-	char *window;
-	char *window_memory;
-	char *depth;
-	char *threads;
-	unsigned long max_pack_size;
-	int no_reuse_delta;
-	int no_reuse_object;
-	int quiet;
-	int local;
-	int name_hash_version;
-	int path_walk;
-	struct list_objects_filter_options filter_options;
-};
-
 static int repack_config(const char *var, const char *value,
 			 const struct config_context *ctx, void *cb)
 {
@@ -116,15 +102,6 @@ static int repack_config(const char *var, const char *value,
 	return git_default_config(var, value, ctx, cb);
 }
 
-static void pack_objects_args_release(struct pack_objects_args *args)
-{
-	free(args->window);
-	free(args->window_memory);
-	free(args->depth);
-	free(args->threads);
-	list_objects_filter_release(&args->filter_options);
-}
-
 struct existing_packs {
 	struct repository *repo;
 	struct string_list kept_packs;
diff --git a/meson.build b/meson.build
index ec55d6a5fd..4a985ce77e 100644
--- a/meson.build
+++ b/meson.build
@@ -462,6 +462,7 @@ libgit_sources = [
   'reftable/tree.c',
   'reftable/writer.c',
   'remote.c',
+  'repack.c',
   'replace-object.c',
   'repo-settings.c',
   'repository.c',
diff --git a/repack.c b/repack.c
new file mode 100644
index 0000000000..a1f5b796fb
--- /dev/null
+++ b/repack.c
@@ -0,0 +1,11 @@
+#include "git-compat-util.h"
+#include "repack.h"
+
+void pack_objects_args_release(struct pack_objects_args *args)
+{
+	free(args->window);
+	free(args->window_memory);
+	free(args->depth);
+	free(args->threads);
+	list_objects_filter_release(&args->filter_options);
+}
diff --git a/repack.h b/repack.h
new file mode 100644
index 0000000000..421d439d5a
--- /dev/null
+++ b/repack.h
@@ -0,0 +1,23 @@
+#ifndef REPACK_H
+#define REPACK_H
+
+#include "list-objects-filter-options.h"
+
+struct pack_objects_args {
+	char *window;
+	char *window_memory;
+	char *depth;
+	char *threads;
+	unsigned long max_pack_size;
+	int no_reuse_delta;
+	int no_reuse_object;
+	int quiet;
+	int local;
+	int name_hash_version;
+	int path_walk;
+	struct list_objects_filter_options filter_options;
+};
+
+void pack_objects_args_release(struct pack_objects_args *args);
+
+#endif /* REPACK_H */
-- 
2.51.0.540.ga7423965ad8
Previous: Taylor BlauNext: Taylor Blau
Message 121 of 163 in “repack: prepare for incremental MIDX-based repacking”
  1. 00/49 repack: prepare for incremental MIDX-based repackingTaylor Blau, Sep 28, 2025
  2. 01/49 builtin/repack.c: avoid "the_repository" in `cmd_repack()`Taylor Blau, Sep 28, 2025
  3. 02/49 builtin/repack.c: avoid "the_repository" in existing packs APITaylor Blau, Sep 28, 2025
  4. Jeff KingOct 10, 2025
  5. Taylor BlauOct 10, 2025
  6. 03/49 builtin/repack.c: avoid "the_repository" when taking a ref snapshotTaylor Blau, Sep 28, 2025
  7. 04/49 builtin/repack.c: avoid "the_repository" when removing packsTaylor Blau, Sep 28, 2025
  8. Jeff KingOct 10, 2025
  9. Taylor BlauOct 10, 2025
  10. 05/49 builtin/repack.c: avoid "the_repository" when repacking promisor objectsTaylor Blau, Sep 28, 2025
  11. 06/49 builtin/repack.c: avoid "the_hash_algo" when deleting packsTaylor Blau, Sep 28, 2025
  12. 07/49 builtin/repack.c: avoid "the_hash_algo" in `write_oid()`Taylor Blau, Sep 28, 2025
  13. Patrick SteinhardtSep 29, 2025
  14. Taylor BlauOct 7, 2025
  15. 08/49 builtin/repack: avoid "the_hash_algo" in `repack_promisor_objects()`Taylor Blau, Sep 28, 2025
  16. 09/49 builtin/repack.c: avoid "the_hash_algo" in `finish_pack_objects_cmd()`Taylor Blau, Sep 28, 2025
  17. Jeff KingOct 10, 2025
  18. Taylor BlauOct 10, 2025
  19. 10/49 builtin/repack.c: avoid using `hash_to_hex()` in pack geometryTaylor Blau, Sep 28, 2025
  20. Patrick SteinhardtSep 29, 2025
  21. 11/49 repack: introduce new compilation unitTaylor Blau, Sep 28, 2025
  22. Jeff KingOct 10, 2025
  23. Taylor BlauOct 10, 2025
  24. 12/49 builtin/repack.c: pass both pack_objects args to repack_configTaylor Blau, Sep 28, 2025
  25. Patrick SteinhardtSep 29, 2025
  26. 13/49 repack: move 'delta_base_offset' to 'struct pack_objects_args'Taylor Blau, Sep 28, 2025
  27. Jeff KingOct 10, 2025
  28. Taylor BlauOct 10, 2025
  29. 14/49 repack: remove 'prepare_pack_objects' from the builtinTaylor Blau, Sep 28, 2025
  30. 15/49 builtin/repack.c: rename many 'struct existing_packs' functionsTaylor Blau, Sep 28, 2025
  31. 16/49 repack: remove 'remove_redundant_pack' from the builtinTaylor Blau, Sep 28, 2025
  32. 17/49 builtin/repack.c: pass "packdir" when removing packsTaylor Blau, Sep 28, 2025
  33. Patrick SteinhardtSep 29, 2025
  34. Taylor BlauOct 7, 2025
  35. Jeff KingOct 10, 2025
  36. Taylor BlauOct 10, 2025
  37. 18/49 builtin/repack.c: avoid unnecessary numeric casts in existing_packsTaylor Blau, Sep 28, 2025
  38. 19/49 repack: remove 'existing_packs' API from the builtinTaylor Blau, Sep 28, 2025
  39. Patrick SteinhardtSep 29, 2025
  40. Taylor BlauOct 7, 2025
  41. Jeff KingOct 10, 2025
  42. Taylor BlauOct 10, 2025
  43. 20/49 builtin/repack.c: rename "struct generated_pack_data"Taylor Blau, Sep 28, 2025
  44. 21/49 builtin/repack.c: factor our "generated_pack_install"Taylor Blau, Sep 28, 2025
  45. Patrick SteinhardtSep 29, 2025
  46. Taylor BlauOct 7, 2025
  47. Patrick SteinhardtOct 8, 2025
  48. Jeff KingOct 10, 2025
  49. Taylor BlauOct 10, 2025
  50. 22/49 builtin/repack.c: pass "packtmp" to `generated_pack_populate()`Taylor Blau, Sep 28, 2025
  51. Patrick SteinhardtSep 29, 2025
  52. Taylor BlauOct 7, 2025
  53. Patrick SteinhardtOct 8, 2025
  54. 23/49 builtin/repack.c: provide pack locations to `generated_pack_install()`Taylor Blau, Sep 28, 2025
  55. 24/49 repack: remove 'generated_pack' API from the builtinTaylor Blau, Sep 28, 2025
  56. 25/49 builtin/repack.c: pass "packtmp" to `repack_promisor_objects()`Taylor Blau, Sep 28, 2025
  57. 26/49 builtin/repack.c: remove "repack_promisor_objects()" from the builtinTaylor Blau, Sep 28, 2025
  58. Patrick SteinhardtSep 29, 2025
  59. Taylor BlauOct 7, 2025
  60. 27/49 builtin/repack.c: rename various pack_geometry functionsTaylor Blau, Sep 28, 2025
  61. Patrick SteinhardtSep 29, 2025
  62. Taylor BlauOct 7, 2025
  63. Patrick SteinhardtOct 8, 2025
  64. Taylor BlauOct 10, 2025
  65. 28/49 builtin/repack.c: pass 'pack_kept_objects' to `pack_geometry_init()`Taylor Blau, Sep 28, 2025
  66. 29/49 builtin/repack.c: pass 'packdir' to `pack_geometry_remove_redundant()`Taylor Blau, Sep 28, 2025
  67. 30/49 repack: remove pack_geometry API from the builtinTaylor Blau, Sep 28, 2025
  68. 31/49 builtin/repack.c: remove ref snapshotting from builtinTaylor Blau, Sep 28, 2025
  69. 32/49 builtin/repack.c: extract opts struct for 'write_midx_included_packs()'Taylor Blau, Sep 28, 2025
  70. 33/49 builtin/repack.c: use a string_list for 'midx_pack_names'Taylor Blau, Sep 28, 2025
  71. 34/49 repack: keep track of MIDX pack names using existing_packsTaylor Blau, Sep 28, 2025
  72. 35/49 builtin/repack.c: reorder `remove_redundant_bitmaps()`Taylor Blau, Sep 28, 2025
  73. 36/49 builtin/repack.c: inline `remove_redundant_bitmaps()`Taylor Blau, Sep 28, 2025
  74. 37/49 builtin/repack.c: pass `repack_write_midx_opts` to `midx_included_packs`Taylor Blau, Sep 28, 2025
  75. 38/49 builtin/repack.c: inline packs within `write_midx_included_packs()`Taylor Blau, Sep 28, 2025
  76. Patrick SteinhardtOct 10, 2025
  77. Taylor BlauOct 10, 2025
  78. Jeff KingOct 15, 2025
  79. 39/49 repack: 'write_midx_included_packs' API from the builtinTaylor Blau, Sep 28, 2025
  80. 40/49 builtin/repack.c: introduce `struct write_pack_opts`Taylor Blau, Sep 28, 2025
  81. Patrick SteinhardtOct 10, 2025
  82. Taylor BlauOct 10, 2025
  83. Jeff KingOct 15, 2025
  84. Taylor BlauOct 15, 2025
  85. 41/49 builtin/repack.c: use `write_pack_opts` within `write_cruft_pack()`Taylor Blau, Sep 28, 2025
  86. Patrick SteinhardtOct 10, 2025
  87. Taylor BlauOct 10, 2025
  88. Jeff KingOct 15, 2025
  89. 42/49 repack: move `find_pack_prefix()` out of the builtinTaylor Blau, Sep 28, 2025
  90. Jeff KingOct 15, 2025
  91. Taylor BlauOct 15, 2025
  92. 43/49 repack: extract `write_pack_opts_is_local()`Taylor Blau, Sep 28, 2025
  93. Patrick SteinhardtOct 10, 2025
  94. Taylor BlauOct 15, 2025
  95. Jeff KingOct 15, 2025
  96. Taylor BlauOct 15, 2025
  97. 44/49 builtin/repack.c: pass `write_pack_opts` to `finish_pack_objects_cmd()`Taylor Blau, Sep 28, 2025
  98. Jeff KingOct 15, 2025
  99. Taylor BlauOct 15, 2025
  100. 45/49 repack: move `finish_pack_objects_cmd()` out of the builtinTaylor Blau, Sep 28, 2025
  101. 46/49 repack: move `pack_kept_objects` to `struct pack_objects_args`Taylor Blau, Sep 28, 2025
  102. 47/49 repack: move `write_filtered_pack()` out of the builtinTaylor Blau, Sep 28, 2025
  103. 48/49 repack: move `write_cruft_pack()` out of the builtinTaylor Blau, Sep 28, 2025
  104. 49/49 builtin/repack.c: clean up unused `#include`sTaylor Blau, Sep 28, 2025
  105. Junio C HamanoSep 28, 2025
  106. Taylor BlauOct 7, 2025
  107. Jeff KingOct 10, 2025
  108. Taylor BlauOct 10, 2025
  109. Jeff KingOct 15, 2025
  110. 00/49 repack: prepare for incremental MIDX-based repackingTaylor Blau, Oct 15, 2025
  111. 01/49 builtin/repack.c: avoid "the_repository" in `cmd_repack()`Taylor Blau, Oct 15, 2025
  112. 02/49 builtin/repack.c: avoid "the_repository" in existing packs APITaylor Blau, Oct 15, 2025
  113. 03/49 builtin/repack.c: avoid "the_repository" when taking a ref snapshotTaylor Blau, Oct 15, 2025
  114. 04/49 builtin/repack.c: avoid "the_repository" when removing packsTaylor Blau, Oct 15, 2025
  115. 05/49 builtin/repack.c: avoid "the_repository" when repacking promisor objectsTaylor Blau, Oct 15, 2025
  116. 06/49 builtin/repack.c: avoid "the_hash_algo" when deleting packsTaylor Blau, Oct 15, 2025
  117. 07/49 builtin/repack.c: avoid "the_hash_algo" in `write_oid()`Taylor Blau, Oct 15, 2025
  118. 08/49 builtin/repack: avoid "the_hash_algo" in `repack_promisor_objects()`Taylor Blau, Oct 15, 2025
  119. 09/49 builtin/repack.c: avoid "the_hash_algo" in `finish_pack_objects_cmd()`Taylor Blau, Oct 15, 2025
  120. 10/49 builtin/repack.c: avoid using `hash_to_hex()` in pack geometryTaylor Blau, Oct 15, 2025
  121. 11/49 repack: introduce new compilation unitTaylor Blau, Oct 15, 2025
  122. 12/49 builtin/repack.c: pass both pack_objects args to repack_configTaylor Blau, Oct 15, 2025
  123. 13/49 repack: move 'delta_base_offset' to 'struct pack_objects_args'Taylor Blau, Oct 15, 2025
  124. 14/49 repack: remove 'prepare_pack_objects' from the builtinTaylor Blau, Oct 15, 2025
  125. 15/49 builtin/repack.c: rename many 'struct existing_packs' functionsTaylor Blau, Oct 15, 2025
  126. 16/49 repack: remove 'remove_redundant_pack' from the builtinTaylor Blau, Oct 15, 2025
  127. 17/49 builtin/repack.c: pass "packdir" when removing packsTaylor Blau, Oct 15, 2025
  128. 18/49 builtin/repack.c: avoid unnecessary numeric casts in existing_packsTaylor Blau, Oct 15, 2025
  129. 19/49 repack: remove 'existing_packs' API from the builtinTaylor Blau, Oct 15, 2025
  130. 20/49 builtin/repack.c: rename "struct generated_pack_data"Taylor Blau, Oct 15, 2025
  131. 21/49 builtin/repack.c: factor out "generated_pack_install"Taylor Blau, Oct 15, 2025
  132. 22/49 builtin/repack.c: pass "packtmp" to `generated_pack_populate()`Taylor Blau, Oct 15, 2025
  133. 23/49 builtin/repack.c: provide pack locations to `generated_pack_install()`Taylor Blau, Oct 15, 2025
  134. 24/49 repack: remove 'generated_pack' API from the builtinTaylor Blau, Oct 15, 2025
  135. 25/49 builtin/repack.c: pass "packtmp" to `repack_promisor_objects()`Taylor Blau, Oct 15, 2025
  136. 26/49 builtin/repack.c: remove "repack_promisor_objects()" from the builtinTaylor Blau, Oct 15, 2025
  137. 27/49 builtin/repack.c: rename various pack_geometry functionsTaylor Blau, Oct 15, 2025
  138. 28/49 builtin/repack.c: pass 'pack_kept_objects' to `pack_geometry_init()`Taylor Blau, Oct 15, 2025
  139. 29/49 builtin/repack.c: pass 'packdir' to `pack_geometry_remove_redundant()`Taylor Blau, Oct 15, 2025
  140. 30/49 repack: remove pack_geometry API from the builtinTaylor Blau, Oct 15, 2025
  141. 31/49 builtin/repack.c: remove ref snapshotting from builtinTaylor Blau, Oct 15, 2025
  142. 32/49 builtin/repack.c: extract opts struct for 'write_midx_included_packs()'Taylor Blau, Oct 15, 2025
  143. 33/49 builtin/repack.c: use a string_list for 'midx_pack_names'Taylor Blau, Oct 15, 2025
  144. 34/49 repack: keep track of MIDX pack names using existing_packsTaylor Blau, Oct 15, 2025
  145. 35/49 builtin/repack.c: reorder `remove_redundant_bitmaps()`Taylor Blau, Oct 15, 2025
  146. 36/49 builtin/repack.c: inline `remove_redundant_bitmaps()`Taylor Blau, Oct 15, 2025
  147. 37/49 builtin/repack.c: pass `repack_write_midx_opts` to `midx_included_packs`Taylor Blau, Oct 15, 2025
  148. 38/49 builtin/repack.c: inline packs within `write_midx_included_packs()`Taylor Blau, Oct 15, 2025
  149. 39/49 repack: 'write_midx_included_packs' API from the builtinTaylor Blau, Oct 15, 2025
  150. 40/49 builtin/repack.c: introduce `struct write_pack_opts`Taylor Blau, Oct 15, 2025
  151. 41/49 builtin/repack.c: use `write_pack_opts` within `write_cruft_pack()`Taylor Blau, Oct 15, 2025
  152. 42/49 repack: move `find_pack_prefix()` out of the builtinTaylor Blau, Oct 15, 2025
  153. 43/49 repack: extract `write_pack_opts_is_local()`Taylor Blau, Oct 15, 2025
  154. 44/49 builtin/repack.c: pass `write_pack_opts` to `finish_pack_objects_cmd()`Taylor Blau, Oct 15, 2025
  155. 45/49 repack: move `finish_pack_objects_cmd()` out of the builtinTaylor Blau, Oct 15, 2025
  156. 46/49 repack: move `pack_kept_objects` to `struct pack_objects_args`Taylor Blau, Oct 15, 2025
  157. 47/49 repack: move `write_filtered_pack()` out of the builtinTaylor Blau, Oct 15, 2025
  158. 48/49 repack: move `write_cruft_pack()` out of the builtinTaylor Blau, Oct 15, 2025
  159. 49/49 builtin/repack.c: clean up unused `#include`sTaylor Blau, Oct 15, 2025
  160. Patrick SteinhardtOct 16, 2025
  161. Junio C HamanoOct 16, 2025
  162. Taylor BlauOct 16, 2025
  163. Jeff KingOct 17, 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.