summaryrefslogtreecommitdiff
path: root/pack-bitmap.c
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2021-08-31 20:52:19 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-09-01 20:56:43 (GMT)
commita5f9f24aa0588621770df7f45a48615e238d8e17 (patch)
tree533ddadae25c43c4d6aa482a407616c02e814e08 /pack-bitmap.c
parent711260fd60366063e8c5253a83fc4aeb8947dc9d (diff)
downloadgit-a5f9f24aa0588621770df7f45a48615e238d8e17.zip
git-a5f9f24aa0588621770df7f45a48615e238d8e17.tar.gz
git-a5f9f24aa0588621770df7f45a48615e238d8e17.tar.bz2
pack-bitmap.c: avoid redundant calls to try_partial_reuse
try_partial_reuse() is used to mark any bits in the beginning of a bitmap whose objects can be reused verbatim from the pack they came from. Currently this function returns void, and signals nothing to the caller when bits could not be reused. But multi-pack bitmaps would benefit from having such a signal, because they may try to pass objects which are in bounds, but from a pack other than the preferred one. Any extra calls are noops because of a conditional in reuse_partial_packfile_from_bitmap(), but those loop iterations can be avoided by letting try_partial_reuse() indicate when it can't accept any more bits for reuse, and then listening to that signal. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pack-bitmap.c')
-rw-r--r--pack-bitmap.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/pack-bitmap.c b/pack-bitmap.c
index d529675..4e37f5d 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1140,22 +1140,26 @@ cleanup:
return NULL;
}
-static void try_partial_reuse(struct bitmap_index *bitmap_git,
- size_t pos,
- struct bitmap *reuse,
- struct pack_window **w_curs)
+/*
+ * -1 means "stop trying further objects"; 0 means we may or may not have
+ * reused, but you can keep feeding bits.
+ */
+static int try_partial_reuse(struct bitmap_index *bitmap_git,
+ size_t pos,
+ struct bitmap *reuse,
+ struct pack_window **w_curs)
{
off_t offset, header;
enum object_type type;
unsigned long size;
if (pos >= bitmap_num_objects(bitmap_git))
- return; /* not actually in the pack or MIDX */
+ return -1; /* not actually in the pack or MIDX */
offset = header = pack_pos_to_offset(bitmap_git->pack, pos);
type = unpack_object_header(bitmap_git->pack, w_curs, &offset, &size);
if (type < 0)
- return; /* broken packfile, punt */
+ return -1; /* broken packfile, punt */
if (type == OBJ_REF_DELTA || type == OBJ_OFS_DELTA) {
off_t base_offset;
@@ -1172,9 +1176,9 @@ static void try_partial_reuse(struct bitmap_index *bitmap_git,
base_offset = get_delta_base(bitmap_git->pack, w_curs,
&offset, type, header);
if (!base_offset)
- return;
+ return 0;
if (offset_to_pack_pos(bitmap_git->pack, base_offset, &base_pos) < 0)
- return;
+ return 0;
/*
* We assume delta dependencies always point backwards. This
@@ -1186,7 +1190,7 @@ static void try_partial_reuse(struct bitmap_index *bitmap_git,
* odd parameters.
*/
if (base_pos >= pos)
- return;
+ return 0;
/*
* And finally, if we're not sending the base as part of our
@@ -1197,13 +1201,14 @@ static void try_partial_reuse(struct bitmap_index *bitmap_git,
* object_entry code path handle it.
*/
if (!bitmap_get(reuse, base_pos))
- return;
+ return 0;
}
/*
* If we got here, then the object is OK to reuse. Mark it.
*/
bitmap_set(reuse, pos);
+ return 0;
}
int reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
@@ -1239,10 +1244,23 @@ int reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
break;
offset += ewah_bit_ctz64(word >> offset);
- try_partial_reuse(bitmap_git, pos + offset, reuse, &w_curs);
+ if (try_partial_reuse(bitmap_git, pos + offset, reuse,
+ &w_curs) < 0) {
+ /*
+ * try_partial_reuse indicated we couldn't reuse
+ * any bits, so there is no point in trying more
+ * bits in the current word, or any other words
+ * in result.
+ *
+ * Jump out of both loops to avoid future
+ * unnecessary calls to try_partial_reuse.
+ */
+ goto done;
+ }
}
}
+done:
unuse_pack(&w_curs);
*entries = bitmap_popcount(reuse);