repack: remove 'remove_redundant_pack' from the builtin
Extract "remove_redundant_pack()" as generic repack-related functionality by moving its implementation to the repack.[ch] compilation unit. This is a prerequisite to moving the "existing_packs" API, which is one of the callers of this function. (The remaining caller in the pack geometry code will eventually move to its own compilation unit as well, and will likewise rely on this function.) While moving it over, prefix the function name with "repack_" to indicate that it belongs to the repack-subsystem. 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:28 UTC
f905f49c68f9cf3aff93f0dcd065dd95345c21d5
3 files changed
+23
-16
builtin/repack.c
+2
-16
@@ -208,20 +208,6 @@ static void existing_packs_mark_for_deletion(struct existing_packs *existing,
208
&existing->cruft_packs);
209
}
210
211
-static void remove_redundant_pack(struct repository *repo,
212
- const char *dir_name, const char *base_name)
213
-{
214
- struct strbuf buf = STRBUF_INIT;
215
- struct odb_source *source = repo->objects->sources;
216
- struct multi_pack_index *m = get_multi_pack_index(source);
217
- strbuf_addf(&buf, "%s.pack", base_name);
218
- if (m && source->local && midx_contains_pack(m, buf.buf))
219
- clear_midx_file(repo);
220
- strbuf_insertf(&buf, 0, "%s/", dir_name);
221
- unlink_pack_path(buf.buf, 1);
222
- strbuf_release(&buf);
223
-}
224
-
211
static void remove_redundant_packs_1(struct repository *repo,
212
struct string_list *packs)
213
{
@@ -229,7 +215,7 @@ static void remove_redundant_packs_1(struct repository *repo,
215
for_each_string_list_item(item, packs) {
216
if (!existing_pack_is_marked_for_deletion(item))
217
continue;
232
- remove_redundant_pack(repo, packdir, item->string);
218
+ repack_remove_redundant_pack(repo, packdir, item->string);
219
}
220
}
221
@@ -652,7 +638,7 @@ static void geometry_remove_redundant_packs(struct pack_geometry *geometry,
638
(string_list_has_string(&existing->kept_packs, buf.buf)))
639
continue;
640
655
- remove_redundant_pack(existing->repo, packdir, buf.buf);
641
+ repack_remove_redundant_pack(existing->repo, packdir, buf.buf);
642
}
643
644
strbuf_release(&buf);
repack.c
+18
@@ -1,5 +1,9 @@
1
#include "git-compat-util.h"
2
+#include "midx.h"
3
+#include "odb.h"
4
+#include "packfile.h"
5
#include "repack.h"
6
+#include "repository.h"
7
#include "run-command.h"
8
9
void prepare_pack_objects(struct child_process *cmd,
@@ -44,3 +48,17 @@ void pack_objects_args_release(struct pack_objects_args *args)
48
free(args->threads);
49
list_objects_filter_release(&args->filter_options);
50
}
51
+
52
+void repack_remove_redundant_pack(struct repository *repo, const char *dir_name,
53
+ const char *base_name)
54
+{
55
+ struct strbuf buf = STRBUF_INIT;
56
+ struct odb_source *source = repo->objects->sources;
57
+ struct multi_pack_index *m = get_multi_pack_index(source);
58
+ strbuf_addf(&buf, "%s.pack", base_name);
59
+ if (m && source->local && midx_contains_pack(m, buf.buf))
60
+ clear_midx_file(repo);
61
+ strbuf_insertf(&buf, 0, "%s/", dir_name);
62
+ unlink_pack_path(buf.buf, 1);
63
+ strbuf_release(&buf);
64
+}
repack.h
+3
@@ -28,4 +28,7 @@ void prepare_pack_objects(struct child_process *cmd,
28
const char *out);
29
void pack_objects_args_release(struct pack_objects_args *args);
30
31
+void repack_remove_redundant_pack(struct repository *repo, const char *dir_name,
32
+ const char *base_name);
33
+
34
#endif /* REPACK_H */