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 {...@@ -793,9 +793,16 @@ pub const Repository = struct {
793 );793 );
794 }794 }
795 }795 }
796 const t4 = tracer.trace(@src(), " find pack_index/pack_offset", .{});796 const pack_index, const pack_offset = try r.getObjectPackIndex(oid) orelse return null;
797 errdefer t4.end();797 // parse .pack
798 const pack_index, const pack_offset = blk: for (r.idx_content.keys(), r.idx_content.values()) |idx_path, idx_content| {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| {
799 if (std.mem.startsWith(u8, idx_content, "\xfftOc")) {806 if (std.mem.startsWith(u8, idx_content, "\xfftOc")) {
800 var idx_fbs: nio.FixedBufferStream([]const u8) = .init(idx_content);807 var idx_fbs: nio.FixedBufferStream([]const u8) = .init(idx_content);
801 _ = idx_fbs.takeSlice(4);808 _ = idx_fbs.takeSlice(4);
...@@ -843,15 +850,11 @@ pub const Repository = struct {...@@ -843,15 +850,11 @@ pub const Repository = struct {
843 try r.pack_content.put(r.gpa, idx_path, pack_content);850 try r.pack_content.put(r.gpa, idx_path, pack_content);
844 break :clk r.pack_content.count() - 1;851 break :clk r.pack_content.count() - 1;
845 };852 };
846 break :blk .{ pack_index, pack_offset };853 return .{ pack_index, pack_offset };
847 } else {
848 return error.Version1Idx;
849 }854 }
850 } else return null;855 return error.UnexpectedIdxVersion;
851 t4.end();856 }
852857 return null;
853 // parse .pack
854 return try r.getPackedObject(arena, oid, pack_index, pack_offset);
855 }858 }
856859
857 fn getPackedObject(r: *Repository, arena: std.mem.Allocator, maybe_oid: ?Id, pack_index: usize, pack_offset: usize) !GitObject {860 fn getPackedObject(r: *Repository, arena: std.mem.Allocator, maybe_oid: ?Id, pack_index: usize, pack_offset: usize) !GitObject {