commit f5e78e05ae4eb8c5e5909841ee696fa5b6d0dfea from: Stefan Sperling date: Wed May 04 15:39:15 2022 UTC avoid loop over the ID set which removes objects IDs with reused deltas ok op@ commit - 2d9e6abf243a0a1895786fa9002b28d69a0f6fea commit + f5e78e05ae4eb8c5e5909841ee696fa5b6d0dfea blob - fb1e3545cc2cf36d2fb0c5ebec569c5b2302472d blob + ca90c2008f13c7d8d23491fdf83419879cbc986d --- lib/pack_create.c +++ lib/pack_create.c @@ -1864,18 +1864,6 @@ remove_unused_object(struct got_object_id *id, void *d struct got_object_idset *idset = arg; if (data == NULL) - got_object_idset_remove(NULL, idset, id); - - return NULL; -} - -static const struct got_error * -remove_reused_object(struct got_object_id *id, void *data, void *arg) -{ - struct got_object_idset *idset = arg; - struct got_pack_meta *m = data; - - if (m->have_reused_delta) got_object_idset_remove(NULL, idset, id); return NULL; @@ -1886,6 +1874,9 @@ add_meta_idset_cb(struct got_object_id *id, void *data { struct got_pack_meta *m = data; struct got_pack_metavec *v = arg; + + if (m->have_reused_delta) + return NULL; return add_meta(m, v); } @@ -1905,6 +1896,7 @@ got_pack_create(uint8_t *packsha1, FILE *packfile, struct got_ratelimit rl; struct got_pack_metavec deltify, reuse; int ncolored = 0, nfound = 0, ntrees = 0; + size_t ndeltify; memset(&deltify, 0, sizeof(deltify)); memset(&reuse, 0, sizeof(reuse)); @@ -1956,12 +1948,6 @@ got_pack_create(uint8_t *packsha1, FILE *packfile, cancel_cb, cancel_arg); if (err) goto done; - if (reuse.nmeta > 0) { - err = got_object_idset_for_each(idset, - remove_reused_object, idset); - if (err) - goto done; - } delta_cache = fdopen(delta_cache_fd, "a+"); if (delta_cache == NULL) { @@ -1975,23 +1961,27 @@ got_pack_create(uint8_t *packsha1, FILE *packfile, goto done; } - deltify.meta = calloc(got_object_idset_num_elements(idset), - sizeof(struct got_pack_meta *)); - if (deltify.meta == NULL) { - err = got_error_from_errno("calloc"); - goto done; - } - deltify.metasz = got_object_idset_num_elements(idset); + ndeltify = got_object_idset_num_elements(idset) - reuse.nmeta; + if (ndeltify > 0) { + deltify.meta = calloc(ndeltify, sizeof(struct got_pack_meta *)); + if (deltify.meta == NULL) { + err = got_error_from_errno("calloc"); + goto done; + } + deltify.metasz = ndeltify; - err = got_object_idset_for_each(idset, add_meta_idset_cb, &deltify); - if (err) - goto done; - if (deltify.nmeta > 0) { - err = pick_deltas(deltify.meta, deltify.nmeta, ncolored, - nfound, ntrees, nours, reuse.nmeta, delta_cache, repo, - progress_cb, progress_arg, &rl, cancel_cb, cancel_arg); + err = got_object_idset_for_each(idset, add_meta_idset_cb, + &deltify); if (err) goto done; + if (deltify.nmeta > 0) { + err = pick_deltas(deltify.meta, deltify.nmeta, + ncolored, nfound, ntrees, nours, reuse.nmeta, + delta_cache, repo, progress_cb, progress_arg, &rl, + cancel_cb, cancel_arg); + if (err) + goto done; + } } if (fflush(delta_cache) == EOF) {