authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-06 13:38:03-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-06 13:38:03-08:00
log699063c5a0e1bba14710c76ef5b2ed1cb1343b62
treef2532155b19bb0a44c133c5a4c27e185726e3a62
parente661e78256e195e23ef7ffded47c2256d0a7620f

fetch: implement the fork override


1 files changed, 22 insertions(+), 1 deletions(-)

src/Package/Fetch.zig+22-1
......@@ -142,7 +142,8 @@ pub const JobQueue = struct {
142142 /// Set of hashes that will be additionally fetched even if they are marked
143143 /// as lazy.
144144 unlazy_set: UnlazySet = .{},
145 /// Identifies paths that override all packages in the tree matching
145 /// Identifies paths that override all packages in the tree with matching
146 /// project ids.
146147 fork_set: ForkSet = .{},
147148
148149 pub const Mode = enum {
......@@ -173,6 +174,17 @@ pub const JobQueue = struct {
173174 return a_project_id.eql(&b_project_id);
174175 }
175176 };
177
178 pub const Adapter = struct {
179 pub fn hash(_: @This(), a: Package.ProjectId) u32 {
180 return @truncate(a.hash());
181 }
182
183 pub fn eql(_: @This(), a_project_id: Package.ProjectId, b: Fork, _: usize) bool {
184 const b_project_id: Package.ProjectId = .init(b.manifest.name, b.manifest.id);
185 return a_project_id.eql(&b_project_id);
186 }
187 };
176188 };
177189
178190 pub fn deinit(jq: *JobQueue) void {
......@@ -558,6 +570,15 @@ pub fn run(f: *Fetch) RunError!void {
558570 var resource_buffer: [init_resource_buffer_size]u8 = undefined;
559571
560572 if (remote.hash) |expected_hash| {
573 const expected_project_id: Package.ProjectId = expected_hash.projectId();
574 if (job_queue.fork_set.getKeyPtrAdapted(expected_project_id, @as(JobQueue.Fork.Adapter, .{}))) |fork| {
575 f.package_root = fork.path;
576 f.manifest_ast = fork.manifest_ast;
577 f.manifest = fork.manifest;
578 if (!job_queue.recursive) return;
579 return queueJobsForDeps(f);
580 }
581
561582 const package_root = try job_queue.root_pkg_path.join(arena, expected_hash.toSlice());
562583 if (package_root.root_dir.handle.access(io, package_root.sub_path, .{})) |_| {
563584 assert(f.lazy_status != .unavailable);