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 {...@@ -1089,6 +1089,10 @@ pub const Repository = struct {
1089 // parse .pack1089 // parse .pack
1090 std.log.warn("pack_index={d} pack_offset={d}", .{ pack_index, pack_offset });1090 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 {
1092 const pack_content = r.pack_content.values()[pack_index];1096 const pack_content = r.pack_content.values()[pack_index];
1093 if (!std.mem.eql(u8, pack_content[0..4], "PACK")) return error.InvalidGitPack;1097 if (!std.mem.eql(u8, pack_content[0..4], "PACK")) return error.InvalidGitPack;
1094 const pack_version = std.mem.readInt(u32, pack_content[4..][0..4], .big);1098 const pack_version = std.mem.readInt(u32, pack_content[4..][0..4], .big);
...@@ -1112,8 +1116,11 @@ pub const Repository = struct {...@@ -1112,8 +1116,11 @@ pub const Repository = struct {
1112 std.log.warn("type={s} size={d}", .{ @tagName(ty), size });1116 std.log.warn("type={s} size={d}", .{ @tagName(ty), size });
11131117
1114 switch (ty) {1118 switch (ty) {
1115 .none, .reserved => {1119 .none => {
1116 return null;1120 unreachable;
1121 },
1122 .reserved => {
1123 unreachable;
1117 },1124 },
1118 .commit, .tree, .blob, .tag => {1125 .commit, .tree, .blob, .tag => {
1119 const compressed_content = packedobj_fbs.rest()[0..size];1126 const compressed_content = packedobj_fbs.rest()[0..size];
...@@ -1125,14 +1132,16 @@ pub const Repository = struct {...@@ -1125,14 +1132,16 @@ pub const Repository = struct {
1125 try list.writer().print(" {d}\x00", .{size});1132 try list.writer().print(" {d}\x00", .{size});
1126 try std.compress.flate.inflate.decompress(.zlib, bufr.anyReadable(), list.writer());1133 try std.compress.flate.inflate.decompress(.zlib, bufr.anyReadable(), list.writer());
1127 const content = try list.toOwnedSlice();1134 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);
1129 return content;1136 return content;
1130 },1137 },
1131 .ofs_delta => {1138 .ofs_delta => {
1132 return null;1139 std.log.debug("type={s} size={d}", .{ @tagName(ty), size });
1140 unreachable;
1133 },1141 },
1134 .ref_delta => {1142 .ref_delta => {
1135 return null;1143 std.log.debug("type={s} size={d}", .{ @tagName(ty), size });
1144 unreachable;
1136 },1145 },
1137 }1146 }
1138 comptime unreachable;1147 comptime unreachable;
...@@ -1142,7 +1151,6 @@ pub const Repository = struct {...@@ -1142,7 +1151,6 @@ pub const Repository = struct {
1142 },1151 },
1143 else => return error.InvalidGitPack,1152 else => return error.InvalidGitPack,
1144 }1153 }
1145 return null;
1146 }1154 }
11471155
1148 pub fn getGitObject(r: *Repository, arena: std.mem.Allocator, obj: Id) !?GitObject {1156 pub fn getGitObject(r: *Repository, arena: std.mem.Allocator, obj: Id) !?GitObject {