authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-11 23:05:43 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-11 23:05:43 -07:00
loge0a0f997c9e236ecba67b9ff1e2d498d83f6b39d
tree9ddc382009effcd3eceb19ed605c7dd501d994b8
parent873eb80d6d42aa3be0ad19e695feb88e8e10236c
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add getPackedObject wrapper for soon ofs_delta


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

git.zig+14-6
......@@ -1089,6 +1089,10 @@ pub const Repository = struct {
10891089 // parse .pack
10901090 std.log.warn("pack_index={d} pack_offset={d}", .{ pack_index, pack_offset });
10911091
1092 return try r.getPackedObject(obj, pack_index, pack_offset);
1093 }
1094
1095 fn getPackedObject(r: *Repository, maybe_obj: ?Id, pack_index: usize, pack_offset: usize) ![]const u8 {
10921096 const pack_content = r.pack_content.values()[pack_index];
10931097 if (!std.mem.eql(u8, pack_content[0..4], "PACK")) return error.InvalidGitPack;
10941098 const pack_version = std.mem.readInt(u32, pack_content[4..][0..4], .big);
......@@ -1112,8 +1116,11 @@ pub const Repository = struct {
11121116 std.log.warn("type={s} size={d}", .{ @tagName(ty), size });
11131117
11141118 switch (ty) {
1115 .none, .reserved => {
1116 return null;
1119 .none => {
1120 unreachable;
1121 },
1122 .reserved => {
1123 unreachable;
11171124 },
11181125 .commit, .tree, .blob, .tag => {
11191126 const compressed_content = packedobj_fbs.rest()[0..size];
......@@ -1125,14 +1132,16 @@ pub const Repository = struct {
11251132 try list.writer().print(" {d}\x00", .{size});
11261133 try std.compress.flate.inflate.decompress(.zlib, bufr.anyReadable(), list.writer());
11271134 const content = try list.toOwnedSlice();
1128 try r.raw_object_contents.put(r.gpa, obj, content);
1135 if (maybe_obj) |obj| try r.raw_object_contents.put(r.gpa, obj, content);
11291136 return content;
11301137 },
11311138 .ofs_delta => {
1132 return null;
1139 std.log.debug("type={s} size={d}", .{ @tagName(ty), size });
1140 unreachable;
11331141 },
11341142 .ref_delta => {
1135 return null;
1143 std.log.debug("type={s} size={d}", .{ @tagName(ty), size });
1144 unreachable;
11361145 },
11371146 }
11381147 comptime unreachable;
......@@ -1142,7 +1151,6 @@ pub const Repository = struct {
11421151 },
11431152 else => return error.InvalidGitPack,
11441153 }
1145 return null;
11461154 }
11471155
11481156 pub fn getGitObject(r: *Repository, arena: std.mem.Allocator, obj: Id) !?GitObject {