| ... | @@ -1046,7 +1046,8 @@ pub const Repository = struct { | ... | @@ -1046,7 +1046,8 @@ pub const Repository = struct { |
| 1046 | @memcpy(pack_path[13..][0..idx_path.len], idx_path); | 1046 | @memcpy(pack_path[13..][0..idx_path.len], idx_path); |
| 1047 | @memcpy(pack_path[13..][idx_path.len - 4 ..][0..5], ".pack"); | 1047 | @memcpy(pack_path[13..][idx_path.len - 4 ..][0..5], ".pack"); |
| 1048 | const pack_name_nidx = std.mem.indexOfScalar(u8, &pack_path, 0).?; | 1048 | 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, .{}); |
| 1050 | defer pack_file.close(); | 1051 | defer pack_file.close(); |
| 1051 | const pack_content = try pack_file.mmap(); | 1052 | const pack_content = try pack_file.mmap(); |
| 1052 | errdefer nfs.munmap(pack_content); | 1053 | errdefer nfs.munmap(pack_content); |
| ... | @@ -1087,6 +1088,7 @@ pub const Repository = struct { | ... | @@ -1087,6 +1088,7 @@ pub const Repository = struct { |
| 1087 | size += (c & 0x7f) << shift; | 1088 | size += (c & 0x7f) << shift; |
| 1088 | shift += 7; | 1089 | shift += 7; |
| 1089 | } | 1090 | } |
| | 1091 | // std.log.debug("type={s} size={d}", .{ @tagName(ty), size }); |
| 1090 | const t2 = tracer.trace(@src(), " 2 {s} {d}", .{ @tagName(ty), size }); | 1092 | const t2 = tracer.trace(@src(), " 2 {s} {d}", .{ @tagName(ty), size }); |
| 1091 | defer t2.end(); | 1093 | defer t2.end(); |
| 1092 | switch (ty) { | 1094 | switch (ty) { |
| ... | @@ -1097,7 +1099,7 @@ pub const Repository = struct { | ... | @@ -1097,7 +1099,7 @@ pub const Repository = struct { |
| 1097 | unreachable; | 1099 | unreachable; |
| 1098 | }, | 1100 | }, |
| 1099 | .commit, .tree, .blob, .tag => { | 1101 | .commit, .tree, .blob, .tag => { |
| 1100 | const compressed_content = packedobj_fbs.rest()[0..size]; | 1102 | const compressed_content = packedobj_fbs.rest(); |
| 1101 | var list: std.ArrayListUnmanaged(u8) = .empty; | 1103 | var list: std.ArrayListUnmanaged(u8) = .empty; |
| 1102 | errdefer list.deinit(r.gpa); | 1104 | errdefer list.deinit(r.gpa); |
| 1103 | try list.ensureUnusedCapacity(r.gpa, 512); | 1105 | try list.ensureUnusedCapacity(r.gpa, 512); |
| ... | @@ -1110,7 +1112,6 @@ pub const Repository = struct { | ... | @@ -1110,7 +1112,6 @@ pub const Repository = struct { |
| 1110 | return obj; | 1112 | return obj; |
| 1111 | }, | 1113 | }, |
| 1112 | .ofs_delta => { | 1114 | .ofs_delta => { |
| 1113 | // std.log.debug("type={s} size={d}", .{ @tagName(ty), size }); | | |
| 1114 | var offset: usize = 0; | 1115 | var offset: usize = 0; |
| 1115 | while (true) { | 1116 | while (true) { |
| 1116 | const c2: usize = packedobj_fbs.takeByte(); | 1117 | const c2: usize = packedobj_fbs.takeByte(); |
| ... | @@ -1124,7 +1125,6 @@ pub const Repository = struct { | ... | @@ -1124,7 +1125,6 @@ pub const Repository = struct { |
| 1124 | return r.getDeltadObject(maybe_oid, &packedobj_fbs, size, base_obj); | 1125 | return r.getDeltadObject(maybe_oid, &packedobj_fbs, size, base_obj); |
| 1125 | }, | 1126 | }, |
| 1126 | .ref_delta => { | 1127 | .ref_delta => { |
| 1127 | // std.log.debug("type={s} size={d}", .{ @tagName(ty), size }); | | |
| 1128 | const base_oid = extras.to_hex(packedobj_fbs.takeSlice(20)[0..20].*); | 1128 | const base_oid = extras.to_hex(packedobj_fbs.takeSlice(20)[0..20].*); |
| 1129 | const base_obj = (try r.getObject(arena, &base_oid)).?; | 1129 | const base_obj = (try r.getObject(arena, &base_oid)).?; |
| 1130 | // std.log.debug("base: type={s} content=[{d}]", .{ @tagName(base_obj.type), base_obj.content.len }); | 1130 | // std.log.debug("base: type={s} content=[{d}]", .{ @tagName(base_obj.type), base_obj.content.len }); |
| ... | @@ -1141,13 +1141,13 @@ pub const Repository = struct { | ... | @@ -1141,13 +1141,13 @@ pub const Repository = struct { |
| 1141 | } | 1141 | } |
| 1142 | | 1142 | |
| 1143 | fn getDeltadObject(r: *Repository, maybe_oid: ?Id, packedobj_fbs: *nio.FixedBufferStream([]const u8), size: usize, base_obj: GitObject) !GitObject { | 1143 | 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(); |
| 1145 | var list: std.ArrayListUnmanaged(u8) = .empty; | 1145 | var list: std.ArrayListUnmanaged(u8) = .empty; |
| 1146 | defer list.deinit(r.gpa); | 1146 | defer list.deinit(r.gpa); |
| 1147 | try list.ensureUnusedCapacity(r.gpa, size); | 1147 | try list.ensureUnusedCapacity(r.gpa, size); |
| 1148 | // try std.compress.flate.inflate.decompress(.zlib, bufr.anyReadable(), list.writer(r.gpa)); | 1148 | // try std.compress.flate.inflate.decompress(.zlib, bufr.anyReadable(), list.writer(r.gpa)); |
| 1149 | try inflate_decompress(compressed_content, &list, r.gpa); | 1149 | 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 }); |
| 1151 | | 1151 | |
| 1152 | var unpackedobj_fbs = nio.FixedBufferStream([]const u8).init(list.items); | 1152 | var unpackedobj_fbs = nio.FixedBufferStream([]const u8).init(list.items); |
| 1153 | | 1153 | |
| ... | @@ -1369,7 +1369,6 @@ const z = @cImport({ | ... | @@ -1369,7 +1369,6 @@ const z = @cImport({ |
| 1369 | }); | 1369 | }); |
| 1370 | | 1370 | |
| 1371 | fn inflate_decompress(in: []const u8, out: *std.ArrayListUnmanaged(u8), allocator: std.mem.Allocator) !void { | 1371 | fn inflate_decompress(in: []const u8, out: *std.ArrayListUnmanaged(u8), allocator: std.mem.Allocator) !void { |
| 1372 | // std.log.debug("{x}", .{in}); | | |
| 1373 | var strm: z.z_stream = std.mem.zeroes(z.z_stream); | 1372 | var strm: z.z_stream = std.mem.zeroes(z.z_stream); |
| 1374 | { | 1373 | { |
| 1375 | const ret: ZlibCode = @enumFromInt(z.inflateInit(&strm)); | 1374 | const ret: ZlibCode = @enumFromInt(z.inflateInit(&strm)); |
| ... | @@ -1391,7 +1390,7 @@ fn inflate_decompress(in: []const u8, out: *std.ArrayListUnmanaged(u8), allocato | ... | @@ -1391,7 +1390,7 @@ fn inflate_decompress(in: []const u8, out: *std.ArrayListUnmanaged(u8), allocato |
| 1391 | strm.next_out = &buf; | 1390 | strm.next_out = &buf; |
| 1392 | strm.avail_out = buf.len; | 1391 | strm.avail_out = buf.len; |
| 1393 | // std.log.debug("inflate_decompress: -> {*} {*} {d} {d}", .{ strm.next_in, strm.next_out, strm.avail_in, strm.avail_out }); | 1392 | // 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)); |
| 1395 | // std.log.debug("inflate_decompress: <- {*} {*} {d} {d} {s}", .{ strm.next_in, strm.next_out, strm.avail_in, strm.avail_out, @tagName(ret) }); | 1394 | // std.log.debug("inflate_decompress: <- {*} {*} {d} {d} {s}", .{ strm.next_in, strm.next_out, strm.avail_in, strm.avail_out, @tagName(ret) }); |
| 1396 | std.debug.assert(ret != .Z_STREAM_ERROR); | 1395 | std.debug.assert(ret != .Z_STREAM_ERROR); |
| 1397 | // if (ret == .Z_BUF_ERROR) std.log.err("{s}", .{strm.msg}); | 1396 | // if (ret == .Z_BUF_ERROR) std.log.err("{s}", .{strm.msg}); |