authorgravatar for ian@ianjohnson.devIan Johnson <ian@ianjohnson.dev> 2024-11-23 09:58:35-05:00
committergravatar for ian@ianjohnson.devIan Johnson <ian@ianjohnson.dev> 2024-12-13 08:49:45-05:00
log62cc81a63afcc1c4bb1863c22d247169a2ab8136
tree6c4adc36061e0b3cfb414610b73773a8698793b0
parentde3db8a1a6e9e7dce0489fd2eedca6e570bece79

Remove copy of `HashedWriter`

It was added to the standard library in #18733.

1 files changed, 3 insertions(+), 33 deletions(-)

src/Package/Fetch/git.zig+3-33
...@@ -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);
11351135
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 is1201 // The object header is not included in the pack data but is
1202 // part of the object's ID1202 // 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);
12831283
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}
13961396
1397fn 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
1420fn hashedWriter(
1421 writer: anytype,
1422 hasher: anytype,
1423) HashedWriter(@TypeOf(writer), @TypeOf(hasher)) {
1424 return .{ .child_writer = writer, .hasher = hasher };
1425}
1426
1427test "packfile indexing and checkout" {1397test "packfile indexing and checkout" {
1428 // To verify the contents of this packfile without using the code in this1398 // To verify the contents of this packfile without using the code in this
1429 // file:1399 // file: