| ... | ... | @@ -816,18 +816,18 @@ pub const Repository = struct { |
| 816 | 816 | defer objfile.close(); |
| 817 | 817 | const compressed_content = try objfile.mmap(); |
| 818 | 818 | defer nfs.munmap(compressed_content); |
| 819 | | var list: std.ArrayListUnmanaged(u8) = .empty; |
| 820 | | errdefer list.deinit(r.gpa); |
| 821 | | try list.ensureUnusedCapacity(r.gpa, 512); |
| 819 | var list: nio.AllocatingWriter = .init(r.gpa); |
| 820 | errdefer list.deinit(); |
| 821 | try list.ensureUnusedCapacity(512); |
| 822 | 822 | // try std.compress.flate.inflate.decompress(.zlib, bufr.anyReadable(), list.writer()); |
| 823 | | try inflate_decompress(compressed_content, &list, r.gpa); |
| 823 | try inflate_decompress(compressed_content, &list); |
| 824 | 824 | const data = list.items; |
| 825 | 825 | const header = data[0..std.mem.indexOfScalar(u8, data, 0).?]; |
| 826 | 826 | const _type_s = header[0..std.mem.indexOfScalar(u8, header, ' ').?]; |
| 827 | 827 | const _type = std.meta.stringToEnum(RefType, _type_s).?; |
| 828 | 828 | const content_len = try extras.parseDigits(u64, header[_type_s.len + 1 ..], 10); |
| 829 | 829 | list.replaceRangeAssumeCapacity(0, header.len + 1, ""); |
| 830 | | const content = try list.toOwnedSlice(r.gpa); |
| 830 | const content = try list.toOwnedSlice(); |
| 831 | 831 | std.debug.assert(content.len == content_len); |
| 832 | 832 | const obj: GitObject = .{ .type = _type, .content = content }; |
| 833 | 833 | if (cache_behavior == .cache) try r.unpacked_loose_objects.put(r.gpa, oid, obj); |
| ... | ... | @@ -959,13 +959,13 @@ pub const Repository = struct { |
| 959 | 959 | }, |
| 960 | 960 | .commit, .tree, .blob, .tag => { |
| 961 | 961 | const compressed_content = packedobj_fbs.rest(); |
| 962 | | var list: std.ArrayListUnmanaged(u8) = .empty; |
| 963 | | errdefer list.deinit(r.gpa); |
| 964 | | try list.ensureUnusedCapacity(r.gpa, 512); |
| 962 | var list: nio.AllocatingWriter = .init(r.gpa); |
| 963 | errdefer list.deinit(); |
| 964 | try list.ensureUnusedCapacity(512); |
| 965 | 965 | // try std.compress.flate.inflate.decompress(.zlib, bufr.anyReadable(), list.writer()); |
| 966 | | try inflate_decompress(compressed_content, &list, r.gpa); |
| 966 | try inflate_decompress(compressed_content, &list); |
| 967 | 967 | const _type = std.meta.stringToEnum(RefType, @tagName(ty)).?; |
| 968 | | const content = try list.toOwnedSlice(r.gpa); |
| 968 | const content = try list.toOwnedSlice(); |
| 969 | 969 | const obj: GitObject = .{ .type = _type, .content = content }; |
| 970 | 970 | if (cache_behavior == .cache) try r.unpacked_objects.put(r.gpa, key, obj); |
| 971 | 971 | return obj; |
| ... | ... | @@ -1001,11 +1001,11 @@ pub const Repository = struct { |
| 1001 | 1001 | |
| 1002 | 1002 | fn getDeltadObject(r: *Repository, maybe_oid: ?Id, key: u64, packedobj_fbs: *nio.FixedBufferStream([]const u8), size: usize, base_obj: GitObject, cache_behavior: CacheBehavior) !GitObject { |
| 1003 | 1003 | const compressed_content = packedobj_fbs.rest(); |
| 1004 | | var list: std.ArrayListUnmanaged(u8) = .empty; |
| 1005 | | defer list.deinit(r.gpa); |
| 1006 | | try list.ensureUnusedCapacity(r.gpa, size); |
| 1004 | var list: nio.AllocatingWriter = .init(r.gpa); |
| 1005 | defer list.deinit(); |
| 1006 | try list.ensureUnusedCapacity(size); |
| 1007 | 1007 | // try std.compress.flate.inflate.decompress(.zlib, bufr.anyReadable(), list.writer(r.gpa)); |
| 1008 | | try inflate_decompress(compressed_content, &list, r.gpa); |
| 1008 | try inflate_decompress(compressed_content, &list); |
| 1009 | 1009 | std.debug.assert(list.items.len == size); |
| 1010 | 1010 | // std.log.debug("maybe_oid={?s} size={d}", .{ maybe_oid, size }); |
| 1011 | 1011 | // std.log.debug("transformation data=[{d}]{d}", .{ list.items.len, list.items }); |
| ... | ... | @@ -1640,7 +1640,7 @@ const z = @cImport({ |
| 1640 | 1640 | @cInclude("zlib.h"); |
| 1641 | 1641 | }); |
| 1642 | 1642 | |
| 1643 | | fn inflate_decompress(in: []const u8, out: *std.ArrayListUnmanaged(u8), allocator: std.mem.Allocator) !void { |
| 1643 | fn inflate_decompress(in: []const u8, out: *nio.AllocatingWriter) !void { |
| 1644 | 1644 | var strm: z.z_stream = std.mem.zeroes(z.z_stream); |
| 1645 | 1645 | { |
| 1646 | 1646 | const ret: ZlibCode = @enumFromInt(z.inflateInit(&strm)); |
| ... | ... | @@ -1672,7 +1672,7 @@ fn inflate_decompress(in: []const u8, out: *std.ArrayListUnmanaged(u8), allocato |
| 1672 | 1672 | // Z_ERRNO |
| 1673 | 1673 | // Z_VERSION_ERROR |
| 1674 | 1674 | std.debug.assert(ret == .Z_OK or ret == .Z_STREAM_END); |
| 1675 | | try out.appendSlice(allocator, buf[0 .. buf.len - strm.avail_out]); |
| 1675 | try out.writeAll(buf[0 .. buf.len - strm.avail_out]); |
| 1676 | 1676 | if (ret == .Z_STREAM_END) break; |
| 1677 | 1677 | } |
| 1678 | 1678 | } |