Skip to content

Commit 3011177

Browse files
jiangxingitster
authored andcommitted
pack-redundant: delay creation of unique_objects
Instead of initializing unique_objects in `add_pack()`, copy from all_objects in `cmp_two_packs()`, when unwanted objects are removed from all_objects. This will save memory (no allocate memory for alt-odb packs), and run `llist_sorted_difference_inplace()` only once when removing ignored objects and removing objects in alt-odb in `scan_alt_odb_packs()`. Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3173a94 commit 3011177

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

builtin/pack-redundant.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
254254
struct llist_item *p1_hint = NULL, *p2_hint = NULL;
255255
const unsigned int hashsz = the_hash_algo->rawsz;
256256

257+
if (!p1->unique_objects)
258+
p1->unique_objects = llist_copy(p1->all_objects);
259+
if (!p2->unique_objects)
260+
p2->unique_objects = llist_copy(p2->all_objects);
261+
257262
p1_base = p1->pack->index_data;
258263
p2_base = p2->pack->index_data;
259264
p1_base += 256 * 4 + ((p1->pack->index_version < 2) ? 4 : 8);
@@ -536,7 +541,7 @@ static void scan_alt_odb_packs(void)
536541
while (alt) {
537542
local = local_packs;
538543
while (local) {
539-
llist_sorted_difference_inplace(local->unique_objects,
544+
llist_sorted_difference_inplace(local->all_objects,
540545
alt->all_objects);
541546
local = local->next;
542547
}
@@ -567,8 +572,7 @@ static struct pack_list * add_pack(struct packed_git *p)
567572
llist_insert_back(l.all_objects, (const struct object_id *)(base + off));
568573
off += step;
569574
}
570-
/* this list will be pruned in cmp_two_packs later */
571-
l.unique_objects = llist_copy(l.all_objects);
575+
l.unique_objects = NULL;
572576
if (p->pack_local)
573577
return pack_list_insert(&local_packs, &l);
574578
else
@@ -646,7 +650,6 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
646650

647651
load_all_objects();
648652

649-
cmp_local_packs();
650653
if (alt_odb)
651654
scan_alt_odb_packs();
652655

@@ -663,10 +666,12 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
663666
llist_sorted_difference_inplace(all_objects, ignore);
664667
pl = local_packs;
665668
while (pl) {
666-
llist_sorted_difference_inplace(pl->unique_objects, ignore);
669+
llist_sorted_difference_inplace(pl->all_objects, ignore);
667670
pl = pl->next;
668671
}
669672

673+
cmp_local_packs();
674+
670675
minimize(&min);
671676

672677
if (verbose) {

0 commit comments

Comments
 (0)