Skip to content

Commit d3d9c51

Browse files
peffgitster
authored andcommitted
repack: convert "names" util bitfield to array
We keep a string_list "names" containing the hashes of packs generated on our behalf by pack-objects. The util field of each item is treated as a bitfield that tells us which extensions (.pack, .idx, .rev, etc) are present for each name. Let's switch this to allocating a real array. That will give us room in a future patch to store more data than just a single bit per extension. And it makes the code a little easier to read, as we avoid casting back and forth between uintptr_t and a void pointer. Since the only thing we're storing is an array, we could just allocate it directly. But instead I've put it into a named struct here. That further increases readability around the casts, and in particular helps differentiate us from other string_lists in the same file which use their util field differently. E.g., the existing_*_packs lists still do bit-twiddling, but their bits have different meaning than the ones in "names". This makes it hard to grep around the code to see how the util fields are used; now you can look for "generated_pack_data". Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d5b4139 commit d3d9c51

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

builtin/repack.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,15 @@ static struct {
247247
{".idx"},
248248
};
249249

250-
static unsigned populate_pack_exts(char *name)
250+
struct generated_pack_data {
251+
char exts[ARRAY_SIZE(exts)];
252+
};
253+
254+
static struct generated_pack_data *populate_pack_exts(const char *name)
251255
{
252256
struct stat statbuf;
253257
struct strbuf path = STRBUF_INIT;
254-
unsigned ret = 0;
258+
struct generated_pack_data *data = xcalloc(1, sizeof(*data));
255259
int i;
256260

257261
for (i = 0; i < ARRAY_SIZE(exts); i++) {
@@ -261,11 +265,11 @@ static unsigned populate_pack_exts(char *name)
261265
if (stat(path.buf, &statbuf))
262266
continue;
263267

264-
ret |= (1 << i);
268+
data->exts[i] = 1;
265269
}
266270

267271
strbuf_release(&path);
268-
return ret;
272+
return data;
269273
}
270274

271275
static void repack_promisor_objects(const struct pack_objects_args *args,
@@ -320,7 +324,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
320324
line.buf);
321325
write_promisor_file(promisor_name, NULL, 0);
322326

323-
item->util = (void *)(uintptr_t)populate_pack_exts(item->string);
327+
item->util = populate_pack_exts(item->string);
324328

325329
free(promisor_name);
326330
}
@@ -994,7 +998,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
994998
string_list_sort(&names);
995999

9961000
for_each_string_list_item(item, &names) {
997-
item->util = (void *)(uintptr_t)populate_pack_exts(item->string);
1001+
item->util = populate_pack_exts(item->string);
9981002
}
9991003

10001004
close_object_store(the_repository->objects);
@@ -1003,6 +1007,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
10031007
* Ok we have prepared all new packfiles.
10041008
*/
10051009
for_each_string_list_item(item, &names) {
1010+
struct generated_pack_data *data = item->util;
1011+
10061012
for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
10071013
char *fname, *fname_old;
10081014

@@ -1011,7 +1017,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
10111017
fname_old = mkpathdup("%s-%s%s",
10121018
packtmp, item->string, exts[ext].name);
10131019

1014-
if (((uintptr_t)item->util) & ((uintptr_t)1 << ext)) {
1020+
if (data->exts[ext]) {
10151021
struct stat statbuffer;
10161022
if (!stat(fname_old, &statbuffer)) {
10171023
statbuffer.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
@@ -1115,7 +1121,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
11151121
write_midx_file(get_object_directory(), NULL, NULL, flags);
11161122
}
11171123

1118-
string_list_clear(&names, 0);
1124+
string_list_clear(&names, 1);
11191125
string_list_clear(&existing_nonkept_packs, 0);
11201126
string_list_clear(&existing_kept_packs, 0);
11211127
clear_pack_geometry(geometry);

0 commit comments

Comments
 (0)