Skip to content

Commit b639606

Browse files
peffgitster
authored andcommitted
repack: populate extension bits incrementally
After generating the main pack and then any additional cruft packs, we iterate over the "names" list (which contains hashes of packs generated by pack-objects), and call populate_pack_exts() for each. There's one small problem with this. In repack_promisor_objects(), we may add entries to "names" and call populate_pack_exts() for them. Calling it again is mostly just wasteful, as we'll stat() the filename with each possible extension, get the same result, and just overwrite our bits. So we could drop the call there, and leave the final loop to populate all of the bits. But instead, this patch does the reverse: drops the final loop, and teaches the other two sites to populate the bits as they add entries. This makes the code easier to reason about, as you never have to worry about when the util field is valid; it is always valid for each entry. It also serves my ulterior purpose: recording the generated filenames as soon as possible will make it easier for a future patch to use them for cleaning up from a failed operation. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d3d9c51 commit b639606

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

builtin/repack.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -714,10 +714,14 @@ static int write_cruft_pack(const struct pack_objects_args *args,
714714

715715
out = xfdopen(cmd.out, "r");
716716
while (strbuf_getline_lf(&line, out) != EOF) {
717+
struct string_list_item *item;
718+
717719
if (line.len != the_hash_algo->hexsz)
718720
die(_("repack: Expecting full hex object ID lines only "
719721
"from pack-objects."));
720-
string_list_append(names, line.buf);
722+
723+
item = string_list_append(names, line.buf);
724+
item->util = populate_pack_exts(line.buf);
721725
}
722726
fclose(out);
723727

@@ -956,9 +960,12 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
956960

957961
out = xfdopen(cmd.out, "r");
958962
while (strbuf_getline_lf(&line, out) != EOF) {
963+
struct string_list_item *item;
964+
959965
if (line.len != the_hash_algo->hexsz)
960966
die(_("repack: Expecting full hex object ID lines only from pack-objects."));
961-
string_list_append(&names, line.buf);
967+
item = string_list_append(&names, line.buf);
968+
item->util = populate_pack_exts(item->string);
962969
}
963970
fclose(out);
964971
ret = finish_command(&cmd);
@@ -997,10 +1004,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
9971004

9981005
string_list_sort(&names);
9991006

1000-
for_each_string_list_item(item, &names) {
1001-
item->util = populate_pack_exts(item->string);
1002-
}
1003-
10041007
close_object_store(the_repository->objects);
10051008

10061009
/*

0 commit comments

Comments
 (0)