╭ changed ───╮ │src/fork.zig│ ╰────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭────────────────────────────────────────────────╮ │62 }; │ │63 │ │64 pub fn create( │ │65 - comptime repo_opts: rp.RepoOpts(.xit), │ │65 + comptime any_opts: rp.AnyRepoOpts(.xit),│ │66 io: std.Io, │ │67 allocator: std.mem.Allocator, │ │68 users_dir: []const u8, │ ╰────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 87 null; │ │ 88 if (existing != null) return error.InvalidPatchDraft; │ │ 89 │ │ 90 - // get the target repo │ │ 90 + // the fork copies the target's db, so it takes the target's hash kind │ │ 91 const target_path = try evt.repoPath(allocator, users_dir, &input.repo_user_id, &input.repo_id); │ │ 92 defer allocator.free(target_path); │ │ 93 - var target_repo = try rp.Repo(.xit, repo_opts).open(io, allocator, .{ .path = target_path, .require_repo_root = true }); │ │ 94 - defer target_repo.deinit(io, allocator); │ │ 93 + var any_target = try rp.AnyRepo(.xit, any_opts).open(io, allocator, .{ .path = target_path, .require_repo_root = true }); │ │ 94 + defer any_target.deinit(io, allocator); │ │ 95 + switch (any_target) { │ │ 96 + inline else => |*target_repo| try copyTarget(target_repo.self_repo_opts, io, allocator, users_dir, target_repo, &user_repo, fork_path, input),│ │ 97 + } │ │ 98 + return fork_path; │ │ 99 +} │ │100 + │ │101 +// copy the target into a new fork at `fork_path` and record its patch and fork events │ │102 +fn copyTarget( │ │103 + comptime repo_opts: rp.RepoOpts(.xit), │ │104 + io: std.Io, │ │105 + allocator: std.mem.Allocator, │ │106 + users_dir: []const u8, │ │107 + target_repo: *rp.Repo(.xit, repo_opts), │ │108 + user_repo: *rp.Repo(.xit, evt.user_repo_opts), │ │109 + fork_path: []const u8, │ │110 + input: CreateInput, │ │111 +) !void { │ │112 if ((try target_repo.readRef(io, .{ .kind = .head, .name = input.target_branch })) == null) return error.TargetNotFound; │ │113 │ │114 // create the fork repo dir │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │234 }}); │ │235 │ │236 // create the fork event │ │220 - try evt.consume(.{ .server = .{ .users_dir = users_dir } }, .user, .xit, evt.user_repo_opts, io, allocator, &user_repo, evt.events_ref, &.{.{│ │237 + try evt.consume(.{ .server = .{ .users_dir = users_dir } }, .user, .xit, evt.user_repo_opts, io, allocator, user_repo, evt.events_ref, &.{.{ │ │238 .id = input.id, │ │239 .timestamp = input.timestamp, │ │240 .author = input.author, │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────╮ │243 .repo_user_id = &input.repo_user_id, │ │244 } }, │ │245 }}); │ │229 - │ │230 - return fork_path; │ │246 } │ │247 │ │248 // tombstone first so a missing fork never remains visible│ ╰───────────────────────────────────────────────────────────────╯