╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
937 } 938 }; 939 940 try srv.run(.xit, .{}, io, allocator, cwd_path, serve_options, run_opts.err, Runnable{ .io = io, .allocator = allocator, .session = &session, .repo = &repo }); 941 } 942 } 943 944 // words cycled through to pad generated lines into prose-like content 945 const scatter_words = [_][]const u8{ 946 "lorem", "ipsum", "dolor", "sit", "amet", "consectetur", 947 "quantum", "vector", "matrix", "buffer", "kernel", "socket", 948 "falcon", "otter", "badger", "walrus", "ferret", "marmot", 949 "scatter", "gather", "encode", "decode", "render", "commit", 950 }; 951 952 fn longDescription(allocator: std.mem.Allocator, initial: []const u8) ![]u8 { 953 var writer = std.Io.Writer.Allocating.init(allocator); 954 defer writer.deinit(); 955 try writer.writer.print("{s}", .{initial}); 956 for (0..ui.detail_preview_lines) |line| 957 try writer.writer.print("\n{d} {s}", .{ line, scatter_words[line % scatter_words.len] }); 958 return writer.toOwnedSlice(); 959 } 960 961 // write `path` as 40 lines of mostly-stable filler. revision `c` and file 962 // index `fi` shift which lines change and the words used, so each (c, fi) 963 // yields a distinct multi-hunk diff against the previous revision. untouched 964 // lines stay byte-identical across revisions, so a bump in `c` is a scatter of 965 // small hunks rather than a full rewrite. 966 fn writeScatterFile(io: std.Io, allocator: std.mem.Allocator, repo_dir: std.Io.Dir, path: []const u8, fi: usize, c: usize) !void { 967 const content = try scatterContent(allocator, fi, c, null); 968 defer allocator.free(content); 969 const file = try repo_dir.createFile(io, path, .{}); 970 defer file.close(io); 971 try file.writeStreamingAll(io, content); 972 } 973 974 const ScatterEdit = struct { line: usize, text: []const u8 }; 975 976 fn scatterContent(allocator: std.mem.Allocator, fi: usize, c: usize, replacement: ?ScatterEdit) ![]u8 { 977 var writer = std.Io.Writer.Allocating.init(allocator); 978 defer writer.deinit(); 979 for (0..40) |line| { 980 if (replacement) |edit| if (line == edit.line) { 981 try writer.writer.print("{s}\n", .{edit.text}); 982 continue; 983 }; 984 const start = writer.written().len; 985 if ((line + fi + c) % 8 == 0) { 986 const tag = scatter_words[(line + fi + c * 3) % scatter_words.len]; 987 try writer.writer.print("rev {d} {s}", .{ c, tag }); 988 } 989 const target = 40 + (line * 17 + fi * 23) % 70; 990 var w = line + fi; 991 while (true) : (w += 1) { 992 const word = scatter_words[w % scatter_words.len]; 993 const len = writer.written().len - start; 994 if (len >= target or len + 1 + word.len > 120) break; 995 if (len == 0) 996 try writer.writer.print("{s}", .{word}) 997 else 998 try writer.writer.print(" {s}", .{word}); 999 } 1000 try writer.writer.writeByte('\n'); 1001 } 1002 return writer.toOwnedSlice(); 1003 } 1004 1005 // tag the current HEAD as the next sequential version: v1, v2, and so on 1006 fn addNextTag(repo: *rp.Repo(.xit, .{}), io: std.Io, allocator: std.mem.Allocator, n: *usize) !void { 1007 var buf: [16]u8 = undefined; 1008 const name = try std.fmt.bufPrint(&buf, "v{d}", .{n.*}); 1009 _ = try repo.addTag(io, allocator, .{ .name = name }); 1010 n.* += 1; 1011 } 1012 1013 fn commitTree( 1014 io: std.Io, 1015 allocator: std.mem.Allocator, 1016 repo: *rp.Repo(.xit, .{}), 1017 oid: *const [hash.hexLen(.sha1)]u8, 1018 ) ![hash.hexLen(.sha1)]u8 { 1019 var moment = try repo.core.latestMoment(); 1020 const state = rp.Repo(.xit, .{}).State(.read_only){ .core = &repo.core, .extra = .{ .moment = &moment } }; 1021 var object = try obj.Object(.xit, .{}).init(state, io, allocator, oid); 1022 defer object.deinit(); 1023 return switch (object.content) { 1024 .commit => |commit| commit.tree, 1025 else => error.InvalidObject, 1026 }; 1027 } 1028 1029 fn seedPatchRevision( 1030 io: std.Io, 1031 allocator: std.mem.Allocator, 1032 repos_path: []const u8, 1033 patch_id: *const [evt.event_id_size]u8, 1034 title: []const u8, 1035 author: evt.CommitAuthor, 1036 timestamp: u64, 1037 random: std.Random, 1038 base_oid: [hash.hexLen(.sha1)]u8, 1039 path: []const u8, 1040 contents: []const []const u8, 1041 ) !void { 1042 const patch_hex = std.fmt.bytesToHex(patch_id.*, .lower); 1043 const fork_path = try fork.forkPath(allocator, repos_path, &patch_hex); 1044 defer allocator.free(fork_path); 1045 var fork_repo = try rp.Repo(.xit, .{}).open(io, allocator, .{ .path = fork_path, .require_repo_root = true }); 1046 defer fork_repo.deinit(io, allocator); 1047 1048 try fork_repo.addConfig(io, allocator, .{ .name = "core.bare", .value = "false" }); 1049 { 1050 var reset = try fork_repo.reset(io, allocator, .{ .target = .{ .oid = &base_oid } }); 1051 defer reset.deinit(); 1052 } 1053 const base_tree_oid = try commitTree(io, allocator, &fork_repo, &base_oid); 1054 var source_oid = base_oid; 1055 var fork_dir = try std.Io.Dir.cwd().openDir(io, fork_path, .{}); 1056 defer fork_dir.close(io); 1057 var writer = std.Io.Writer.Allocating.init(allocator); 1058 defer writer.deinit(); 1059 if (std.fs.path.dirname(path)) |dir| try fork_dir.createDirPath(io, dir); 1060 for (contents, 0..) |content, i| { 1061 { 1062 const file = try fork_dir.createFile(io, path, .{}); 1063 defer file.close(io); 1064 try file.writeStreamingAll(io, content); 1065 } 1066 try fork_repo.add(io, allocator, &.{path}); 1067 writer.clearRetainingCapacity(); 1068 try writer.writer.print("{s} ({d}/{d})", .{ title, i + 1, contents.len }); 1069 source_oid = try fork_repo.commit(io, allocator, .{ .message = writer.written(), .timestamp = timestamp + i }); 1070 } 1071 try fork_repo.patchAll(io, allocator, null); 1072 try fork_repo.addConfig(io, allocator, .{ .name = "core.bare", .value = "true" }); 1073 // the commits above skipped the push path, so index the patch branch by hand 1074 try find.refresh(.{}, io, allocator, &fork_repo); 1075 try fork_dir.deleteFile(io, path); 1076 const revision_id = evt.EventWithId.randomId(random); 1077 const head_tree_oid = try commitTree(io, allocator, &fork_repo, &source_oid); 1078 const revision: evt.PatchRev = .{ 1079 .base_oid = &base_oid, 1080 .source_oid = &source_oid, 1081 .message = title, 1082 }; 1083 const revision_timestamp = timestamp + 3; 1084 const tree_entries = [_]evt.EventTreeEntry{ 1085 .{ .tree = .{ .name = "base", .oid = &base_tree_oid } }, 1086 .{ .tree = .{ .name = "head", .oid = &head_tree_oid } }, 1087 }; 1088 try evt.consume(.server, .fork, .xit, .{}, io, allocator, &fork_repo, evt.events_ref, &.{.{ 1089 .id = std.fmt.bytesToHex(revision_id, .lower), 1090 .timestamp = revision_timestamp, 1091 .author = author, 1092 .tree_entries = &tree_entries, 1093 .event = .{ .patchrev = revision }, 1094 }}); 1095 1096 var arena = std.heap.ArenaAllocator.init(allocator); 1097 defer arena.deinit(); 1098 const moment = try evt.currentMoment(.{}, &fork_repo); 1099 const revision_record = (try evt.PatchRev.readById(evt.EventDB(.sha1), .sha1, moment, &arena, &revision_id)) orelse return error.NotFound; 1100 const patch_record = (try evt.Patch.readById(evt.EventDB(.sha1), .sha1, moment, &arena, patch_id)) orelse return error.NotFound; 1101 var patch = patch_record.event; 1102 patch.revision = evt.Patch.Revision.fromRecord(revision_id, revision_record); 1103 try evt.consume(.server, .fork, .xit, .{}, io, allocator, &fork_repo, evt.events_ref, &.{.{ 1104 .id = patch_hex, 1105 .timestamp = revision_timestamp + 1, 1106 .author = author, 1107 .event = .{ .patch = patch }, 1108 }}); 1109 } 1110 1111 fn seedPatches( 1112 io: std.Io, 1113 allocator: std.mem.Allocator, 1114 server_path: []const u8, 1115 admin_repo: *rp.Repo(.xit, evt.admin_repo_opts), 1116 target_repo: *rp.Repo(.xit, .{}), 1117 repo_id: *const [evt.event_id_size]u8, 1118 user_id: *const [evt.event_id_size]u8, 1119 random: std.Random, 1120 ) !void { 1121 const patch_data = [_]struct { 1122 title: []const u8, 1123 description: []const u8, 1124 tags: []const u8, 1125 status: ?evt.Patch.StatusKind, 1126 alpha_edit: ?ScatterEdit = null, 1127 }{ 1128 .{ 1129 .title = "Draft a faster dependency scanner", 1130 .description = "Rework dependency discovery so a large workspace can be scanned without repeatedly opening the same manifests.", 1131 .tags = "performance build", 1132 .status = null, 1133 }, 1134 .{ 1135 .title = "Remove the legacy configuration loader", 1136 .description = "Delete the compatibility loader now that the replacement format has shipped and the migration warning has been available for a full release.", 1137 .tags = "cleanup config", 1138 .status = .merged, 1139 }, 1140 .{ 1141 .title = "Cache parsed manifests between commands", 1142 .description = "Keep parsed manifests in the command context so consecutive operations do not repeat identical filesystem and parsing work.", 1143 .tags = "performance cache", 1144 .status = .closed, 1145 }, 1146 .{ 1147 .title = "Add structured output to the inspect command", 1148 .description = "Add a stable JSON representation of inspect results for scripts and editor integrations.", 1149 .tags = "enhancement cli", 1150 .status = .open, 1151 }, 1152 .{ 1153 .title = "Edit an adjacent line in alpha.txt", 1154 .description = "This patch can be cleanly merged by haxy, while git throws a merge conflict!", 1155 .tags = "merge", 1156 .status = .open, 1157 .alpha_edit = .{ .line = 2, .text = "adjust alpha beside the latest scatter edit" }, 1158 }, 1159 .{ 1160 .title = "Edit a conflicting line in alpha.txt", 1161 .description = "Both source and squash merges conflict with a different edit to the same line on master.", 1162 .tags = "merge", 1163 .status = .open, 1164 .alpha_edit = .{ .line = 3, .text = "replace alpha with a conflicting edit" }, 1165 }, 1166 }; 1167 1168 const repos_path = try std.fs.path.join(allocator, &.{ server_path, "repos" }); 1169 defer allocator.free(repos_path); 1170 const patch_author = evt.CommitAuthor{ .name = "admin", .email = "admin@example.test" }; 1171 var patch_ids: [patch_data.len][evt.event_id_size]u8 = undefined; 1172 for (patch_data, 0..) |patch, i| { 1173 const timestamp: u64 = @intCast(500 + i * 10); 1174 patch_ids[i] = evt.EventWithId.randomId(random); 1175 const patch_hex = std.fmt.bytesToHex(patch_ids[i], .lower); 1176 const path = try fork.create(.{}, io, allocator, repos_path, admin_repo, .{ 1177 .id = patch_hex, 1178 .user_id = user_id.*, 1179 .repo_id = repo_id.*, 1180 .title = patch.title, 1181 .description = patch.description, 1182 .tags = patch.tags, 1183 .target_branch = "master", 1184 .author = patch_author, 1185 .timestamp = timestamp, 1186 }); 1187 allocator.free(path); 1188 1189 // prepare the patch's base and file contents, then seed its commits and revision 1190 { 1191 var arena = std.heap.ArenaAllocator.init(allocator); 1192 defer arena.deinit(); 1193 const aa = arena.allocator(); 1194 var base_oid = (try target_repo.readRef(io, .{ .kind = .head, .name = "master" })) orelse return error.NotFound; 1195 var contents: [3][]const u8 = undefined; 1196 const file_path: []const u8, const count: usize = if (patch.alpha_edit) |edit| blk: { 1197 // v30 precedes the last scatter commit, even after the sample merge 1198 const tag_oid = (try target_repo.readRef(io, .{ .kind = .tag, .name = "v30" })) orelse return error.NotFound; 1199 var moment = try target_repo.core.latestMoment(); 1200 const state = rp.Repo(.xit, .{}).State(.read_only){ .core = &target_repo.core, .extra = .{ .moment = &moment } }; 1201 var tag = try obj.Object(.xit, .{}).init(state, io, allocator, &tag_oid); 1202 defer tag.deinit(); 1203 base_oid = switch (tag.content) { 1204 .tag => |value| value.target, 1205 else => return error.InvalidObject, 1206 }; 1207 // rev 29 first changes line 4; edit that line or the one above it 1208 contents[0] = try scatterContent(aa, 0, 28, edit); 1209 break :blk .{ "src/alpha.txt", 1 }; 1210 } else blk: { 1211 var writer = std.Io.Writer.Allocating.init(allocator); 1212 defer writer.deinit(); 1213 for (&contents, 0..) |*content, part| { 1214 try writer.writer.print("{s}: part {d}\n", .{ patch.title, part + 1 }); 1215 content.* = try aa.dupe(u8, writer.written()); 1216 } 1217 break :blk .{ "patch.txt", contents.len }; 1218 }; 1219 try seedPatchRevision(io, allocator, repos_path, &patch_ids[i], patch.title, patch_author, timestamp + 1, random, base_oid, file_path, contents[0..count]); 1220 } 1221 const status = patch.status orelse continue; 1222 const fork_path = try fork.forkPath(allocator, repos_path, &patch_hex); 1223 defer allocator.free(fork_path); 1224 try pch.publish(.{}, io, allocator, admin_repo, target_repo, fork_path, .{ 1225 .id = patch_hex, 1226 .user_id = user_id.*, 1227 .repo_id = repo_id.*, 1228 .author = patch_author, 1229 .timestamp = timestamp + 6, 1230 }); 1231 1232 if (status == .merged) { 1233 try pch.mergeAndRemoveFork(.{}, io, allocator, repos_path, admin_repo, target_repo, .{ 1234 .id = patch_hex, 1235 .revision = .source, 1236 .author = patch_author, 1237 .timestamp = timestamp + 7, 1238 }); 1239 } else if (status != .open) { 1240 try evt.Patch.update(.server, .xit, .{}, io, allocator, target_repo, &patch_ids[i], .{ .status = status }, patch_author); 1241 } 1242 } 1243 1244 // seed a small comment tree on the newest patch 1245 var comment_ids: [5][evt.event_id_size]u8 = undefined; 1246 for (&comment_ids) |*id| id.* = evt.EventWithId.randomId(random); 1247 const comment_bodies = [_][]const u8{ 1248 "This also needs to preserve the executable bit for files nested inside generated directories.", 1249 "I tested the archive path and the direct-copy path; both currently lose the mode.", 1250 "The archive writer is the right place to centralize it, since every exporter already goes through that layer.", 1251 "Please include a regression fixture with a mix of executable and ordinary files.", 1252 "I'll add that fixture and cover both supported archive formats.", 1253 }; 1254 var comments: [comment_ids.len]evt.EventWithId = undefined; 1255 for (&comments, 0..) |*comment, i| { 1256 comment.* = .{ 1257 .id = std.fmt.bytesToHex(comment_ids[i], .lower), 1258 .timestamp = @intCast(700 + i), 1259 .author = .{ .name = if (i % 2 == 0) "alice" else "bob", .email = if (i % 2 == 0) "alice@example.test" else "bob@example.test" }, 1260 .event = .{ .comment = .{ 1261 .thread_id = std.fmt.bytesToHex(patch_ids[patch_ids.len - 1], .lower), 1262 .parent_id = switch (i) { 1263 0, 1 => std.fmt.bytesToHex(patch_ids[patch_ids.len - 1], .lower), 1264 2, 4 => std.fmt.bytesToHex(comment_ids[0], .lower), 1265 3 => std.fmt.bytesToHex(comment_ids[2], .lower), 1266 else => unreachable, 1267 }, 1268 .body = comment_bodies[i], 1269 } }, 1270 }; 1271 } 1272 try evt.consume(.server, .repo, .xit, .{}, io, allocator, target_repo, evt.events_ref, &comments); 1273 1274 // create divergent metadata edits on the next three patches 1275 var patch_arena = std.heap.ArenaAllocator.init(allocator); 1276 defer patch_arena.deinit(); 1277 const moment = try evt.currentMoment(.{}, target_repo); 1278 var values: [3]evt.Patch = undefined; 1279 for (1..4) |i| { 1280 const record = (try evt.Patch.readById(evt.EventDB(.sha1), .sha1, moment, &patch_arena, &patch_ids[i])) orelse return error.NotFound; 1281 values[i - 1] = record.event; 1282 } 1283 var ours_values = values; 1284 ours_values[0].title = "Drop the legacy configuration loader"; 1285 ours_values[0].tags = "cleanup config breaking"; 1286 const closed_description = try longDescription( 1287 patch_arena.allocator(), 1288 "Cache parsed manifests for the lifetime of a command invocation and invalidate entries when their files change.", 1289 ); 1290 ours_values[1].description = closed_description; 1291 ours_values[2].description = "Add JSON output to inspect with versioned field names and deterministic object ordering."; 1292 var theirs_values = values; 1293 theirs_values[0].title = "Delete compatibility configuration support"; 1294 theirs_values[0].tags = "config maintenance"; 1295 theirs_values[1].description = "Keep a process-wide manifest cache shared by every command and refresh it after writes."; 1296 theirs_values[2].description = "Expose inspect results as newline-delimited JSON so callers can stream large repositories."; 1297 1298 const seed_tip = (try target_repo.readRef(io, evt.events_ref)) orelse return error.NotFound; 1299 const other_ref = xit.ref.Ref{ .kind = .head, .name = "haxy/patch-other" }; 1300 var ours = [_]evt.EventWithId{ 1301 .{ 1302 .id = std.fmt.bytesToHex(patch_ids[1], .lower), 1303 .timestamp = 800, 1304 .author = .{ .name = "alice", .email = "alice@example.test" }, 1305 .event = .{ .patch = ours_values[0] }, 1306 }, 1307 .{ 1308 .id = std.fmt.bytesToHex(patch_ids[2], .lower), 1309 .timestamp = 801, 1310 .author = .{ .name = "alice", .email = "alice@example.test" }, 1311 .event = .{ .patch = ours_values[1] }, 1312 }, 1313 .{ 1314 .id = std.fmt.bytesToHex(patch_ids[3], .lower), 1315 .timestamp = 802, 1316 .author = .{ .name = "alice", .email = "alice@example.test" }, 1317 .event = .{ .patch = ours_values[2] }, 1318 }, 1319 }; 1320 1321 var theirs = ours; 1322 theirs[0].timestamp = 810; 1323 theirs[0].author = .{ .name = "bob", .email = "bob@example.test" }; 1324 theirs[0].event.patch = theirs_values[0]; 1325 theirs[1].timestamp = 811; 1326 theirs[1].author = .{ .name = "bob", .email = "bob@example.test" }; 1327 theirs[1].event.patch = theirs_values[1]; 1328 theirs[2].timestamp = 812; 1329 theirs[2].author = .{ .name = "bob", .email = "bob@example.test" }; 1330 theirs[2].event.patch = theirs_values[2]; 1331 1332 try evt.consume(.server, .repo, .xit, .{}, io, allocator, target_repo, evt.events_ref, &ours); 1333 var json: std.Io.Writer.Allocating = .init(allocator); 1334 defer json.deinit(); 1335 for (theirs, 0..) |event, i| { 1336 json.clearRetainingCapacity(); 1337 try std.json.Stringify.value(event, .{}, &json.writer); 1338 const author = try std.fmt.allocPrint(allocator, "{s} <{s}>", .{ event.author.name, event.author.email }); 1339 defer allocator.free(author); 1340 _ = try target_repo.commitAtRef(io, allocator, .{ 1341 .author = author, 1342 .message = json.written(), 1343 .timestamp = event.timestamp, 1344 .parent_oids = if (i == 0) &.{seed_tip} else null, 1345 }, null, other_ref); 1346 } 1347 { 1348 var merge = try target_repo.mergeAtRef(io, allocator, .{ .kind = .full, .action = .{ .new = .{ .source = &.{.{ .ref = other_ref }} } } }, evt.events_ref, null); 1349 defer merge.deinit(); 1350 if (merge.result != .success) return error.MergeFailed; 1351 } 1352 try target_repo.removeBranch(io, .{ .name = other_ref.name }); 1353 try evt.consume(.server, .repo, .xit, .{}, io, allocator, target_repo, evt.events_ref, &.{}); 1354 try pch.writeBranchPatch(.server, .xit, .{}, io, allocator, target_repo, std.fmt.bytesToHex(evt.EventWithId.randomId(random), .lower), .{ 1355 .title = "Merge the existing feature branch", 1356 .description = "This patch tracks the feature branch in this repo without creating a fork.", 1357 .tags = "feature", 1358 .source_branch = "feature", 1359 .target_branch = "master", 1360 }, null, patch_author); 1361 } 1362 1363 // recursively copy the contents of src_dir into dest_dir 1364 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 1365 var iter = src_dir.iterate(); 1366 while (try iter.next(io)) |entry| { 1367 switch (entry.kind) { 1368 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 1369 .directory => { 1370 try dest_dir.createDirPath(io, entry.name); 1371 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1372 defer dest_entry_dir.close(io); 1373 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1374 defer src_entry_dir.close(io); 1375 try copyDir(io, src_entry_dir, dest_entry_dir); 1376 }, 1377 else => {}, 1378 } 1379 } 1380 } 1381