]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repack: move `write_filtered_pack()` out of the builtin
authorTaylor Blau <me@ttaylorr.com>
Sun, 28 Sep 2025 22:10:30 +0000 (18:10 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Sep 2025 16:31:25 +0000 (09:31 -0700)
In a similar fashion as in previous commits, move the function
`write_filtered_pack()` out of the builtin and into its own compilation
unit.

This function is now part of the repack.h API, but implemented in its
own "repack-filtered.c" unit as it is a separate component from other
kinds of repacking operations.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile
builtin/repack.c
meson.build
repack-filtered.c [new file with mode: 0644]
repack.h

index b2142771635c3120c3443620b9c30a7c393d88e5..ba4f3bbfa27684942be0731d0d172b4754e6788d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1137,6 +1137,7 @@ LIB_OBJS += refs/ref-cache.o
 LIB_OBJS += refspec.o
 LIB_OBJS += remote.o
 LIB_OBJS += repack.o
+LIB_OBJS += repack-filtered.o
 LIB_OBJS += repack-geometry.o
 LIB_OBJS += repack-midx.o
 LIB_OBJS += repack-promisor.o
index 9d89217b772b04c329ba0ded6ea493734ba0d9ff..a9fc09a24d07b5a2efac5330b44080c2bb1330a8 100644 (file)
@@ -106,52 +106,6 @@ static int repack_config(const char *var, const char *value,
        return git_default_config(var, value, ctx, cb);
 }
 
-static int write_filtered_pack(struct write_pack_opts *opts,
-                              struct existing_packs *existing,
-                              struct string_list *names)
-{
-       struct child_process cmd = CHILD_PROCESS_INIT;
-       struct string_list_item *item;
-       FILE *in;
-       int ret;
-       const char *caret;
-       const char *pack_prefix = write_pack_opts_pack_prefix(opts);
-
-       prepare_pack_objects(&cmd, opts->po_args, opts->destination);
-
-       strvec_push(&cmd.args, "--stdin-packs");
-
-       for_each_string_list_item(item, &existing->kept_packs)
-               strvec_pushf(&cmd.args, "--keep-pack=%s", item->string);
-
-       cmd.in = -1;
-
-       ret = start_command(&cmd);
-       if (ret)
-               return ret;
-
-       /*
-        * Here 'names' contains only the pack(s) that were just
-        * written, which is exactly the packs we want to keep. Also
-        * 'existing_kept_packs' already contains the packs in
-        * 'keep_pack_list'.
-        */
-       in = xfdopen(cmd.in, "w");
-       for_each_string_list_item(item, names)
-               fprintf(in, "^%s-%s.pack\n", pack_prefix, item->string);
-       for_each_string_list_item(item, &existing->non_kept_packs)
-               fprintf(in, "%s.pack\n", item->string);
-       for_each_string_list_item(item, &existing->cruft_packs)
-               fprintf(in, "%s.pack\n", item->string);
-       caret = opts->po_args->pack_kept_objects ? "" : "^";
-       for_each_string_list_item(item, &existing->kept_packs)
-               fprintf(in, "%s%s.pack\n", caret, item->string);
-       fclose(in);
-
-       return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd,
-                                      names);
-}
-
 static void combine_small_cruft_packs(FILE *in, size_t combine_cruft_below_size,
                                      struct existing_packs *existing)
 {
index 0423ed30c41d6425072270dda6b0b94cc6cabe19..7124b158ae8724eecd154ad542ae07bb8e240049 100644 (file)
@@ -463,6 +463,7 @@ libgit_sources = [
   'reftable/writer.c',
   'remote.c',
   'repack.c',
+  'repack-filtered.c',
   'repack-geometry.c',
   'repack-midx.c',
   'repack-promisor.c',
diff --git a/repack-filtered.c b/repack-filtered.c
new file mode 100644 (file)
index 0000000..96c7b02
--- /dev/null
@@ -0,0 +1,51 @@
+#include "git-compat-util.h"
+#include "repack.h"
+#include "repository.h"
+#include "run-command.h"
+#include "string-list.h"
+
+int write_filtered_pack(struct write_pack_opts *opts,
+                       struct existing_packs *existing,
+                       struct string_list *names)
+{
+       struct child_process cmd = CHILD_PROCESS_INIT;
+       struct string_list_item *item;
+       FILE *in;
+       int ret;
+       const char *caret;
+       const char *pack_prefix = write_pack_opts_pack_prefix(opts);
+
+       prepare_pack_objects(&cmd, opts->po_args, opts->destination);
+
+       strvec_push(&cmd.args, "--stdin-packs");
+
+       for_each_string_list_item(item, &existing->kept_packs)
+               strvec_pushf(&cmd.args, "--keep-pack=%s", item->string);
+
+       cmd.in = -1;
+
+       ret = start_command(&cmd);
+       if (ret)
+               return ret;
+
+       /*
+        * Here 'names' contains only the pack(s) that were just
+        * written, which is exactly the packs we want to keep. Also
+        * 'existing_kept_packs' already contains the packs in
+        * 'keep_pack_list'.
+        */
+       in = xfdopen(cmd.in, "w");
+       for_each_string_list_item(item, names)
+               fprintf(in, "^%s-%s.pack\n", pack_prefix, item->string);
+       for_each_string_list_item(item, &existing->non_kept_packs)
+               fprintf(in, "%s.pack\n", item->string);
+       for_each_string_list_item(item, &existing->cruft_packs)
+               fprintf(in, "%s.pack\n", item->string);
+       caret = opts->po_args->pack_kept_objects ? "" : "^";
+       for_each_string_list_item(item, &existing->kept_packs)
+               fprintf(in, "%s%s.pack\n", caret, item->string);
+       fclose(in);
+
+       return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd,
+                                      names);
+}
index 4a1c4eb60669d56d3430257b7de237ee432e9238..a7ddbe784b9d997fdcd80df06a40d14a601c4588 100644 (file)
--- a/repack.h
+++ b/repack.h
@@ -133,4 +133,8 @@ struct repack_write_midx_opts {
 void midx_snapshot_refs(struct repository *repo, struct tempfile *f);
 int write_midx_included_packs(struct repack_write_midx_opts *opts);
 
+int write_filtered_pack(struct write_pack_opts *opts,
+                       struct existing_packs *existing,
+                       struct string_list *names);
+
 #endif /* REPACK_H */