]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repack: introduce new compilation unit
authorTaylor Blau <me@ttaylorr.com>
Wed, 15 Oct 2025 22:27:53 +0000 (18:27 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Oct 2025 17:08:53 +0000 (10:08 -0700)
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>
Makefile
builtin/repack.c
meson.build
repack.c [new file with mode: 0644]
repack.h [new file with mode: 0644]

index 4c95affadb5e265a98ffcf485f8c13a6c3a7e167..c0df6da2371ab6745ae6738f2c29cc36e2afa46f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1136,6 +1136,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
index 0d35f15b4b19c1fa74b312c2e0f810e40f2e8d94..6dfcb3327e66934be93487696effce9513b4421d 100644 (file)
@@ -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;
index b3dfcc04972601cbc3d05222f72070ddf0c2356f..993e8f368ffac1ad56e8782451ad96c9124ee6fa 100644 (file)
@@ -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 (file)
index 0000000..a1f5b79
--- /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 (file)
index 0000000..421d439
--- /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 */