pack-bitmap: simplify `reuse_partial_packfile_from_bitmap()` signature

The signature of `reuse_partial_packfile_from_bitmap()` currently takes in a bitmap, as well as three output parameters (filled through pointers, and passed as arguments), and also returns an integer result. The output parameters are filled out with: (a) the packfile used for pack-reuse, (b) the number of objects from that pack that we can reuse, and (c) a bitmap indicating which objects we can reuse. The return value is either -1 (when there are no objects to reuse), or 0 (when there is at least one object to reuse). Some of these parameters are redundant. Notably, we can infer from the bitmap how many objects are reused by calling bitmap_popcount(). And we can similar compute the return value based on that number as well. As such, clean up the signature of this function to drop the "*entries" parameter, as well as the int return value, since the single caller of this function can infer these values themself. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Dec 14, 2023 at 17:24 UTC 35e156b9de1dcc43673c6050cdb65735a7457c1a
3 files changed +19 -20
builtin/pack-objects.c
+9 -7
@@ -3943,13 +3943,15 @@ static int get_object_list_from_bitmap(struct rev_info *revs)
3943 if (!(bitmap_git = prepare_bitmap_walk(revs, 0)))
3944 return -1;
3945
3946 - if (pack_options_allow_reuse() &&
3947 - !reuse_partial_packfile_from_bitmap(
3948 - bitmap_git,
3949 - &reuse_packfile,
3950 - &reuse_packfile_objects,
3951 - &reuse_packfile_bitmap)) {
3952 - assert(reuse_packfile_objects);
3946 + if (pack_options_allow_reuse())
3947 + reuse_partial_packfile_from_bitmap(bitmap_git, &reuse_packfile,
3948 + &reuse_packfile_bitmap);
3949 +
3950 + if (reuse_packfile) {
3951 + reuse_packfile_objects = bitmap_popcount(reuse_packfile_bitmap);
3952 + if (!reuse_packfile_objects)
3953 + BUG("expected non-empty reuse bitmap");
3954 +
3955 nr_result += reuse_packfile_objects;
3956 nr_seen += reuse_packfile_objects;
3957 display_progress(progress_state, nr_seen);
pack-bitmap.c
+7 -9
@@ -2000,10 +2000,9 @@ static int bitmapped_pack_cmp(const void *va, const void *vb)
2000 return 0;
2001 }
2002
2003 -int reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
2004 - struct packed_git **packfile_out,
2005 - uint32_t *entries,
2006 - struct bitmap **reuse_out)
2003 +void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
2004 + struct packed_git **packfile_out,
2005 + struct bitmap **reuse_out)
2006 {
2007 struct repository *r = the_repository;
2008 struct bitmapped_pack *packs = NULL;
@@ -2025,7 +2024,7 @@ int reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
2024 warning(_("unable to load pack: '%s', disabling pack-reuse"),
2025 bitmap_git->midx->pack_names[i]);
2026 free(packs);
2028 - return -1;
2027 + return;
2028 }
2029 if (!pack.bitmap_nr)
2030 continue; /* no objects from this pack */
@@ -2059,10 +2058,10 @@ int reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
2058
2059 reuse_partial_packfile_from_bitmap_1(bitmap_git, packs, reuse);
2060
2062 - *entries = bitmap_popcount(reuse);
2063 - if (!*entries) {
2061 + if (bitmap_is_empty(reuse)) {
2062 + free(packs);
2063 bitmap_free(reuse);
2065 - return -1;
2064 + return;
2065 }
2066
2067 /*
@@ -2072,7 +2071,6 @@ int reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
2071 bitmap_and_not(result, reuse);
2072 *packfile_out = packs[0].p;
2073 *reuse_out = reuse;
2075 - return 0;
2074 }
2075
2076 int bitmap_walk_contains(struct bitmap_index *bitmap_git,
pack-bitmap.h
+3 -4
@@ -78,10 +78,9 @@ int test_bitmap_hashes(struct repository *r);
78 struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
79 int filter_provided_objects);
80 uint32_t midx_preferred_pack(struct bitmap_index *bitmap_git);
81 -int reuse_partial_packfile_from_bitmap(struct bitmap_index *,
82 - struct packed_git **packfile,
83 - uint32_t *entries,
84 - struct bitmap **reuse_out);
81 +void reuse_partial_packfile_from_bitmap(struct bitmap_index *,
82 + struct packed_git **packfile,
83 + struct bitmap **reuse_out);
84 int rebuild_existing_bitmaps(struct bitmap_index *, struct packing_data *mapping,
85 kh_oid_map_t *reused_bitmaps, int show_progress);
86 void free_bitmap_index(struct bitmap_index *);