Skip to content

Commit f905f49

Browse files
ttaylorrgitster
authored andcommitted
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>
1 parent a0dcecb commit f905f49

3 files changed

Lines changed: 23 additions & 16 deletions

File tree

builtin/repack.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,28 +208,14 @@ static void existing_packs_mark_for_deletion(struct existing_packs *existing,
208208
&existing->cruft_packs);
209209
}
210210

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-
225211
static void remove_redundant_packs_1(struct repository *repo,
226212
struct string_list *packs)
227213
{
228214
struct string_list_item *item;
229215
for_each_string_list_item(item, packs) {
230216
if (!existing_pack_is_marked_for_deletion(item))
231217
continue;
232-
remove_redundant_pack(repo, packdir, item->string);
218+
repack_remove_redundant_pack(repo, packdir, item->string);
233219
}
234220
}
235221

@@ -652,7 +638,7 @@ static void geometry_remove_redundant_packs(struct pack_geometry *geometry,
652638
(string_list_has_string(&existing->kept_packs, buf.buf)))
653639
continue;
654640

655-
remove_redundant_pack(existing->repo, packdir, buf.buf);
641+
repack_remove_redundant_pack(existing->repo, packdir, buf.buf);
656642
}
657643

658644
strbuf_release(&buf);

repack.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include "git-compat-util.h"
2+
#include "midx.h"
3+
#include "odb.h"
4+
#include "packfile.h"
25
#include "repack.h"
6+
#include "repository.h"
37
#include "run-command.h"
48

59
void prepare_pack_objects(struct child_process *cmd,
@@ -44,3 +48,17 @@ void pack_objects_args_release(struct pack_objects_args *args)
4448
free(args->threads);
4549
list_objects_filter_release(&args->filter_options);
4650
}
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ void prepare_pack_objects(struct child_process *cmd,
2828
const char *out);
2929
void pack_objects_args_release(struct pack_objects_args *args);
3030

31+
void repack_remove_redundant_pack(struct repository *repo, const char *dir_name,
32+
const char *base_name);
33+
3134
#endif /* REPACK_H */

0 commit comments

Comments
 (0)