authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-14 04:05:32 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-14 04:05:32 -07:00
log4d582b1398ee864a942901fc3095a295b6b794e9
treeb8876c86e6aefe440444a0233cddc65d75cc2711
parent52075b3bd908a77c2cd2aebc5b480354643496f7
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

compressed_content is not limited by size

zlib knows when to stop

1 files changed, 7 insertions(+), 8 deletions(-)

git.zig+7-8
......@@ -1046,7 +1046,8 @@ pub const Repository = struct {
10461046 @memcpy(pack_path[13..][0..idx_path.len], idx_path);
10471047 @memcpy(pack_path[13..][idx_path.len - 4 ..][0..5], ".pack");
10481048 const pack_name_nidx = std.mem.indexOfScalar(u8, &pack_path, 0).?;
1049 const pack_file = try r.gitdir.openFile(pack_path[0..pack_name_nidx :0], .{});
1049 const pack_name = pack_path[0..pack_name_nidx :0];
1050 const pack_file = try r.gitdir.openFile(pack_name, .{});
10501051 defer pack_file.close();
10511052 const pack_content = try pack_file.mmap();
10521053 errdefer nfs.munmap(pack_content);
......@@ -1087,6 +1088,7 @@ pub const Repository = struct {
10871088 size += (c & 0x7f) << shift;
10881089 shift += 7;
10891090 }
1091 // std.log.debug("type={s} size={d}", .{ @tagName(ty), size });
10901092 const t2 = tracer.trace(@src(), " 2 {s} {d}", .{ @tagName(ty), size });
10911093 defer t2.end();
10921094 switch (ty) {
......@@ -1097,7 +1099,7 @@ pub const Repository = struct {
10971099 unreachable;
10981100 },
10991101 .commit, .tree, .blob, .tag => {
1100 const compressed_content = packedobj_fbs.rest()[0..size];
1102 const compressed_content = packedobj_fbs.rest();
11011103 var list: std.ArrayListUnmanaged(u8) = .empty;
11021104 errdefer list.deinit(r.gpa);
11031105 try list.ensureUnusedCapacity(r.gpa, 512);
......@@ -1110,7 +1112,6 @@ pub const Repository = struct {
11101112 return obj;
11111113 },
11121114 .ofs_delta => {
1113 // std.log.debug("type={s} size={d}", .{ @tagName(ty), size });
11141115 var offset: usize = 0;
11151116 while (true) {
11161117 const c2: usize = packedobj_fbs.takeByte();
......@@ -1124,7 +1125,6 @@ pub const Repository = struct {
11241125 return r.getDeltadObject(maybe_oid, &packedobj_fbs, size, base_obj);
11251126 },
11261127 .ref_delta => {
1127 // std.log.debug("type={s} size={d}", .{ @tagName(ty), size });
11281128 const base_oid = extras.to_hex(packedobj_fbs.takeSlice(20)[0..20].*);
11291129 const base_obj = (try r.getObject(arena, &base_oid)).?;
11301130 // std.log.debug("base: type={s} content=[{d}]", .{ @tagName(base_obj.type), base_obj.content.len });
......@@ -1141,13 +1141,13 @@ pub const Repository = struct {
11411141 }
11421142
11431143 fn getDeltadObject(r: *Repository, maybe_oid: ?Id, packedobj_fbs: *nio.FixedBufferStream([]const u8), size: usize, base_obj: GitObject) !GitObject {
1144 const compressed_content = packedobj_fbs.rest()[0..size];
1144 const compressed_content = packedobj_fbs.rest();
11451145 var list: std.ArrayListUnmanaged(u8) = .empty;
11461146 defer list.deinit(r.gpa);
11471147 try list.ensureUnusedCapacity(r.gpa, size);
11481148 // try std.compress.flate.inflate.decompress(.zlib, bufr.anyReadable(), list.writer(r.gpa));
11491149 try inflate_decompress(compressed_content, &list, r.gpa);
1150 // std.log.debug("transformation data={d}", .{list.items});
1150 // std.log.debug("transformation data=[{d}]{d}", .{ list.items.len, list.items });
11511151
11521152 var unpackedobj_fbs = nio.FixedBufferStream([]const u8).init(list.items);
11531153
......@@ -1369,7 +1369,6 @@ const z = @cImport({
13691369});
13701370
13711371fn inflate_decompress(in: []const u8, out: *std.ArrayListUnmanaged(u8), allocator: std.mem.Allocator) !void {
1372 // std.log.debug("{x}", .{in});
13731372 var strm: z.z_stream = std.mem.zeroes(z.z_stream);
13741373 {
13751374 const ret: ZlibCode = @enumFromInt(z.inflateInit(&strm));
......@@ -1391,7 +1390,7 @@ fn inflate_decompress(in: []const u8, out: *std.ArrayListUnmanaged(u8), allocato
13911390 strm.next_out = &buf;
13921391 strm.avail_out = buf.len;
13931392 // std.log.debug("inflate_decompress: -> {*} {*} {d} {d}", .{ strm.next_in, strm.next_out, strm.avail_in, strm.avail_out });
1394 const ret: ZlibCode = @enumFromInt(z.inflate(&strm, z.Z_NO_FLUSH));
1393 const ret: ZlibCode = @enumFromInt(z.inflate(&strm, z.Z_FINISH));
13951394 // std.log.debug("inflate_decompress: <- {*} {*} {d} {d} {s}", .{ strm.next_in, strm.next_out, strm.avail_in, strm.avail_out, @tagName(ret) });
13961395 std.debug.assert(ret != .Z_STREAM_ERROR);
13971396 // if (ret == .Z_BUF_ERROR) std.log.err("{s}", .{strm.msg});