| ... | @@ -1133,7 +1133,7 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype) | ... | @@ -1133,7 +1133,7 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype) |
| 1133 | } | 1133 | } |
| 1134 | @memset(fan_out_table[fan_out_index..], count); | 1134 | @memset(fan_out_table[fan_out_index..], count); |
| 1135 | | 1135 | |
| 1136 | var index_hashed_writer = hashedWriter(index_writer, Sha1.init(.{})); | 1136 | var index_hashed_writer = std.compress.hashedWriter(index_writer, Sha1.init(.{})); |
| 1137 | const writer = index_hashed_writer.writer(); | 1137 | const writer = index_hashed_writer.writer(); |
| 1138 | try writer.writeAll(IndexHeader.signature); | 1138 | try writer.writeAll(IndexHeader.signature); |
| 1139 | try writer.writeInt(u32, IndexHeader.supported_version, .big); | 1139 | try writer.writeInt(u32, IndexHeader.supported_version, .big); |
| ... | @@ -1196,7 +1196,7 @@ fn indexPackFirstPass( | ... | @@ -1196,7 +1196,7 @@ fn indexPackFirstPass( |
| 1196 | .commit, .tree, .blob, .tag => |object| { | 1196 | .commit, .tree, .blob, .tag => |object| { |
| 1197 | var entry_decompress_stream = std.compress.zlib.decompressor(entry_crc32_reader.reader()); | 1197 | var entry_decompress_stream = std.compress.zlib.decompressor(entry_crc32_reader.reader()); |
| 1198 | var entry_counting_reader = std.io.countingReader(entry_decompress_stream.reader()); | 1198 | var entry_counting_reader = std.io.countingReader(entry_decompress_stream.reader()); |
| 1199 | var entry_hashed_writer = hashedWriter(std.io.null_writer, Sha1.init(.{})); | 1199 | var entry_hashed_writer = std.compress.hashedWriter(std.io.null_writer, Sha1.init(.{})); |
| 1200 | const entry_writer = entry_hashed_writer.writer(); | 1200 | const entry_writer = entry_hashed_writer.writer(); |
| 1201 | // The object header is not included in the pack data but is | 1201 | // The object header is not included in the pack data but is |
| 1202 | // part of the object's ID | 1202 | // part of the object's ID |
| ... | @@ -1282,7 +1282,7 @@ fn indexPackHashDelta( | ... | @@ -1282,7 +1282,7 @@ fn indexPackHashDelta( |
| 1282 | const base_data = try resolveDeltaChain(allocator, pack, base_object, delta_offsets.items, cache); | 1282 | const base_data = try resolveDeltaChain(allocator, pack, base_object, delta_offsets.items, cache); |
| 1283 | | 1283 | |
| 1284 | var entry_hasher = Sha1.init(.{}); | 1284 | var entry_hasher = Sha1.init(.{}); |
| 1285 | var entry_hashed_writer = hashedWriter(std.io.null_writer, &entry_hasher); | 1285 | var entry_hashed_writer = std.compress.hashedWriter(std.io.null_writer, &entry_hasher); |
| 1286 | try entry_hashed_writer.writer().print("{s} {}\x00", .{ @tagName(base_object.type), base_data.len }); | 1286 | try entry_hashed_writer.writer().print("{s} {}\x00", .{ @tagName(base_object.type), base_data.len }); |
| 1287 | entry_hasher.update(base_data); | 1287 | entry_hasher.update(base_data); |
| 1288 | return entry_hasher.finalResult(); | 1288 | return entry_hasher.finalResult(); |
| ... | @@ -1394,36 +1394,6 @@ fn expandDelta(base_object: anytype, delta_reader: anytype, writer: anytype) !vo | ... | @@ -1394,36 +1394,6 @@ fn expandDelta(base_object: anytype, delta_reader: anytype, writer: anytype) !vo |
| 1394 | } | 1394 | } |
| 1395 | } | 1395 | } |
| 1396 | | 1396 | |
| 1397 | fn HashedWriter( | | |
| 1398 | comptime WriterType: anytype, | | |
| 1399 | comptime HasherType: anytype, | | |
| 1400 | ) type { | | |
| 1401 | return struct { | | |
| 1402 | child_writer: WriterType, | | |
| 1403 | hasher: HasherType, | | |
| 1404 | | | |
| 1405 | const Error = WriterType.Error; | | |
| 1406 | const Writer = std.io.Writer(*@This(), Error, write); | | |
| 1407 | | | |
| 1408 | fn write(hashed_writer: *@This(), buf: []const u8) Error!usize { | | |
| 1409 | const amt = try hashed_writer.child_writer.write(buf); | | |
| 1410 | hashed_writer.hasher.update(buf); | | |
| 1411 | return amt; | | |
| 1412 | } | | |
| 1413 | | | |
| 1414 | fn writer(hashed_writer: *@This()) Writer { | | |
| 1415 | return .{ .context = hashed_writer }; | | |
| 1416 | } | | |
| 1417 | }; | | |
| 1418 | } | | |
| 1419 | | | |
| 1420 | fn hashedWriter( | | |
| 1421 | writer: anytype, | | |
| 1422 | hasher: anytype, | | |
| 1423 | ) HashedWriter(@TypeOf(writer), @TypeOf(hasher)) { | | |
| 1424 | return .{ .child_writer = writer, .hasher = hasher }; | | |
| 1425 | } | | |
| 1426 | | | |
| 1427 | test "packfile indexing and checkout" { | 1397 | test "packfile indexing and checkout" { |
| 1428 | // To verify the contents of this packfile without using the code in this | 1398 | // To verify the contents of this packfile without using the code in this |
| 1429 | // file: | 1399 | // file: |