repack: introduce new compilation unit

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Oct 15, 2025 at 18:27 UTC c7a120722ed60c07fa6a32f43b56f8361bfe38af
5 files changed +37 -24
Makefile
+1
@@ -1136,6 +1136,7 @@ LIB_OBJS += refs/packed-backend.o
1136 LIB_OBJS += refs/ref-cache.o
1137 LIB_OBJS += refspec.o
1138 LIB_OBJS += remote.o
1139 +LIB_OBJS += repack.o
1140 LIB_OBJS += replace-object.o
1141 LIB_OBJS += repo-settings.o
1142 LIB_OBJS += repository.o
builtin/repack.c
+1 -24
@@ -19,6 +19,7 @@
19 #include "prune-packed.h"
20 #include "odb.h"
21 #include "promisor-remote.h"
22 +#include "repack.h"
23 #include "shallow.h"
24 #include "pack.h"
25 #include "pack-bitmap.h"
@@ -53,21 +54,6 @@ static const char incremental_bitmap_conflict_error[] = N_(
54 "--no-write-bitmap-index or disable the pack.writeBitmaps configuration."
55 );
56
56 -struct pack_objects_args {
57 - char *window;
58 - char *window_memory;
59 - char *depth;
60 - char *threads;
61 - unsigned long max_pack_size;
62 - int no_reuse_delta;
63 - int no_reuse_object;
64 - int quiet;
65 - int local;
66 - int name_hash_version;
67 - int path_walk;
68 - struct list_objects_filter_options filter_options;
69 -};
70 -
57 static int repack_config(const char *var, const char *value,
58 const struct config_context *ctx, void *cb)
59 {
@@ -116,15 +102,6 @@ static int repack_config(const char *var, const char *value,
102 return git_default_config(var, value, ctx, cb);
103 }
104
119 -static void pack_objects_args_release(struct pack_objects_args *args)
120 -{
121 - free(args->window);
122 - free(args->window_memory);
123 - free(args->depth);
124 - free(args->threads);
125 - list_objects_filter_release(&args->filter_options);
126 -}
127 -
105 struct existing_packs {
106 struct repository *repo;
107 struct string_list kept_packs;
meson.build
+1
@@ -462,6 +462,7 @@ libgit_sources = [
462 'reftable/tree.c',
463 'reftable/writer.c',
464 'remote.c',
465 + 'repack.c',
466 'replace-object.c',
467 'repo-settings.c',
468 'repository.c',
repack.c new
+11
@@ -0,0 +1,11 @@
1 +#include "git-compat-util.h"
2 +#include "repack.h"
3 +
4 +void pack_objects_args_release(struct pack_objects_args *args)
5 +{
6 + free(args->window);
7 + free(args->window_memory);
8 + free(args->depth);
9 + free(args->threads);
10 + list_objects_filter_release(&args->filter_options);
11 +}
repack.h new
+23
@@ -0,0 +1,23 @@
1 +#ifndef REPACK_H
2 +#define REPACK_H
3 +
4 +#include "list-objects-filter-options.h"
5 +
6 +struct pack_objects_args {
7 + char *window;
8 + char *window_memory;
9 + char *depth;
10 + char *threads;
11 + unsigned long max_pack_size;
12 + int no_reuse_delta;
13 + int no_reuse_object;
14 + int quiet;
15 + int local;
16 + int name_hash_version;
17 + int path_walk;
18 + struct list_objects_filter_options filter_options;
19 +};
20 +
21 +void pack_objects_args_release(struct pack_objects_args *args);
22 +
23 +#endif /* REPACK_H */