╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
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