Skip to content

Commit f2d3bf1

Browse files
ttaylorrgitster
authored andcommitted
builtin/repack.c: extract redundant pack cleanup for existing packs
To remove redundant packs at the end of a repacking operation, Git uses its `remove_redundant_pack()` function in a loop over the set of pre-existing, non-kept packs. In a later commit, we will split this list into two, one for pre-existing cruft pack(s), and another for non-cruft pack(s). Prepare for this by factoring out the routine to loop over and delete redundant packs into its own function. Instead of calling `remove_redundant_pack()` directly, we now will call `remove_redundant_existing_packs()`, which itself dispatches a call to `remove_redundant_packs_1()`. Note that the geometric repacking code will still call `remove_redundant_pack()` directly, but see the previous commit for more details. Having `remove_redundant_packs_1()` exist as a separate function may seem like overkill in this patch. However, a later patch will call `remove_redundant_packs_1()` once over two separate lists, so this refactoring sets us up for that. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 639c4a3 commit f2d3bf1

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

builtin/repack.c

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,33 @@ static void mark_packs_for_deletion(struct existing_packs *existing,
135135
mark_packs_for_deletion_1(names, &existing->non_kept_packs);
136136
}
137137

138+
static void remove_redundant_pack(const char *dir_name, const char *base_name)
139+
{
140+
struct strbuf buf = STRBUF_INIT;
141+
struct multi_pack_index *m = get_local_multi_pack_index(the_repository);
142+
strbuf_addf(&buf, "%s.pack", base_name);
143+
if (m && midx_contains_pack(m, buf.buf))
144+
clear_midx_file(the_repository);
145+
strbuf_insertf(&buf, 0, "%s/", dir_name);
146+
unlink_pack_path(buf.buf, 1);
147+
strbuf_release(&buf);
148+
}
149+
150+
static void remove_redundant_packs_1(struct string_list *packs)
151+
{
152+
struct string_list_item *item;
153+
for_each_string_list_item(item, packs) {
154+
if (!((uintptr_t)item->util & DELETE_PACK))
155+
continue;
156+
remove_redundant_pack(packdir, item->string);
157+
}
158+
}
159+
160+
static void remove_redundant_existing_packs(struct existing_packs *existing)
161+
{
162+
remove_redundant_packs_1(&existing->non_kept_packs);
163+
}
164+
138165
static void existing_packs_release(struct existing_packs *existing)
139166
{
140167
string_list_clear(&existing->kept_packs, 0);
@@ -184,18 +211,6 @@ static void collect_pack_filenames(struct existing_packs *existing,
184211
strbuf_release(&buf);
185212
}
186213

187-
static void remove_redundant_pack(const char *dir_name, const char *base_name)
188-
{
189-
struct strbuf buf = STRBUF_INIT;
190-
struct multi_pack_index *m = get_local_multi_pack_index(the_repository);
191-
strbuf_addf(&buf, "%s.pack", base_name);
192-
if (m && midx_contains_pack(m, buf.buf))
193-
clear_midx_file(the_repository);
194-
strbuf_insertf(&buf, 0, "%s/", dir_name);
195-
unlink_pack_path(buf.buf, 1);
196-
strbuf_release(&buf);
197-
}
198-
199214
static void prepare_pack_objects(struct child_process *cmd,
200215
const struct pack_objects_args *args,
201216
const char *out)
@@ -1221,11 +1236,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
12211236

12221237
if (delete_redundant) {
12231238
int opts = 0;
1224-
for_each_string_list_item(item, &existing.non_kept_packs) {
1225-
if (!((uintptr_t)item->util & DELETE_PACK))
1226-
continue;
1227-
remove_redundant_pack(packdir, item->string);
1228-
}
1239+
remove_redundant_existing_packs(&existing);
12291240

12301241
if (geometry.split_factor)
12311242
geometry_remove_redundant_packs(&geometry, &names,

0 commit comments

Comments
 (0)