authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-19 22:23:41-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:50-07:00
log97bde94e360cc95206edca478a9dbbc5a0e75264
tree8220ed44c33ff7db9f6d480df2f979fa102252e7
parent6d1b2c7f64fd1a1c671f357cff96b3dd39612857

compiler: upgrade unit tests to new API


2 files changed, 50 insertions(+), 37 deletions(-)

src/Package/Fetch.zig+13-5
...@@ -2069,6 +2069,7 @@ test "tarball with duplicate paths" {...@@ -2069,6 +2069,7 @@ test "tarball with duplicate paths" {
2069 //2069 //
20702070
2071 const gpa = std.testing.allocator;2071 const gpa = std.testing.allocator;
2072 const io = std.testing.io;
2072 var tmp = std.testing.tmpDir(.{});2073 var tmp = std.testing.tmpDir(.{});
2073 defer tmp.cleanup();2074 defer tmp.cleanup();
20742075
...@@ -2079,7 +2080,7 @@ test "tarball with duplicate paths" {...@@ -2079,7 +2080,7 @@ test "tarball with duplicate paths" {
20792080
2080 // Run tarball fetch, expect to fail2081 // Run tarball fetch, expect to fail
2081 var fb: TestFetchBuilder = undefined;2082 var fb: TestFetchBuilder = undefined;
2082 var fetch = try fb.build(gpa, tmp.dir, tarball_path);2083 var fetch = try fb.build(gpa, io, tmp.dir, tarball_path);
2083 defer fb.deinit();2084 defer fb.deinit();
2084 try std.testing.expectError(error.FetchFailed, fetch.run());2085 try std.testing.expectError(error.FetchFailed, fetch.run());
20852086
...@@ -2101,6 +2102,7 @@ test "tarball with excluded duplicate paths" {...@@ -2101,6 +2102,7 @@ test "tarball with excluded duplicate paths" {
2101 //2102 //
21022103
2103 const gpa = std.testing.allocator;2104 const gpa = std.testing.allocator;
2105 const io = std.testing.io;
2104 var tmp = std.testing.tmpDir(.{});2106 var tmp = std.testing.tmpDir(.{});
2105 defer tmp.cleanup();2107 defer tmp.cleanup();
21062108
...@@ -2111,7 +2113,7 @@ test "tarball with excluded duplicate paths" {...@@ -2111,7 +2113,7 @@ test "tarball with excluded duplicate paths" {
21112113
2112 // Run tarball fetch, should succeed2114 // Run tarball fetch, should succeed
2113 var fb: TestFetchBuilder = undefined;2115 var fb: TestFetchBuilder = undefined;
2114 var fetch = try fb.build(gpa, tmp.dir, tarball_path);2116 var fetch = try fb.build(gpa, io, tmp.dir, tarball_path);
2115 defer fb.deinit();2117 defer fb.deinit();
2116 try fetch.run();2118 try fetch.run();
21172119
...@@ -2145,6 +2147,8 @@ test "tarball without root folder" {...@@ -2145,6 +2147,8 @@ test "tarball without root folder" {
2145 //2147 //
21462148
2147 const gpa = std.testing.allocator;2149 const gpa = std.testing.allocator;
2150 const io = std.testing.io;
2151
2148 var tmp = std.testing.tmpDir(.{});2152 var tmp = std.testing.tmpDir(.{});
2149 defer tmp.cleanup();2153 defer tmp.cleanup();
21502154
...@@ -2155,7 +2159,7 @@ test "tarball without root folder" {...@@ -2155,7 +2159,7 @@ test "tarball without root folder" {
21552159
2156 // Run tarball fetch, should succeed2160 // Run tarball fetch, should succeed
2157 var fb: TestFetchBuilder = undefined;2161 var fb: TestFetchBuilder = undefined;
2158 var fetch = try fb.build(gpa, tmp.dir, tarball_path);2162 var fetch = try fb.build(gpa, io, tmp.dir, tarball_path);
2159 defer fb.deinit();2163 defer fb.deinit();
2160 try fetch.run();2164 try fetch.run();
21612165
...@@ -2176,6 +2180,8 @@ test "tarball without root folder" {...@@ -2176,6 +2180,8 @@ test "tarball without root folder" {
2176test "set executable bit based on file content" {2180test "set executable bit based on file content" {
2177 if (!std.fs.has_executable_bit) return error.SkipZigTest;2181 if (!std.fs.has_executable_bit) return error.SkipZigTest;
2178 const gpa = std.testing.allocator;2182 const gpa = std.testing.allocator;
2183 const io = std.testing.io;
2184
2179 var tmp = std.testing.tmpDir(.{});2185 var tmp = std.testing.tmpDir(.{});
2180 defer tmp.cleanup();2186 defer tmp.cleanup();
21812187
...@@ -2194,7 +2200,7 @@ test "set executable bit based on file content" {...@@ -2194,7 +2200,7 @@ test "set executable bit based on file content" {
2194 // -rwxrwxr-x 17 executables/script2200 // -rwxrwxr-x 17 executables/script
21952201
2196 var fb: TestFetchBuilder = undefined;2202 var fb: TestFetchBuilder = undefined;
2197 var fetch = try fb.build(gpa, tmp.dir, tarball_path);2203 var fetch = try fb.build(gpa, io, tmp.dir, tarball_path);
2198 defer fb.deinit();2204 defer fb.deinit();
21992205
2200 try fetch.run();2206 try fetch.run();
...@@ -2244,13 +2250,14 @@ const TestFetchBuilder = struct {...@@ -2244,13 +2250,14 @@ const TestFetchBuilder = struct {
2244 fn build(2250 fn build(
2245 self: *TestFetchBuilder,2251 self: *TestFetchBuilder,
2246 allocator: std.mem.Allocator,2252 allocator: std.mem.Allocator,
2253 io: Io,
2247 cache_parent_dir: std.fs.Dir,2254 cache_parent_dir: std.fs.Dir,
2248 path_or_url: []const u8,2255 path_or_url: []const u8,
2249 ) !*Fetch {2256 ) !*Fetch {
2250 const cache_dir = try cache_parent_dir.makeOpenPath("zig-global-cache", .{});2257 const cache_dir = try cache_parent_dir.makeOpenPath("zig-global-cache", .{});
22512258
2252 try self.thread_pool.init(.{ .allocator = allocator });2259 try self.thread_pool.init(.{ .allocator = allocator });
2253 self.http_client = .{ .allocator = allocator };2260 self.http_client = .{ .allocator = allocator, .io = io };
2254 self.global_cache_directory = .{ .handle = cache_dir, .path = null };2261 self.global_cache_directory = .{ .handle = cache_dir, .path = null };
22552262
2256 self.job_queue = .{2263 self.job_queue = .{
...@@ -2266,6 +2273,7 @@ const TestFetchBuilder = struct {...@@ -2266,6 +2273,7 @@ const TestFetchBuilder = struct {
22662273
2267 self.fetch = .{2274 self.fetch = .{
2268 .arena = std.heap.ArenaAllocator.init(allocator),2275 .arena = std.heap.ArenaAllocator.init(allocator),
2276 .io = io,
2269 .location = .{ .path_or_url = path_or_url },2277 .location = .{ .path_or_url = path_or_url },
2270 .location_tok = 0,2278 .location_tok = 0,
2271 .hash_tok = .none,2279 .hash_tok = .none,
src/Package/Fetch/git.zig+37-32
...@@ -5,6 +5,7 @@...@@ -5,6 +5,7 @@
5//! a package.5//! a package.
66
7const std = @import("std");7const std = @import("std");
8const Io = std.Io;
8const mem = std.mem;9const mem = std.mem;
9const testing = std.testing;10const testing = std.testing;
10const Allocator = mem.Allocator;11const Allocator = mem.Allocator;
...@@ -67,8 +68,8 @@ pub const Oid = union(Format) {...@@ -67,8 +68,8 @@ pub const Oid = union(Format) {
67 };68 };
6869
69 const Hashing = union(Format) {70 const Hashing = union(Format) {
70 sha1: std.Io.Writer.Hashing(Sha1),71 sha1: Io.Writer.Hashing(Sha1),
71 sha256: std.Io.Writer.Hashing(Sha256),72 sha256: Io.Writer.Hashing(Sha256),
7273
73 fn init(oid_format: Format, buffer: []u8) Hashing {74 fn init(oid_format: Format, buffer: []u8) Hashing {
74 return switch (oid_format) {75 return switch (oid_format) {
...@@ -77,7 +78,7 @@ pub const Oid = union(Format) {...@@ -77,7 +78,7 @@ pub const Oid = union(Format) {
77 };78 };
78 }79 }
7980
80 fn writer(h: *@This()) *std.Io.Writer {81 fn writer(h: *@This()) *Io.Writer {
81 return switch (h.*) {82 return switch (h.*) {
82 inline else => |*inner| &inner.writer,83 inline else => |*inner| &inner.writer,
83 };84 };
...@@ -100,7 +101,7 @@ pub const Oid = union(Format) {...@@ -100,7 +101,7 @@ pub const Oid = union(Format) {
100 };101 };
101 }102 }
102103
103 pub fn readBytes(oid_format: Format, reader: *std.Io.Reader) !Oid {104 pub fn readBytes(oid_format: Format, reader: *Io.Reader) !Oid {
104 return switch (oid_format) {105 return switch (oid_format) {
105 inline else => |tag| @unionInit(Oid, @tagName(tag), (try reader.takeArray(tag.byteLength())).*),106 inline else => |tag| @unionInit(Oid, @tagName(tag), (try reader.takeArray(tag.byteLength())).*),
106 };107 };
...@@ -146,7 +147,7 @@ pub const Oid = union(Format) {...@@ -146,7 +147,7 @@ pub const Oid = union(Format) {
146 } else error.InvalidOid;147 } else error.InvalidOid;
147 }148 }
148149
149 pub fn format(oid: Oid, writer: *std.Io.Writer) std.Io.Writer.Error!void {150 pub fn format(oid: Oid, writer: *Io.Writer) Io.Writer.Error!void {
150 try writer.print("{x}", .{oid.slice()});151 try writer.print("{x}", .{oid.slice()});
151 }152 }
152153
...@@ -594,7 +595,7 @@ pub const Packet = union(enum) {...@@ -594,7 +595,7 @@ pub const Packet = union(enum) {
594 pub const max_data_length = 65516;595 pub const max_data_length = 65516;
595596
596 /// Reads a packet in pkt-line format.597 /// Reads a packet in pkt-line format.
597 fn read(reader: *std.Io.Reader) !Packet {598 fn read(reader: *Io.Reader) !Packet {
598 const packet: Packet = try .peek(reader);599 const packet: Packet = try .peek(reader);
599 switch (packet) {600 switch (packet) {
600 .data => |data| reader.toss(data.len),601 .data => |data| reader.toss(data.len),
...@@ -605,7 +606,7 @@ pub const Packet = union(enum) {...@@ -605,7 +606,7 @@ pub const Packet = union(enum) {
605606
606 /// Consumes the header of a pkt-line packet and reads any associated data607 /// Consumes the header of a pkt-line packet and reads any associated data
607 /// into the reader's buffer, but does not consume the data.608 /// into the reader's buffer, but does not consume the data.
608 fn peek(reader: *std.Io.Reader) !Packet {609 fn peek(reader: *Io.Reader) !Packet {
609 const length = std.fmt.parseUnsigned(u16, try reader.take(4), 16) catch return error.InvalidPacket;610 const length = std.fmt.parseUnsigned(u16, try reader.take(4), 16) catch return error.InvalidPacket;
610 switch (length) {611 switch (length) {
611 0 => return .flush,612 0 => return .flush,
...@@ -618,7 +619,7 @@ pub const Packet = union(enum) {...@@ -618,7 +619,7 @@ pub const Packet = union(enum) {
618 }619 }
619620
620 /// Writes a packet in pkt-line format.621 /// Writes a packet in pkt-line format.
621 fn write(packet: Packet, writer: *std.Io.Writer) !void {622 fn write(packet: Packet, writer: *Io.Writer) !void {
622 switch (packet) {623 switch (packet) {
623 .flush => try writer.writeAll("0000"),624 .flush => try writer.writeAll("0000"),
624 .delimiter => try writer.writeAll("0001"),625 .delimiter => try writer.writeAll("0001"),
...@@ -812,7 +813,7 @@ pub const Session = struct {...@@ -812,7 +813,7 @@ pub const Session = struct {
812813
813 const CapabilityIterator = struct {814 const CapabilityIterator = struct {
814 request: std.http.Client.Request,815 request: std.http.Client.Request,
815 reader: *std.Io.Reader,816 reader: *Io.Reader,
816 decompress: std.http.Decompress,817 decompress: std.http.Decompress,
817818
818 const Capability = struct {819 const Capability = struct {
...@@ -869,7 +870,7 @@ pub const Session = struct {...@@ -869,7 +870,7 @@ pub const Session = struct {
869 upload_pack_uri.query = null;870 upload_pack_uri.query = null;
870 upload_pack_uri.fragment = null;871 upload_pack_uri.fragment = null;
871872
872 var body: std.Io.Writer = .fixed(options.buffer);873 var body: Io.Writer = .fixed(options.buffer);
873 try Packet.write(.{ .data = "command=ls-refs\n" }, &body);874 try Packet.write(.{ .data = "command=ls-refs\n" }, &body);
874 if (session.supports_agent) {875 if (session.supports_agent) {
875 try Packet.write(.{ .data = agent_capability }, &body);876 try Packet.write(.{ .data = agent_capability }, &body);
...@@ -918,7 +919,7 @@ pub const Session = struct {...@@ -918,7 +919,7 @@ pub const Session = struct {
918 pub const RefIterator = struct {919 pub const RefIterator = struct {
919 format: Oid.Format,920 format: Oid.Format,
920 request: std.http.Client.Request,921 request: std.http.Client.Request,
921 reader: *std.Io.Reader,922 reader: *Io.Reader,
922 decompress: std.http.Decompress,923 decompress: std.http.Decompress,
923924
924 pub const Ref = struct {925 pub const Ref = struct {
...@@ -986,7 +987,7 @@ pub const Session = struct {...@@ -986,7 +987,7 @@ pub const Session = struct {
986 upload_pack_uri.query = null;987 upload_pack_uri.query = null;
987 upload_pack_uri.fragment = null;988 upload_pack_uri.fragment = null;
988989
989 var body: std.Io.Writer = .fixed(response_buffer);990 var body: Io.Writer = .fixed(response_buffer);
990 try Packet.write(.{ .data = "command=fetch\n" }, &body);991 try Packet.write(.{ .data = "command=fetch\n" }, &body);
991 if (session.supports_agent) {992 if (session.supports_agent) {
992 try Packet.write(.{ .data = agent_capability }, &body);993 try Packet.write(.{ .data = agent_capability }, &body);
...@@ -1068,8 +1069,8 @@ pub const Session = struct {...@@ -1068,8 +1069,8 @@ pub const Session = struct {
10681069
1069 pub const FetchStream = struct {1070 pub const FetchStream = struct {
1070 request: std.http.Client.Request,1071 request: std.http.Client.Request,
1071 input: *std.Io.Reader,1072 input: *Io.Reader,
1072 reader: std.Io.Reader,1073 reader: Io.Reader,
1073 err: ?Error = null,1074 err: ?Error = null,
1074 remaining_len: usize,1075 remaining_len: usize,
1075 decompress: std.http.Decompress,1076 decompress: std.http.Decompress,
...@@ -1094,7 +1095,7 @@ pub const Session = struct {...@@ -1094,7 +1095,7 @@ pub const Session = struct {
1094 _,1095 _,
1095 };1096 };
10961097
1097 pub fn stream(r: *std.Io.Reader, w: *std.Io.Writer, limit: std.Io.Limit) std.Io.Reader.StreamError!usize {1098 pub fn stream(r: *Io.Reader, w: *Io.Writer, limit: Io.Limit) Io.Reader.StreamError!usize {
1098 const fs: *FetchStream = @alignCast(@fieldParentPtr("reader", r));1099 const fs: *FetchStream = @alignCast(@fieldParentPtr("reader", r));
1099 const input = fs.input;1100 const input = fs.input;
1100 if (fs.remaining_len == 0) {1101 if (fs.remaining_len == 0) {
...@@ -1139,7 +1140,7 @@ const PackHeader = struct {...@@ -1139,7 +1140,7 @@ const PackHeader = struct {
1139 const signature = "PACK";1140 const signature = "PACK";
1140 const supported_version = 2;1141 const supported_version = 2;
11411142
1142 fn read(reader: *std.Io.Reader) !PackHeader {1143 fn read(reader: *Io.Reader) !PackHeader {
1143 const actual_signature = reader.take(4) catch |e| switch (e) {1144 const actual_signature = reader.take(4) catch |e| switch (e) {
1144 error.EndOfStream => return error.InvalidHeader,1145 error.EndOfStream => return error.InvalidHeader,
1145 else => |other| return other,1146 else => |other| return other,
...@@ -1202,7 +1203,7 @@ const EntryHeader = union(Type) {...@@ -1202,7 +1203,7 @@ const EntryHeader = union(Type) {
1202 };1203 };
1203 }1204 }
12041205
1205 fn read(format: Oid.Format, reader: *std.Io.Reader) !EntryHeader {1206 fn read(format: Oid.Format, reader: *Io.Reader) !EntryHeader {
1206 const InitialByte = packed struct { len: u4, type: u3, has_next: bool };1207 const InitialByte = packed struct { len: u4, type: u3, has_next: bool };
1207 const initial: InitialByte = @bitCast(reader.takeByte() catch |e| switch (e) {1208 const initial: InitialByte = @bitCast(reader.takeByte() catch |e| switch (e) {
1208 error.EndOfStream => return error.InvalidFormat,1209 error.EndOfStream => return error.InvalidFormat,
...@@ -1231,7 +1232,7 @@ const EntryHeader = union(Type) {...@@ -1231,7 +1232,7 @@ const EntryHeader = union(Type) {
1231 }1232 }
1232};1233};
12331234
1234fn readOffsetVarInt(r: *std.Io.Reader) !u64 {1235fn readOffsetVarInt(r: *Io.Reader) !u64 {
1235 const Byte = packed struct { value: u7, has_next: bool };1236 const Byte = packed struct { value: u7, has_next: bool };
1236 var b: Byte = @bitCast(try r.takeByte());1237 var b: Byte = @bitCast(try r.takeByte());
1237 var value: u64 = b.value;1238 var value: u64 = b.value;
...@@ -1250,7 +1251,7 @@ const IndexHeader = struct {...@@ -1250,7 +1251,7 @@ const IndexHeader = struct {
1250 const supported_version = 2;1251 const supported_version = 2;
1251 const size = 4 + 4 + @sizeOf([256]u32);1252 const size = 4 + 4 + @sizeOf([256]u32);
12521253
1253 fn read(index_header: *IndexHeader, reader: *std.Io.Reader) !void {1254 fn read(index_header: *IndexHeader, reader: *Io.Reader) !void {
1254 const sig = try reader.take(4);1255 const sig = try reader.take(4);
1255 if (!mem.eql(u8, sig, signature)) return error.InvalidHeader;1256 if (!mem.eql(u8, sig, signature)) return error.InvalidHeader;
1256 const version = try reader.takeInt(u32, .big);1257 const version = try reader.takeInt(u32, .big);
...@@ -1324,7 +1325,7 @@ pub fn indexPack(...@@ -1324,7 +1325,7 @@ pub fn indexPack(
1324 }1325 }
1325 @memset(fan_out_table[fan_out_index..], count);1326 @memset(fan_out_table[fan_out_index..], count);
13261327
1327 var index_hashed_writer = std.Io.Writer.hashed(&index_writer.interface, Oid.Hasher.init(format), &.{});1328 var index_hashed_writer = Io.Writer.hashed(&index_writer.interface, Oid.Hasher.init(format), &.{});
1328 const writer = &index_hashed_writer.writer;1329 const writer = &index_hashed_writer.writer;
1329 try writer.writeAll(IndexHeader.signature);1330 try writer.writeAll(IndexHeader.signature);
1330 try writer.writeInt(u32, IndexHeader.supported_version, .big);1331 try writer.writeInt(u32, IndexHeader.supported_version, .big);
...@@ -1489,14 +1490,14 @@ fn resolveDeltaChain(...@@ -1489,14 +1490,14 @@ fn resolveDeltaChain(
1489 const delta_header = try EntryHeader.read(format, &pack.interface);1490 const delta_header = try EntryHeader.read(format, &pack.interface);
1490 const delta_data = try readObjectRaw(allocator, &pack.interface, delta_header.uncompressedLength());1491 const delta_data = try readObjectRaw(allocator, &pack.interface, delta_header.uncompressedLength());
1491 defer allocator.free(delta_data);1492 defer allocator.free(delta_data);
1492 var delta_reader: std.Io.Reader = .fixed(delta_data);1493 var delta_reader: Io.Reader = .fixed(delta_data);
1493 _ = try delta_reader.takeLeb128(u64); // base object size1494 _ = try delta_reader.takeLeb128(u64); // base object size
1494 const expanded_size = try delta_reader.takeLeb128(u64);1495 const expanded_size = try delta_reader.takeLeb128(u64);
14951496
1496 const expanded_alloc_size = std.math.cast(usize, expanded_size) orelse return error.ObjectTooLarge;1497 const expanded_alloc_size = std.math.cast(usize, expanded_size) orelse return error.ObjectTooLarge;
1497 const expanded_data = try allocator.alloc(u8, expanded_alloc_size);1498 const expanded_data = try allocator.alloc(u8, expanded_alloc_size);
1498 errdefer allocator.free(expanded_data);1499 errdefer allocator.free(expanded_data);
1499 var expanded_delta_stream: std.Io.Writer = .fixed(expanded_data);1500 var expanded_delta_stream: Io.Writer = .fixed(expanded_data);
1500 try expandDelta(base_data, &delta_reader, &expanded_delta_stream);1501 try expandDelta(base_data, &delta_reader, &expanded_delta_stream);
1501 if (expanded_delta_stream.end != expanded_size) return error.InvalidObject;1502 if (expanded_delta_stream.end != expanded_size) return error.InvalidObject;
15021503
...@@ -1509,9 +1510,9 @@ fn resolveDeltaChain(...@@ -1509,9 +1510,9 @@ fn resolveDeltaChain(
1509/// Reads the complete contents of an object from `reader`. This function may1510/// Reads the complete contents of an object from `reader`. This function may
1510/// read more bytes than required from `reader`, so the reader position after1511/// read more bytes than required from `reader`, so the reader position after
1511/// returning is not reliable.1512/// returning is not reliable.
1512fn readObjectRaw(allocator: Allocator, reader: *std.Io.Reader, size: u64) ![]u8 {1513fn readObjectRaw(allocator: Allocator, reader: *Io.Reader, size: u64) ![]u8 {
1513 const alloc_size = std.math.cast(usize, size) orelse return error.ObjectTooLarge;1514 const alloc_size = std.math.cast(usize, size) orelse return error.ObjectTooLarge;
1514 var aw: std.Io.Writer.Allocating = .init(allocator);1515 var aw: Io.Writer.Allocating = .init(allocator);
1515 try aw.ensureTotalCapacity(alloc_size + std.compress.flate.max_window_len);1516 try aw.ensureTotalCapacity(alloc_size + std.compress.flate.max_window_len);
1516 defer aw.deinit();1517 defer aw.deinit();
1517 var decompress: std.compress.flate.Decompress = .init(reader, .zlib, &.{});1518 var decompress: std.compress.flate.Decompress = .init(reader, .zlib, &.{});
...@@ -1523,7 +1524,7 @@ fn readObjectRaw(allocator: Allocator, reader: *std.Io.Reader, size: u64) ![]u8...@@ -1523,7 +1524,7 @@ fn readObjectRaw(allocator: Allocator, reader: *std.Io.Reader, size: u64) ![]u8
1523///1524///
1524/// The format of the delta data is documented in1525/// The format of the delta data is documented in
1525/// [pack-format](https://git-scm.com/docs/pack-format).1526/// [pack-format](https://git-scm.com/docs/pack-format).
1526fn expandDelta(base_object: []const u8, delta_reader: *std.Io.Reader, writer: *std.Io.Writer) !void {1527fn expandDelta(base_object: []const u8, delta_reader: *Io.Reader, writer: *Io.Writer) !void {
1527 while (true) {1528 while (true) {
1528 const inst: packed struct { value: u7, copy: bool } = @bitCast(delta_reader.takeByte() catch |e| switch (e) {1529 const inst: packed struct { value: u7, copy: bool } = @bitCast(delta_reader.takeByte() catch |e| switch (e) {
1529 error.EndOfStream => return,1530 error.EndOfStream => return,
...@@ -1576,7 +1577,7 @@ fn expandDelta(base_object: []const u8, delta_reader: *std.Io.Reader, writer: *s...@@ -1576,7 +1577,7 @@ fn expandDelta(base_object: []const u8, delta_reader: *std.Io.Reader, writer: *s
1576/// - SHA-1: `dd582c0720819ab7130b103635bd7271b9fd4feb`1577/// - SHA-1: `dd582c0720819ab7130b103635bd7271b9fd4feb`
1577/// - SHA-256: `7f444a92bd4572ee4a28b2c63059924a9ca1829138553ef3e7c41ee159afae7a`1578/// - SHA-256: `7f444a92bd4572ee4a28b2c63059924a9ca1829138553ef3e7c41ee159afae7a`
1578/// 4. `git checkout $commit`1579/// 4. `git checkout $commit`
1579fn runRepositoryTest(comptime format: Oid.Format, head_commit: []const u8) !void {1580fn runRepositoryTest(io: Io, comptime format: Oid.Format, head_commit: []const u8) !void {
1580 const testrepo_pack = @embedFile("git/testdata/testrepo-" ++ @tagName(format) ++ ".pack");1581 const testrepo_pack = @embedFile("git/testdata/testrepo-" ++ @tagName(format) ++ ".pack");
15811582
1582 var git_dir = testing.tmpDir(.{});1583 var git_dir = testing.tmpDir(.{});
...@@ -1586,7 +1587,7 @@ fn runRepositoryTest(comptime format: Oid.Format, head_commit: []const u8) !void...@@ -1586,7 +1587,7 @@ fn runRepositoryTest(comptime format: Oid.Format, head_commit: []const u8) !void
1586 try pack_file.writeAll(testrepo_pack);1587 try pack_file.writeAll(testrepo_pack);
15871588
1588 var pack_file_buffer: [2000]u8 = undefined;1589 var pack_file_buffer: [2000]u8 = undefined;
1589 var pack_file_reader = pack_file.reader(&pack_file_buffer);1590 var pack_file_reader = pack_file.reader(io, &pack_file_buffer);
15901591
1591 var index_file = try git_dir.dir.createFile("testrepo.idx", .{ .read = true });1592 var index_file = try git_dir.dir.createFile("testrepo.idx", .{ .read = true });
1592 defer index_file.close();1593 defer index_file.close();
...@@ -1608,7 +1609,7 @@ fn runRepositoryTest(comptime format: Oid.Format, head_commit: []const u8) !void...@@ -1608,7 +1609,7 @@ fn runRepositoryTest(comptime format: Oid.Format, head_commit: []const u8) !void
1608 try testing.expectEqualSlices(u8, testrepo_idx, index_file_data);1609 try testing.expectEqualSlices(u8, testrepo_idx, index_file_data);
1609 }1610 }
16101611
1611 var index_file_reader = index_file.reader(&index_file_buffer);1612 var index_file_reader = index_file.reader(io, &index_file_buffer);
1612 var repository: Repository = undefined;1613 var repository: Repository = undefined;
1613 try repository.init(testing.allocator, format, &pack_file_reader, &index_file_reader);1614 try repository.init(testing.allocator, format, &pack_file_reader, &index_file_reader);
1614 defer repository.deinit();1615 defer repository.deinit();
...@@ -1687,11 +1688,11 @@ fn runRepositoryTest(comptime format: Oid.Format, head_commit: []const u8) !void...@@ -1687,11 +1688,11 @@ fn runRepositoryTest(comptime format: Oid.Format, head_commit: []const u8) !void
1687const skip_checksums = true;1688const skip_checksums = true;
16881689
1689test "SHA-1 packfile indexing and checkout" {1690test "SHA-1 packfile indexing and checkout" {
1690 try runRepositoryTest(.sha1, "dd582c0720819ab7130b103635bd7271b9fd4feb");1691 try runRepositoryTest(std.testing.io, .sha1, "dd582c0720819ab7130b103635bd7271b9fd4feb");
1691}1692}
16921693
1693test "SHA-256 packfile indexing and checkout" {1694test "SHA-256 packfile indexing and checkout" {
1694 try runRepositoryTest(.sha256, "7f444a92bd4572ee4a28b2c63059924a9ca1829138553ef3e7c41ee159afae7a");1695 try runRepositoryTest(std.testing.io, .sha256, "7f444a92bd4572ee4a28b2c63059924a9ca1829138553ef3e7c41ee159afae7a");
1695}1696}
16961697
1697/// Checks out a commit of a packfile. Intended for experimenting with and1698/// Checks out a commit of a packfile. Intended for experimenting with and
...@@ -1699,6 +1700,10 @@ test "SHA-256 packfile indexing and checkout" {...@@ -1699,6 +1700,10 @@ test "SHA-256 packfile indexing and checkout" {
1699pub fn main() !void {1700pub fn main() !void {
1700 const allocator = std.heap.smp_allocator;1701 const allocator = std.heap.smp_allocator;
17011702
1703 var threaded: Io.Threaded = .init(allocator);
1704 defer threaded.deinit();
1705 const io = threaded.io();
1706
1702 const args = try std.process.argsAlloc(allocator);1707 const args = try std.process.argsAlloc(allocator);
1703 defer std.process.argsFree(allocator, args);1708 defer std.process.argsFree(allocator, args);
1704 if (args.len != 5) {1709 if (args.len != 5) {
...@@ -1710,7 +1715,7 @@ pub fn main() !void {...@@ -1710,7 +1715,7 @@ pub fn main() !void {
1710 var pack_file = try std.fs.cwd().openFile(args[2], .{});1715 var pack_file = try std.fs.cwd().openFile(args[2], .{});
1711 defer pack_file.close();1716 defer pack_file.close();
1712 var pack_file_buffer: [4096]u8 = undefined;1717 var pack_file_buffer: [4096]u8 = undefined;
1713 var pack_file_reader = pack_file.reader(&pack_file_buffer);1718 var pack_file_reader = pack_file.reader(io, &pack_file_buffer);
17141719
1715 const commit = try Oid.parse(format, args[3]);1720 const commit = try Oid.parse(format, args[3]);
1716 var worktree = try std.fs.cwd().makeOpenPath(args[4], .{});1721 var worktree = try std.fs.cwd().makeOpenPath(args[4], .{});
...@@ -1727,7 +1732,7 @@ pub fn main() !void {...@@ -1727,7 +1732,7 @@ pub fn main() !void {
1727 try indexPack(allocator, format, &pack_file_reader, &index_file_writer);1732 try indexPack(allocator, format, &pack_file_reader, &index_file_writer);
17281733
1729 std.debug.print("Starting checkout...\n", .{});1734 std.debug.print("Starting checkout...\n", .{});
1730 var index_file_reader = index_file.reader(&index_file_buffer);1735 var index_file_reader = index_file.reader(io, &index_file_buffer);
1731 var repository: Repository = undefined;1736 var repository: Repository = undefined;
1732 try repository.init(allocator, format, &pack_file_reader, &index_file_reader);1737 try repository.init(allocator, format, &pack_file_reader, &index_file_reader);
1733 defer repository.deinit();1738 defer repository.deinit();