Skip to content

Commit eabfaf8

Browse files
ttaylorrgitster
authored andcommitted
builtin/repack.c: store existing cruft packs separately
When repacking with the `--write-midx` option, we invoke the function `midx_included_packs()` in order to produce the list of packs we want to include in the resulting MIDX. This list is comprised of: - existing .keep packs - any pack(s) which were written earlier in the same process - any unchanged packs when doing a `--geometric` repack - any cruft packs Prior to this patch, we stored pre-existing cruft and non-cruft packs together (provided those packs are non-kept). This meant we needed an additional bit to indicate which non-kept pack(s) were cruft versus those that aren't. But alternatively we can store cruft packs in a separate list, avoiding the need for this extra bit, and simplifying the code below. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4bbfb00 commit eabfaf8

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

builtin/repack.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#define PACK_CRUFT 4
2828

2929
#define DELETE_PACK 1
30-
#define CRUFT_PACK 2
3130

3231
static int pack_everything;
3332
static int delta_base_offset = 1;
@@ -98,16 +97,18 @@ static int repack_config(const char *var, const char *value,
9897
struct existing_packs {
9998
struct string_list kept_packs;
10099
struct string_list non_kept_packs;
100+
struct string_list cruft_packs;
101101
};
102102

103103
#define EXISTING_PACKS_INIT { \
104104
.kept_packs = STRING_LIST_INIT_DUP, \
105105
.non_kept_packs = STRING_LIST_INIT_DUP, \
106+
.cruft_packs = STRING_LIST_INIT_DUP, \
106107
}
107108

108109
static int has_existing_non_kept_packs(const struct existing_packs *existing)
109110
{
110-
return existing->non_kept_packs.nr;
111+
return existing->non_kept_packs.nr || existing->cruft_packs.nr;
111112
}
112113

113114
static void mark_packs_for_deletion_1(struct string_list *names,
@@ -138,6 +139,7 @@ static void mark_packs_for_deletion(struct existing_packs *existing,
138139

139140
{
140141
mark_packs_for_deletion_1(names, &existing->non_kept_packs);
142+
mark_packs_for_deletion_1(names, &existing->cruft_packs);
141143
}
142144

143145
static void remove_redundant_pack(const char *dir_name, const char *base_name)
@@ -165,12 +167,14 @@ static void remove_redundant_packs_1(struct string_list *packs)
165167
static void remove_redundant_existing_packs(struct existing_packs *existing)
166168
{
167169
remove_redundant_packs_1(&existing->non_kept_packs);
170+
remove_redundant_packs_1(&existing->cruft_packs);
168171
}
169172

170173
static void existing_packs_release(struct existing_packs *existing)
171174
{
172175
string_list_clear(&existing->kept_packs, 0);
173176
string_list_clear(&existing->non_kept_packs, 0);
177+
string_list_clear(&existing->cruft_packs, 0);
174178
}
175179

176180
/*
@@ -204,12 +208,10 @@ static void collect_pack_filenames(struct existing_packs *existing,
204208

205209
if ((extra_keep->nr > 0 && i < extra_keep->nr) || p->pack_keep)
206210
string_list_append(&existing->kept_packs, buf.buf);
207-
else {
208-
struct string_list_item *item;
209-
item = string_list_append(&existing->non_kept_packs, buf.buf);
210-
if (p->is_cruft)
211-
item->util = (void*)(uintptr_t)CRUFT_PACK;
212-
}
211+
else if (p->is_cruft)
212+
string_list_append(&existing->cruft_packs, buf.buf);
213+
else
214+
string_list_append(&existing->non_kept_packs, buf.buf);
213215
}
214216

215217
string_list_sort(&existing->kept_packs);
@@ -691,14 +693,11 @@ static void midx_included_packs(struct string_list *include,
691693
string_list_insert(include, strbuf_detach(&buf, NULL));
692694
}
693695

694-
for_each_string_list_item(item, &existing->non_kept_packs) {
695-
if (!((uintptr_t)item->util & CRUFT_PACK)) {
696-
/*
697-
* no need to check DELETE_PACK, since we're not
698-
* doing an ALL_INTO_ONE repack
699-
*/
700-
continue;
701-
}
696+
for_each_string_list_item(item, &existing->cruft_packs) {
697+
/*
698+
* no need to check DELETE_PACK, since we're not
699+
* doing an ALL_INTO_ONE repack
700+
*/
702701
string_list_insert(include, xstrfmt("%s.idx", item->string));
703702
}
704703
} else {
@@ -707,6 +706,12 @@ static void midx_included_packs(struct string_list *include,
707706
continue;
708707
string_list_insert(include, xstrfmt("%s.idx", item->string));
709708
}
709+
710+
for_each_string_list_item(item, &existing->cruft_packs) {
711+
if ((uintptr_t)item->util & DELETE_PACK)
712+
continue;
713+
string_list_insert(include, xstrfmt("%s.idx", item->string));
714+
}
710715
}
711716
}
712717

@@ -836,6 +841,8 @@ static int write_cruft_pack(const struct pack_objects_args *args,
836841
fprintf(in, "%s-%s.pack\n", pack_prefix, item->string);
837842
for_each_string_list_item(item, &existing->non_kept_packs)
838843
fprintf(in, "-%s.pack\n", item->string);
844+
for_each_string_list_item(item, &existing->cruft_packs)
845+
fprintf(in, "-%s.pack\n", item->string);
839846
for_each_string_list_item(item, &existing->kept_packs)
840847
fprintf(in, "%s.pack\n", item->string);
841848
fclose(in);

0 commit comments

Comments
 (0)