Skip to content

Commit c147b75

Browse files
ttaylorrgitster
authored andcommitted
pack-objects: perform name-hash traversal for unpacked objects
With '--unpacked', pack-objects adds loose objects (which don't appear in any of the excluded packs from '--stdin-packs') to the output pack without considering them as reachability tips for the name-hash traversal. This was an oversight in the original implementation of '--stdin-packs', since the code which enumerates and adds loose objects to the output pack (`add_unreachable_loose_objects()`) did not have access to the 'rev_info' struct found in `read_packs_list_from_stdin()`. Excluding unpacked objects from that traversal doesn't affect the correctness of the resulting pack, but it does make it harder to discover good deltas for loose objects. Now that the 'rev_info' struct is declared outside of `read_packs_list_from_stdin()`, we can pass it to `add_objects_in_unpacked_packs()` and add any loose objects as tips to the above-mentioned traversal, in theory producing slightly tighter packs as a result. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2828d72 commit c147b75

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

builtin/pack-objects.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3647,7 +3647,7 @@ static void read_packs_list_from_stdin(struct rev_info *revs)
36473647
string_list_clear(&exclude_packs, 0);
36483648
}
36493649

3650-
static void add_unreachable_loose_objects(void);
3650+
static void add_unreachable_loose_objects(struct rev_info *revs);
36513651

36523652
static void read_stdin_packs(int rev_list_unpacked)
36533653
{
@@ -3674,7 +3674,7 @@ static void read_stdin_packs(int rev_list_unpacked)
36743674
ignore_packed_keep_in_core = 1;
36753675
read_packs_list_from_stdin(&revs);
36763676
if (rev_list_unpacked)
3677-
add_unreachable_loose_objects();
3677+
add_unreachable_loose_objects(&revs);
36783678

36793679
if (prepare_revision_walk(&revs))
36803680
die(_("revision walk setup failed"));
@@ -3793,7 +3793,7 @@ static void enumerate_cruft_objects(void)
37933793
_("Enumerating cruft objects"), 0);
37943794

37953795
add_objects_in_unpacked_packs();
3796-
add_unreachable_loose_objects();
3796+
add_unreachable_loose_objects(NULL);
37973797

37983798
stop_progress(&progress_state);
37993799
}
@@ -4071,8 +4071,9 @@ static void add_objects_in_unpacked_packs(void)
40714071
}
40724072

40734073
static int add_loose_object(const struct object_id *oid, const char *path,
4074-
void *data UNUSED)
4074+
void *data)
40754075
{
4076+
struct rev_info *revs = data;
40764077
enum object_type type = oid_object_info(the_repository, oid, NULL);
40774078

40784079
if (type < 0) {
@@ -4093,6 +4094,10 @@ static int add_loose_object(const struct object_id *oid, const char *path,
40934094
} else {
40944095
add_object_entry(oid, type, "", 0);
40954096
}
4097+
4098+
if (revs && type == OBJ_COMMIT)
4099+
add_pending_oid(revs, NULL, oid, 0);
4100+
40964101
return 0;
40974102
}
40984103

@@ -4101,11 +4106,10 @@ static int add_loose_object(const struct object_id *oid, const char *path,
41014106
* add_object_entry will weed out duplicates, so we just add every
41024107
* loose object we find.
41034108
*/
4104-
static void add_unreachable_loose_objects(void)
4109+
static void add_unreachable_loose_objects(struct rev_info *revs)
41054110
{
41064111
for_each_loose_file_in_objdir(repo_get_object_directory(the_repository),
4107-
add_loose_object,
4108-
NULL, NULL, NULL);
4112+
add_loose_object, NULL, NULL, revs);
41094113
}
41104114

41114115
static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
@@ -4361,7 +4365,7 @@ static void get_object_list(struct rev_info *revs, int ac, const char **av)
43614365
if (keep_unreachable)
43624366
add_objects_in_unpacked_packs();
43634367
if (pack_loose_unreachable)
4364-
add_unreachable_loose_objects();
4368+
add_unreachable_loose_objects(NULL);
43654369
if (unpack_unreachable)
43664370
loosen_unused_packed_objects();
43674371

0 commit comments

Comments
 (0)