authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-15 21:11:34 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-15 21:11:34 -07:00
loga76cb9d698e9f03b1e00b0b35b9c480901fe95e7
tree1d7f2cc21a885bffa974f0fed22d6cd96af3a84e
parentee13f80f6a00477098711a81fdef8d65ca6d1c2e
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add getObjectPackIndex, move this block into its own function


1 files changed, 14 insertions(+), 11 deletions(-)

git.zig+14-11
......@@ -793,9 +793,16 @@ pub const Repository = struct {
793793 );
794794 }
795795 }
796 const t4 = tracer.trace(@src(), " find pack_index/pack_offset", .{});
797 errdefer t4.end();
798 const pack_index, const pack_offset = blk: for (r.idx_content.keys(), r.idx_content.values()) |idx_path, idx_content| {
796 const pack_index, const pack_offset = try r.getObjectPackIndex(oid) orelse return null;
797 // parse .pack
798 return try r.getPackedObject(arena, oid, pack_index, pack_offset);
799 }
800
801 fn getObjectPackIndex(r: *Repository, oid: Id) !?[2]usize {
802 const t = tracer.trace(@src(), " {s}", .{oid});
803 defer t.end();
804
805 for (r.idx_content.keys(), r.idx_content.values()) |idx_path, idx_content| {
799806 if (std.mem.startsWith(u8, idx_content, "\xfftOc")) {
800807 var idx_fbs: nio.FixedBufferStream([]const u8) = .init(idx_content);
801808 _ = idx_fbs.takeSlice(4);
......@@ -843,15 +850,11 @@ pub const Repository = struct {
843850 try r.pack_content.put(r.gpa, idx_path, pack_content);
844851 break :clk r.pack_content.count() - 1;
845852 };
846 break :blk .{ pack_index, pack_offset };
847 } else {
848 return error.Version1Idx;
853 return .{ pack_index, pack_offset };
849854 }
850 } else return null;
851 t4.end();
852
853 // parse .pack
854 return try r.getPackedObject(arena, oid, pack_index, pack_offset);
855 return error.UnexpectedIdxVersion;
856 }
857 return null;
855858 }
856859
857860 fn getPackedObject(r: *Repository, arena: std.mem.Allocator, maybe_oid: ?Id, pack_index: usize, pack_offset: usize) !GitObject {