From: Taylor Blau <me@ttaylorr.com>
To: git@vger.kernel.org
Cc: Elijah Newren <newren@gmail.com>, Jeff King <peff@peff.net>,
Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>
Subject: [PATCH 07/11] write_reused_pack_one(): translate bit positions directly
Date: Wed, 9 Oct 2024 16:31:21 -0400 [thread overview]
Message-ID: <94e5c96f6859479e0206d6d775eacf54b3639ee5.1728505840.git.me@ttaylorr.com> (raw)
In-Reply-To: <cover.1728505840.git.me@ttaylorr.com>
A future commit will want to deal with bit positions instead of pack
positions from within builtin/pack-objects.c::write_reused_pack_one().
That function at present takes a pack position, so one approach to
accommodating the new functionality would be to add a secondary bit
position parameter, making the function's declaration look something
like:
static void write_reused_pack_one(struct packed_git *reuse_packfile,
size_t pack_pos, size_t bitmap_pos,
struct hashfile *out,
off_t pack_start,
struct pack_window **w_curs);
But because the pack-relative position can be easily derived from the
bit position, it makes senes to just pass the latter and let the
function itself translate it into a pack-relative position.
To do this, extract a new function `bitmap_to_pack_pos()` from the
existing `write_reused_pack()` function. This new routine is responsible
for performing the conversion from bitmap- to pack-relative positions.
Instead of performing that translation in `write_reused_pack()`, instead
call the new function from within `write_reused_pack_one()` so that we
can just pass a single bit position to it.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
builtin/pack-objects.c | 78 ++++++++++++++++++++++--------------------
1 file changed, 41 insertions(+), 37 deletions(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 097bb5ac2ca..7f50d58a235 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1017,6 +1017,42 @@ static off_t find_reused_offset(off_t where)
return reused_chunks[lo-1].difference;
}
+static uint32_t bitmap_to_pack_pos(struct packed_git *reuse_packfile,
+ size_t pos)
+{
+ if (bitmap_is_midx(bitmap_git)) {
+ /*
+ * When doing multi-pack reuse on a
+ * non-preferred pack, translate bit positions
+ * from the MIDX pseudo-pack order back to their
+ * pack-relative positions before attempting
+ * reuse.
+ */
+ struct multi_pack_index *m = bitmap_midx(bitmap_git);
+ uint32_t midx_pos, pack_pos;
+ off_t pack_ofs;
+
+ if (!m)
+ BUG("non-zero bitmap position without MIDX");
+
+ midx_pos = pack_pos_to_midx(m, pos);
+ pack_ofs = nth_midxed_offset(m, midx_pos);
+
+ if (offset_to_pack_pos(reuse_packfile, pack_ofs, &pack_pos) < 0)
+ BUG("could not find expected object at offset %"PRIuMAX" in pack %s",
+ (uintmax_t)pack_ofs, pack_basename(reuse_packfile));
+
+ return pack_pos;
+ } else {
+ /*
+ * Can use bit positions directly, even for MIDX
+ * bitmaps. See comment in try_partial_reuse()
+ * for why.
+ */
+ return pos;
+ }
+}
+
static void write_reused_pack_one(struct packed_git *reuse_packfile,
size_t pos, struct hashfile *out,
off_t pack_start,
@@ -1025,9 +1061,10 @@ static void write_reused_pack_one(struct packed_git *reuse_packfile,
off_t offset, next, cur;
enum object_type type;
unsigned long size;
+ uint32_t pack_pos = bitmap_to_pack_pos(reuse_packfile, pos);
- offset = pack_pos_to_offset(reuse_packfile, pos);
- next = pack_pos_to_offset(reuse_packfile, pos + 1);
+ offset = pack_pos_to_offset(reuse_packfile, pack_pos);
+ next = pack_pos_to_offset(reuse_packfile, pack_pos + 1);
record_reused_object(offset,
offset - (hashfile_total(out) - pack_start));
@@ -1191,7 +1228,6 @@ static void write_reused_pack(struct bitmapped_pack *reuse_packfile,
size_t pos = (i * BITS_IN_EWORD);
for (offset = 0; offset < BITS_IN_EWORD; ++offset) {
- uint32_t pack_pos;
if ((word >> offset) == 0)
break;
@@ -1201,40 +1237,8 @@ static void write_reused_pack(struct bitmapped_pack *reuse_packfile,
if (pos + offset >= reuse_packfile->bitmap_pos + reuse_packfile->bitmap_nr)
goto done;
- if (bitmap_is_midx(bitmap_git)) {
- /*
- * When doing multi-pack reuse on a
- * non-preferred pack, translate bit positions
- * from the MIDX pseudo-pack order back to their
- * pack-relative positions before attempting
- * reuse.
- */
- struct multi_pack_index *m = bitmap_midx(bitmap_git);
- uint32_t midx_pos;
- off_t pack_ofs;
-
- if (!m)
- BUG("non-zero bitmap position without MIDX");
-
- midx_pos = pack_pos_to_midx(m, pos + offset);
- pack_ofs = nth_midxed_offset(m, midx_pos);
-
- if (offset_to_pack_pos(reuse_packfile->p,
- pack_ofs, &pack_pos) < 0)
- BUG("could not find expected object at offset %"PRIuMAX" in pack %s",
- (uintmax_t)pack_ofs,
- pack_basename(reuse_packfile->p));
- } else {
- /*
- * Can use bit positions directly, even for MIDX
- * bitmaps. See comment in try_partial_reuse()
- * for why.
- */
- pack_pos = pos + offset;
- }
-
- write_reused_pack_one(reuse_packfile->p, pack_pos, f,
- pack_start, &w_curs);
+ write_reused_pack_one(reuse_packfile->p, pos + offset,
+ f, pack_start, &w_curs);
display_progress(progress_state, ++written);
}
}
--
2.47.0.11.g487258bca34
next prev parent reply other threads:[~2024-10-09 20:31 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-09 20:30 [PATCH 00/11] pack-bitmap: convert offset to ref deltas where possible Taylor Blau
2024-10-09 20:31 ` [PATCH 01/11] pack-bitmap.c: do not pass `pack_pos` to `try_partial_reuse()` Taylor Blau
2024-10-09 20:31 ` [PATCH 02/11] pack-bitmap.c: avoid unnecessary `offset_to_pack_pos()` Taylor Blau
2024-10-09 20:31 ` [PATCH 03/11] pack-bitmap.c: delay calling 'offset_to_pack_pos()' Taylor Blau
2024-10-09 20:31 ` [PATCH 04/11] pack-bitmap.c: compare `base_offset` to `delta_obj_offset` Taylor Blau
2024-10-09 20:31 ` [PATCH 05/11] pack-bitmap.c: extract `find_base_bitmap_pos()` Taylor Blau
2024-10-09 20:31 ` [PATCH 06/11] pack-bitmap: drop `from_midx` field from `bitmapped_pack` Taylor Blau
2024-10-09 20:31 ` Taylor Blau [this message]
2024-10-11 8:16 ` [PATCH 07/11] write_reused_pack_one(): translate bit positions directly Jeff King
2024-11-04 20:36 ` Taylor Blau
2024-10-09 20:31 ` [PATCH 08/11] t5332: enable OFS_DELTAs via test_pack_objects_reused Taylor Blau
2024-10-11 8:19 ` Jeff King
2024-11-04 20:50 ` Taylor Blau
2024-10-09 20:31 ` [PATCH 09/11] pack-bitmap: enable cross-pack delta reuse Taylor Blau
2024-10-11 8:31 ` Jeff King
2024-11-04 21:00 ` Taylor Blau
2024-10-09 20:31 ` [PATCH 10/11] pack-bitmap.c: record whether the result was filtered Taylor Blau
2024-10-11 8:35 ` Jeff King
2024-11-04 21:01 ` Taylor Blau
2024-10-09 20:31 ` [PATCH 11/11] pack-bitmap: enable reusing deltas with base objects in 'haves' bitmap Taylor Blau
2024-10-10 16:46 ` [PATCH 00/11] pack-bitmap: convert offset to ref deltas where possible Junio C Hamano
2024-10-10 17:07 ` Taylor Blau
2024-10-10 20:20 ` Junio C Hamano
2024-10-10 20:32 ` Taylor Blau
2024-10-11 7:54 ` Jeff King
2024-10-11 8:01 ` Jeff King
2024-10-11 16:23 ` Junio C Hamano
2024-10-11 8:38 ` Jeff King
2024-11-19 23:08 ` Taylor Blau
2024-11-19 23:34 ` Taylor Blau
2024-12-18 12:57 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=94e5c96f6859479e0206d6d775eacf54b3639ee5.1728505840.git.me@ttaylorr.com \
--to=me@ttaylorr.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=newren@gmail.com \
--cc=peff@peff.net \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).