╭ changed ──╮ │src/try.zig│ ╰───────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────╮ │ 982 _ = try repo.addTag(io, allocator, .{ .name = name }); │ │ 983 n.* += 1; │ │ 984 } │ │ 985 - │ │ 986 -const PatchRevisionFixture = struct { │ │ 987 - id: [evt.event_id_size]u8, │ │ 988 - oid: [hash.hexLen(.sha1)]u8, │ │ 989 - tree_oid: [hash.hexLen(.sha1)]u8, │ │ 990 - timestamp: u64, │ │ 991 - │ │ 992 - fn event(self: *const PatchRevisionFixture, title: []const u8) evt.PatchRev {│ │ 993 - return .{ │ │ 994 - .base_oid = &self.oid, │ │ 995 - .source_oid = &self.oid, │ │ 996 - .target_ref = "refs/heads/master", │ │ 997 - .message = title, │ │ 998 - }; │ │ 999 - } │ │1000 -}; │ │ 985 │ │ 986 fn commitTree( │ │ 987 io: std.Io, │ ╰───────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────╮ │1005 repos_path: []const u8, │ │1006 patch_id: *const [evt.event_id_size]u8, │ │1007 title: []const u8, │ │1008 + author: evt.CommitAuthor, │ │1009 timestamp: u64, │ │1010 random: std.Random, │ │1026 -) !PatchRevisionFixture { │ │1011 +) !void { │ │1012 const patch_hex = std.fmt.bytesToHex(patch_id.*, .lower); │ │1013 const fork_path = try fork.forkPath(allocator, repos_path, &patch_hex);│ │1014 defer allocator.free(fork_path); │ ╰─────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1015 var fork_repo = try rp.Repo(.xit, .{}).open(io, allocator, .{ .path = fork_path, .require_repo_root = true }); │ │1016 defer fork_repo.deinit(io, allocator); │ │1017 │ │1033 - const source_oid = (try fork_repo.readRef(io, fork.ref)) orelse return error.NotFound; │ │1034 - var fixture = PatchRevisionFixture{ │ │1035 - .id = evt.EventWithId.randomId(random), │ │1036 - .oid = source_oid, │ │1037 - .tree_oid = try commitTree(io, allocator, &fork_repo, &source_oid), │ │1038 - .timestamp = timestamp, │ │1018 + const base_oid = (try fork_repo.readRef(io, fork.ref)) orelse return error.NotFound; │ │1019 + const base_tree_oid = try commitTree(io, allocator, &fork_repo, &base_oid); │ │1020 + var source_oid = base_oid; │ │1021 + var fork_dir = try std.Io.Dir.cwd().openDir(io, fork_path, .{}); │ │1022 + defer fork_dir.close(io); │ │1023 + var writer = std.Io.Writer.Allocating.init(allocator); │ │1024 + defer writer.deinit(); │ │1025 + for (0..3) |i| { │ │1026 + writer.clearRetainingCapacity(); │ │1027 + for (0..i + 1) |line| try writer.writer.print("{s}: part {d}\n", .{ title, line + 1 }); │ │1028 + { │ │1029 + const file = try fork_dir.createFile(io, "patch.txt", .{}); │ │1030 + defer file.close(io); │ │1031 + try file.writeStreamingAll(io, writer.written()); │ │1032 + } │ │1033 + try fork_repo.add(io, allocator, &.{"patch.txt"}); │ │1034 + writer.clearRetainingCapacity(); │ │1035 + try writer.writer.print("{s} ({d}/3)", .{ title, i + 1 }); │ │1036 + source_oid = try fork_repo.commit(io, allocator, .{ .message = writer.written(), .timestamp = timestamp + i });│ │1037 + } │ │1038 + const revision_id = evt.EventWithId.randomId(random); │ │1039 + const head_tree_oid = try commitTree(io, allocator, &fork_repo, &source_oid); │ │1040 + const revision: evt.PatchRev = .{ │ │1041 + .base_oid = &base_oid, │ │1042 + .source_oid = &source_oid, │ │1043 + .target_ref = "refs/heads/master", │ │1044 + .message = title, │ │1045 }; │ │1040 - const revision = fixture.event(title); │ │1046 + const revision_timestamp = timestamp + 3; │ │1047 const tree_entries = [_]evt.EventTreeEntry{ │ │1042 - .{ .tree = .{ .name = "base", .oid = &fixture.tree_oid } }, │ │1043 - .{ .tree = .{ .name = "head", .oid = &fixture.tree_oid } }, │ │1048 + .{ .tree = .{ .name = "base", .oid = &base_tree_oid } }, │ │1049 + .{ .tree = .{ .name = "head", .oid = &head_tree_oid } }, │ │1050 }; │ │1051 try evt.consume(.fork, .xit, .{}, io, allocator, &fork_repo, evt.events_ref, &.{.{ │ │1046 - .id = std.fmt.bytesToHex(fixture.id, .lower), │ │1047 - .timestamp = timestamp, │ │1048 - .author = .{ .name = "admin", .email = "admin@example.test" }, │ │1052 + .id = std.fmt.bytesToHex(revision_id, .lower), │ │1053 + .timestamp = revision_timestamp, │ │1054 + .author = author, │ │1055 .tree_entries = &tree_entries, │ │1056 .event = .{ .patchrev = revision }, │ │1057 }}); │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1059 var arena = std.heap.ArenaAllocator.init(allocator); │ │1060 defer arena.deinit(); │ │1061 const moment = try evt.currentMoment(.{}, &fork_repo); │ │1056 - const revision_record = (try evt.PatchRev.readById(evt.EventDB(.sha1), .sha1, moment, &arena, &fixture.id)) orelse return error.NotFound; │ │1062 + const revision_record = (try evt.PatchRev.readById(evt.EventDB(.sha1), .sha1, moment, &arena, &revision_id)) orelse return error.NotFound;│ │1063 const patch_record = (try evt.Patch.readById(evt.EventDB(.sha1), .sha1, moment, &arena, patch_id)) orelse return error.NotFound; │ │1064 var patch = patch_record.event; │ │1059 - patch.revision = evt.Patch.Revision.fromRecord(fixture.id, revision_record); │ │1065 + patch.revision = evt.Patch.Revision.fromRecord(revision_id, revision_record); │ │1066 try evt.consume(.fork, .xit, .{}, io, allocator, &fork_repo, evt.events_ref, &.{.{ │ │1067 .id = patch_hex, │ │1062 - .timestamp = timestamp + 1, │ │1063 - .author = .{ .name = "admin", .email = "admin@example.test" }, │ │1068 + .timestamp = revision_timestamp + 1, │ │1069 + .author = author, │ │1070 .event = .{ .patch = patch }, │ │1071 }}); │ │1066 - return fixture; │ │1072 } │ │1073 │ │1074 fn seedPatches( │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ │1121 │ │1122 const repos_path = try std.fs.path.join(allocator, &.{ server_path, "repos" }); │ │1123 defer allocator.free(repos_path); │ │1124 + const patch_author = evt.CommitAuthor{ .name = "admin", .email = "admin@example.test" };│ │1125 var patch_ids: [patch_data.len][evt.event_id_size]u8 = undefined; │ │1126 for (patch_data, 0..) |patch, i| { │ │1127 + const timestamp: u64 = @intCast(500 + i * 10); │ │1128 patch_ids[i] = evt.EventWithId.randomId(random); │ │1129 const patch_hex = std.fmt.bytesToHex(patch_ids[i], .lower); │ │1130 const path = try fork.create(.{}, io, allocator, repos_path, admin_repo, .{ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1134 .title = patch.title, │ │1135 .description = patch.description, │ │1136 .tags = patch.tags, │ │1130 - .author = .{ .name = "admin", .email = "admin@example.test" }, │ │1131 - .timestamp = @intCast(500 + i * 10), │ │1137 + .author = patch_author, │ │1138 + .timestamp = timestamp, │ │1139 }); │ │1140 allocator.free(path); │ │1134 - const status = patch.status orelse continue; │ │1141 │ │1136 - const revision = try seedPatchRevision(io, allocator, repos_path, &patch_ids[i], patch.title, @intCast(502 + i * 10), random);│ │1142 + try seedPatchRevision(io, allocator, repos_path, &patch_ids[i], patch.title, patch_author, timestamp + 1, random); │ │1143 + const status = patch.status orelse continue; │ │1144 const fork_path = try fork.forkPath(allocator, repos_path, &patch_hex); │ │1145 defer allocator.free(fork_path); │ │1146 try pch.publish(.{}, io, allocator, admin_repo, target_repo, fork_path, .{ │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────╮ │1147 .id = patch_hex, │ │1148 .user_id = user_id.*, │ │1149 .repo_id = repo_id.*, │ │1143 - .author = .{ .name = "admin", .email = "admin@example.test" },│ │1144 - .timestamp = @intCast(505 + i * 10), │ │1150 + .author = patch_author, │ │1151 + .timestamp = timestamp + 6, │ │1152 }); │ │1153 │ │1154 if (status == .merged) { │ ╰────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1148 - const event = revision.event(patch.title); │ │1149 - const tree_entries = [_]evt.EventTreeEntry{ │ │1150 - .{ .tree = .{ .name = "base", .oid = &revision.tree_oid } }, │ │1151 - .{ .tree = .{ .name = "head", .oid = &revision.tree_oid } }, │ │1152 - }; │ │1153 - try evt.consume(.repo, .xit, .{}, io, allocator, target_repo, evt.events_ref, &.{.{ │ │1154 - .id = std.fmt.bytesToHex(revision.id, .lower), │ │1155 - .timestamp = revision.timestamp, │ │1156 - .author = .{ .name = "admin", .email = "admin@example.test" }, │ │1157 - .tree_entries = &tree_entries, │ │1158 - .event = .{ .patchrev = event }, │ │1159 - }}); │ │1160 - } │ │1161 - if (status != .open) { │ │1162 - try evt.Patch.update(.xit, .{}, io, allocator, target_repo, &patch_ids[i], .{ .status = status }, .{ │ │1163 - .name = "admin", │ │1164 - .email = "admin@example.test", │ │1165 - }); │ │1166 - } │ │1167 - if (status == .merged) { │ │1168 - try fork.remove(io, allocator, repos_path, admin_repo, &patch_hex, user_id, .{ │ │1169 - .name = "admin", │ │1170 - .email = "admin@example.test", │ │1155 + try pch.merge(.{}, io, allocator, repos_path, target_repo, .{ │ │1156 + .id = patch_hex, │ │1157 + .revision = .source, │ │1158 + .author = patch_author, │ │1159 + .timestamp = timestamp + 7, │ │1160 }); │ │1161 + try fork.remove(io, allocator, repos_path, admin_repo, &patch_hex, user_id, patch_author); │ │1162 + } else if (status != .open) { │ │1163 + try evt.Patch.update(.xit, .{}, io, allocator, target_repo, &patch_ids[i], .{ .status = status }, patch_author);│ │1164 } │ │1165 } │ │1166 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯