repack: move `write_filtered_pack()` out of the builtin
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>
Taylor Blau committed
Oct 15, 2025 at 18:29 UTC
7ac4231b4283f4f8dc8447439730a5a2b8ed7eb4
5 files changed
+57
-46
Makefile
+1
@@ -1137,6 +1137,7 @@ LIB_OBJS += refs/ref-cache.o
1137
LIB_OBJS += refspec.o
1138
LIB_OBJS += remote.o
1139
LIB_OBJS += repack.o
1140
+LIB_OBJS += repack-filtered.o
1141
LIB_OBJS += repack-geometry.o
1142
LIB_OBJS += repack-midx.o
1143
LIB_OBJS += repack-promisor.o
builtin/repack.c
-46
@@ -106,52 +106,6 @@ static int repack_config(const char *var, const char *value,
106
return git_default_config(var, value, ctx, cb);
107
}
108
109
-static int write_filtered_pack(const struct write_pack_opts *opts,
110
- struct existing_packs *existing,
111
- struct string_list *names)
112
-{
113
- struct child_process cmd = CHILD_PROCESS_INIT;
114
- struct string_list_item *item;
115
- FILE *in;
116
- int ret;
117
- const char *caret;
118
- const char *pack_prefix = write_pack_opts_pack_prefix(opts);
119
-
120
- prepare_pack_objects(&cmd, opts->po_args, opts->destination);
121
-
122
- strvec_push(&cmd.args, "--stdin-packs");
123
-
124
- for_each_string_list_item(item, &existing->kept_packs)
125
- strvec_pushf(&cmd.args, "--keep-pack=%s", item->string);
126
-
127
- cmd.in = -1;
128
-
129
- ret = start_command(&cmd);
130
- if (ret)
131
- return ret;
132
-
133
- /*
134
- * Here 'names' contains only the pack(s) that were just
135
- * written, which is exactly the packs we want to keep. Also
136
- * 'existing_kept_packs' already contains the packs in
137
- * 'keep_pack_list'.
138
- */
139
- in = xfdopen(cmd.in, "w");
140
- for_each_string_list_item(item, names)
141
- fprintf(in, "^%s-%s.pack\n", pack_prefix, item->string);
142
- for_each_string_list_item(item, &existing->non_kept_packs)
143
- fprintf(in, "%s.pack\n", item->string);
144
- for_each_string_list_item(item, &existing->cruft_packs)
145
- fprintf(in, "%s.pack\n", item->string);
146
- caret = opts->po_args->pack_kept_objects ? "" : "^";
147
- for_each_string_list_item(item, &existing->kept_packs)
148
- fprintf(in, "%s%s.pack\n", caret, item->string);
149
- fclose(in);
150
-
151
- return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd,
152
- names);
153
-}
154
-
109
static void combine_small_cruft_packs(FILE *in, size_t combine_cruft_below_size,
110
struct existing_packs *existing)
111
{
meson.build
+1
@@ -463,6 +463,7 @@ libgit_sources = [
463
'reftable/writer.c',
464
'remote.c',
465
'repack.c',
466
+ 'repack-filtered.c',
467
'repack-geometry.c',
468
'repack-midx.c',
469
'repack-promisor.c',
repack-filtered.c
new
+51
@@ -0,0 +1,51 @@
1
+#include "git-compat-util.h"
2
+#include "repack.h"
3
+#include "repository.h"
4
+#include "run-command.h"
5
+#include "string-list.h"
6
+
7
+int write_filtered_pack(const struct write_pack_opts *opts,
8
+ struct existing_packs *existing,
9
+ struct string_list *names)
10
+{
11
+ struct child_process cmd = CHILD_PROCESS_INIT;
12
+ struct string_list_item *item;
13
+ FILE *in;
14
+ int ret;
15
+ const char *caret;
16
+ const char *pack_prefix = write_pack_opts_pack_prefix(opts);
17
+
18
+ prepare_pack_objects(&cmd, opts->po_args, opts->destination);
19
+
20
+ strvec_push(&cmd.args, "--stdin-packs");
21
+
22
+ for_each_string_list_item(item, &existing->kept_packs)
23
+ strvec_pushf(&cmd.args, "--keep-pack=%s", item->string);
24
+
25
+ cmd.in = -1;
26
+
27
+ ret = start_command(&cmd);
28
+ if (ret)
29
+ return ret;
30
+
31
+ /*
32
+ * Here 'names' contains only the pack(s) that were just
33
+ * written, which is exactly the packs we want to keep. Also
34
+ * 'existing_kept_packs' already contains the packs in
35
+ * 'keep_pack_list'.
36
+ */
37
+ in = xfdopen(cmd.in, "w");
38
+ for_each_string_list_item(item, names)
39
+ fprintf(in, "^%s-%s.pack\n", pack_prefix, item->string);
40
+ for_each_string_list_item(item, &existing->non_kept_packs)
41
+ fprintf(in, "%s.pack\n", item->string);
42
+ for_each_string_list_item(item, &existing->cruft_packs)
43
+ fprintf(in, "%s.pack\n", item->string);
44
+ caret = opts->po_args->pack_kept_objects ? "" : "^";
45
+ for_each_string_list_item(item, &existing->kept_packs)
46
+ fprintf(in, "%s%s.pack\n", caret, item->string);
47
+ fclose(in);
48
+
49
+ return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd,
50
+ names);
51
+}
repack.h
+4
@@ -133,4 +133,8 @@ struct repack_write_midx_opts {
133
void midx_snapshot_refs(struct repository *repo, struct tempfile *f);
134
int write_midx_included_packs(struct repack_write_midx_opts *opts);
135
136
+int write_filtered_pack(const struct write_pack_opts *opts,
137
+ struct existing_packs *existing,
138
+ struct string_list *names);
139
+
140
#endif /* REPACK_H */