╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1093 try transaction(io, &fork_repo, Reindex{ .io = io, .allocator = allocator, .core = &fork_repo.core, .commits = false }); 1094 _ = try fork_repo.garbageCollect(io, allocator, .{}); 1095 try fork_dir.deleteFile(io, path); 1096 const revision_id = evt.EventWithId.randomId(random); 1097 const head_tree_oid = try commitTree(io, allocator, &fork_repo, &source_oid); 1098 const revision: evt.PatchRev = .{ 1099 .base_oid = &base_oid, 1100 .source_oid = &source_oid, 1101 .message = title, 1102 }; 1103 const revision_timestamp = timestamp + 3; 1104 const tree_entries = [_]evt.EventTreeEntry{ 1105 .{ .tree = .{ .name = "base", .oid = &base_tree_oid } }, 1106 .{ .tree = .{ .name = "head", .oid = &head_tree_oid } }, 1107 }; 1108 try evt.consume(.server, .fork, .xit, .{}, io, allocator, &fork_repo, evt.events_ref, &.{.{ 1109 .id = std.fmt.bytesToHex(revision_id, .lower), 1110 .timestamp = revision_timestamp, 1111 .author = author, 1112 .tree_entries = &tree_entries, 1113 .event = .{ .patchrev = revision }, 1114 }}); 1115 1116 var arena = std.heap.ArenaAllocator.init(allocator); 1117 defer arena.deinit(); 1118 const moment = try evt.currentMoment(.{}, &fork_repo); 1119 const revision_record = (try evt.PatchRev.readById(evt.EventDB(.sha1), .sha1, moment, &arena, &revision_id)) orelse return error.NotFound; 1120 const patch_record = (try evt.Patch.readById(evt.EventDB(.sha1), .sha1, moment, &arena, patch_id)) orelse return error.NotFound; 1121 var patch = patch_record.event; 1122 patch.revision = evt.Patch.Revision.fromRecord(revision_id, revision_record); 1123 try evt.consume(.server, .fork, .xit, .{}, io, allocator, &fork_repo, evt.events_ref, &.{.{ 1124 .id = patch_hex, 1125 .timestamp = revision_timestamp + 1, 1126 .author = author, 1127 .event = .{ .patch = patch }, 1128 }}); 1129 } 1130 1131 fn seedPatches( 1132 io: std.Io, 1133 allocator: std.mem.Allocator, 1134 server_path: []const u8, 1135 admin_repo: *rp.Repo(.xit, evt.admin_repo_opts), 1136 target_repo: *rp.Repo(.xit, .{}), 1137 repo_id: *const [evt.event_id_size]u8, 1138 user_id: *const [evt.event_id_size]u8, 1139 random: std.Random, 1140 ) !void { 1141 const patch_data = [_]struct { 1142 title: []const u8, 1143 description: []const u8, 1144 labels: []const u8, 1145 status: ?evt.Patch.StatusKind, 1146 alpha_edit: ?ScatterEdit = null, 1147 // based behind master, so merging it makes a merge commit 1148 behind_master: bool = false, 1149 }{ 1150 .{ 1151 .title = "Draft a faster dependency scanner", 1152 .description = "Rework dependency discovery so a large workspace can be scanned without repeatedly opening the same manifests.", 1153 .labels = "performance build", 1154 .status = null, 1155 }, 1156 .{ 1157 .title = "Remove the legacy configuration loader", 1158 .description = "Delete the compatibility loader now that the replacement format has shipped and the migration warning has been available for a full release.", 1159 .labels = "cleanup config", 1160 .status = .merged, 1161 .behind_master = true, 1162 }, 1163 .{ 1164 .title = "Cache parsed manifests between commands", 1165 .description = "Keep parsed manifests in the command context so consecutive operations do not repeat identical filesystem and parsing work.", 1166 .labels = "performance cache", 1167 .status = .closed, 1168 }, 1169 .{ 1170 .title = "Add structured output to the inspect command", 1171 .description = "Add a stable JSON representation of inspect results for scripts and editor integrations.", 1172 .labels = "enhancement cli", 1173 .status = .open, 1174 }, 1175 .{ 1176 .title = "Edit an adjacent line in alpha.txt", 1177 .description = "This patch can be cleanly merged by haxy, while git throws a merge conflict!", 1178 .labels = "merge", 1179 .status = .open, 1180 .alpha_edit = .{ .line = 2, .text = "adjust alpha beside the latest scatter edit" }, 1181 }, 1182 .{ 1183 .title = "Edit a conflicting line in alpha.txt", 1184 .description = "Both source and squash merges conflict with a different edit to the same line on master.", 1185 .labels = "merge", 1186 .status = .open, 1187 .alpha_edit = .{ .line = 3, .text = "replace alpha with a conflicting edit" }, 1188 }, 1189 }; 1190 1191 const repos_path = try std.fs.path.join(allocator, &.{ server_path, "repos" }); 1192 defer allocator.free(repos_path); 1193 const patch_author = evt.CommitAuthor{ .name = "admin", .email = "admin@example.test" }; 1194 var patch_ids: [patch_data.len][evt.event_id_size]u8 = undefined; 1195 for (patch_data, 0..) |patch, i| { 1196 const timestamp: u64 = @intCast(500 + i * 10); 1197 patch_ids[i] = evt.EventWithId.randomId(random); 1198 const patch_hex = std.fmt.bytesToHex(patch_ids[i], .lower); 1199 const path = try fork.create(.{}, io, allocator, repos_path, admin_repo, .{ 1200 .id = patch_hex, 1201 .user_id = user_id.*, 1202 .repo_id = repo_id.*, 1203 .title = patch.title, 1204 .description = patch.description, 1205 .labels = patch.labels, 1206 .target_branch = "master", 1207 .author = patch_author, 1208 .timestamp = timestamp, 1209 }); 1210 allocator.free(path); 1211 1212 // prepare the patch's base and file contents, then seed its commits and revision 1213 { 1214 var arena = std.heap.ArenaAllocator.init(allocator); 1215 defer arena.deinit(); 1216 const aa = arena.allocator(); 1217 var base_oid = (try target_repo.readRef(io, .{ .kind = .head, .name = "master" })) orelse return error.NotFound; 1218 if (patch.alpha_edit != null or patch.behind_master) { 1219 // v30 precedes the last scatter commit, even after the sample merge 1220 const tag_oid = (try target_repo.readRef(io, .{ .kind = .tag, .name = "v30" })) orelse return error.NotFound; 1221 var moment = try target_repo.core.latestMoment(); 1222 const state = rp.Repo(.xit, .{}).State(.read_only){ .core = &target_repo.core, .extra = .{ .moment = &moment } }; 1223 var tag = try obj.Object(.xit, .{}).init(state, io, allocator, &tag_oid); 1224 defer tag.deinit(); 1225 base_oid = switch (tag.content) { 1226 .tag => |value| value.target, 1227 else => return error.InvalidObject, 1228 }; 1229 } 1230 var contents: [3][]const u8 = undefined; 1231 const file_path: []const u8, const count: usize = if (patch.alpha_edit) |edit| blk: { 1232 // rev 29 first changes line 4; edit that line or the one above it 1233 contents[0] = try scatterContent(aa, 0, 28, edit); 1234 break :blk .{ "src/alpha.txt", 1 }; 1235 } else blk: { 1236 var writer = std.Io.Writer.Allocating.init(allocator); 1237 defer writer.deinit(); 1238 for (&contents, 0..) |*content, part| { 1239 try writer.writer.print("{s}: part {d}\n", .{ patch.title, part + 1 }); 1240 content.* = try aa.dupe(u8, writer.written()); 1241 } 1242 break :blk .{ "patch.txt", contents.len }; 1243 }; 1244 try seedPatchRevision(io, allocator, repos_path, &patch_ids[i], patch.title, patch_author, timestamp + 1, random, base_oid, file_path, contents[0..count]); 1245 } 1246 const status = patch.status orelse continue; 1247 const fork_path = try fork.forkPath(allocator, repos_path, &patch_hex); 1248 defer allocator.free(fork_path); 1249 try pch.publish(.{}, io, allocator, admin_repo, target_repo, fork_path, .{ 1250 .id = patch_hex, 1251 .user_id = user_id.*, 1252 .repo_id = repo_id.*, 1253 .author = patch_author, 1254 .timestamp = timestamp + 6, 1255 }); 1256 1257 if (status == .merged) { 1258 try pch.mergeAndRemoveFork(.{}, io, allocator, repos_path, admin_repo, target_repo, .{ 1259 .id = patch_hex, 1260 .revision = .source, 1261 .author = patch_author, 1262 .timestamp = timestamp + 7, 1263 }); 1264 } else if (status != .open) { 1265 try evt.Patch.update(.server, .xit, .{}, io, allocator, target_repo, &patch_ids[i], .{ .status = status }, patch_author); 1266 } 1267 } 1268 1269 // seed a small comment tree on the newest patch 1270 var comment_ids: [5][evt.event_id_size]u8 = undefined; 1271 for (&comment_ids) |*id| id.* = evt.EventWithId.randomId(random); 1272 const comment_bodies = [_][]const u8{ 1273 "This also needs to preserve the executable bit for files nested inside generated directories.", 1274 "I tested the archive path and the direct-copy path; both currently lose the mode.", 1275 "The archive writer is the right place to centralize it, since every exporter already goes through that layer.", 1276 "Please include a regression fixture with a mix of executable and ordinary files.", 1277 "I'll add that fixture and cover both supported archive formats.", 1278 }; 1279 var comments: [comment_ids.len]evt.EventWithId = undefined; 1280 for (&comments, 0..) |*comment, i| { 1281 comment.* = .{ 1282 .id = std.fmt.bytesToHex(comment_ids[i], .lower), 1283 .timestamp = @intCast(700 + i), 1284 .author = .{ .name = if (i % 2 == 0) "alice" else "bob", .email = if (i % 2 == 0) "alice@example.test" else "bob@example.test" }, 1285 .event = .{ .comment = .{ 1286 .thread_id = std.fmt.bytesToHex(patch_ids[patch_ids.len - 1], .lower), 1287 .parent_id = switch (i) { 1288 0, 1 => std.fmt.bytesToHex(patch_ids[patch_ids.len - 1], .lower), 1289 2, 4 => std.fmt.bytesToHex(comment_ids[0], .lower), 1290 3 => std.fmt.bytesToHex(comment_ids[2], .lower), 1291 else => unreachable, 1292 }, 1293 .body = comment_bodies[i], 1294 } }, 1295 }; 1296 } 1297 try evt.consume(.server, .repo, .xit, .{}, io, allocator, target_repo, evt.events_ref, &comments); 1298 1299 // create divergent metadata edits on the next three patches 1300 var patch_arena = std.heap.ArenaAllocator.init(allocator); 1301 defer patch_arena.deinit(); 1302 const moment = try evt.currentMoment(.{}, target_repo); 1303 var values: [3]evt.Patch = undefined; 1304 for (1..4) |i| { 1305 const record = (try evt.Patch.readById(evt.EventDB(.sha1), .sha1, moment, &patch_arena, &patch_ids[i])) orelse return error.NotFound; 1306 values[i - 1] = record.event; 1307 } 1308 var ours_values = values; 1309 ours_values[0].title = "Drop the legacy configuration loader"; 1310 ours_values[0].labels = "cleanup config breaking"; 1311 const closed_description = try longDescription( 1312 patch_arena.allocator(), 1313 "Cache parsed manifests for the lifetime of a command invocation and invalidate entries when their files change.", 1314 ); 1315 ours_values[1].description = closed_description; 1316 ours_values[2].description = "Add JSON output to inspect with versioned field names and deterministic object ordering."; 1317 var theirs_values = values; 1318 theirs_values[0].title = "Delete compatibility configuration support"; 1319 theirs_values[0].labels = "config maintenance"; 1320 theirs_values[1].description = "Keep a process-wide manifest cache shared by every command and refresh it after writes."; 1321 theirs_values[2].description = "Expose inspect results as newline-delimited JSON so callers can stream large repositories."; 1322 1323 const seed_tip = (try target_repo.readRef(io, evt.events_ref)) orelse return error.NotFound; 1324 const other_ref = xit.ref.Ref{ .kind = .head, .name = "haxy/patch-other" }; 1325 var ours = [_]evt.EventWithId{ 1326 .{ 1327 .id = std.fmt.bytesToHex(patch_ids[1], .lower), 1328 .timestamp = 800, 1329 .author = .{ .name = "alice", .email = "alice@example.test" }, 1330 .event = .{ .patch = ours_values[0] }, 1331 }, 1332 .{ 1333 .id = std.fmt.bytesToHex(patch_ids[2], .lower), 1334 .timestamp = 801, 1335 .author = .{ .name = "alice", .email = "alice@example.test" }, 1336 .event = .{ .patch = ours_values[1] }, 1337 }, 1338 .{ 1339 .id = std.fmt.bytesToHex(patch_ids[3], .lower), 1340 .timestamp = 802, 1341 .author = .{ .name = "alice", .email = "alice@example.test" }, 1342 .event = .{ .patch = ours_values[2] }, 1343 }, 1344 }; 1345 1346 var theirs = ours; 1347 theirs[0].timestamp = 810; 1348 theirs[0].author = .{ .name = "bob", .email = "bob@example.test" }; 1349 theirs[0].event.patch = theirs_values[0]; 1350 theirs[1].timestamp = 811; 1351 theirs[1].author = .{ .name = "bob", .email = "bob@example.test" }; 1352 theirs[1].event.patch = theirs_values[1]; 1353 theirs[2].timestamp = 812; 1354 theirs[2].author = .{ .name = "bob", .email = "bob@example.test" }; 1355 theirs[2].event.patch = theirs_values[2]; 1356 1357 try evt.consume(.server, .repo, .xit, .{}, io, allocator, target_repo, evt.events_ref, &ours); 1358 try commitEventsAtRef(io, allocator, target_repo, other_ref, &theirs, seed_tip); 1359 { 1360 var merge = try target_repo.mergeAtRef(io, allocator, .{ .kind = .full, .action = .{ .new = .{ .source = &.{.{ .ref = other_ref }} } } }, evt.events_ref, null); 1361 defer merge.deinit(); 1362 if (merge.result != .success) return error.MergeFailed; 1363 } 1364 try target_repo.removeBranch(io, .{ .name = other_ref.name }); 1365 try evt.consume(.server, .repo, .xit, .{}, io, allocator, target_repo, evt.events_ref, &.{}); 1366 try pch.writeBranchPatch(.server, .xit, .{}, io, allocator, target_repo, std.fmt.bytesToHex(evt.EventWithId.randomId(random), .lower), .{ 1367 .title = "Merge the existing feature branch", 1368 .description = "This patch tracks the feature branch in this repo without creating a fork.", 1369 .labels = "feature", 1370 .source_branch = "feature", 1371 .target_branch = "master", 1372 }, null, patch_author); 1373 1374 // a push onto the branch that patch tracks, so the undo tab shows the 1375 // action and the patch refresh it sets off 1376 try seedPush(io, allocator, target_repo, patch_author); 1377 try pch.refreshBranches(.server, .xit, .{}, io, allocator, target_repo, null, null); 1378 } 1379 1380 // stand in for a client push, which the fixture has no server to receive: one 1381 // transaction moves the branch, refreshes the patches tracking it and records 1382 // the action, the way receive-pack does 1383 fn seedPush(io: std.Io, allocator: std.mem.Allocator, repo: *rp.Repo(.xit, .{}), author: evt.CommitAuthor) !void { 1384 const Repo = rp.Repo(.xit, .{}); 1385 const DB = Repo.DB; 1386 const Ctx = struct { 1387 core: *Repo.Core, 1388 io: std.Io, 1389 allocator: std.mem.Allocator, 1390 author: evt.CommitAuthor, 1391 1392 pub fn run(ctx: @This(), cursor: *DB.Cursor(.read_write)) !void { 1393 const opts: rp.RepoOpts(.xit) = .{}; 1394 var moment = try DB.HashMap(.read_write).init(cursor.*); 1395 const state = Repo.State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1396 var arena = std.heap.ArenaAllocator.init(ctx.allocator); 1397 defer arena.deinit(); 1398 const aa = arena.allocator(); 1399 1400 // a null tree keeps the parent's content, so the branch advances 1401 // without the fixture having to build one 1402 const author_line = try std.fmt.allocPrint(aa, "{s} <{s}>", .{ ctx.author.name, ctx.author.email }); 1403 const feature_old = (try rf.readRecur(.xit, opts, state.readOnly(), ctx.io, .{ .ref = .{ .kind = .head, .name = "feature" } })) orelse return error.NotFound; 1404 const feature_new = try obj.writeCommit(.xit, opts, state, ctx.io, ctx.allocator, .{ 1405 .message = "Revise the feature branch", 1406 .author = author_line, 1407 .timestamp = 820, 1408 }, null, .{ .kind = .head, .name = "feature" }); 1409 1410 // a branch the push creates has no old tip, so its range is open 1411 try bch.add(.xit, opts, state, ctx.io, .{ .name = "docs" }); 1412 const docs_new = (try rf.readRecur(.xit, opts, state.readOnly(), ctx.io, .{ .ref = .{ .kind = .head, .name = "docs" } })) orelse return error.NotFound; 1413 1414 const updates = [_]xit.net_server_receive_pack.AppliedRefUpdate{ 1415 .{ 1416 .ref_name = try aa.dupe(u8, "refs/heads/feature"), 1417 .old_oid = try aa.dupe(u8, &feature_old), 1418 .new_oid = try aa.dupe(u8, &feature_new), 1419 }, 1420 .{ 1421 .ref_name = try aa.dupe(u8, "refs/heads/docs"), 1422 .old_oid = try aa.dupe(u8, "0" ** hash.hexLen(opts.hash)), 1423 .new_oid = try aa.dupe(u8, &docs_new), 1424 }, 1425 }; 1426 1427 _ = try pch.refreshBranchesInTransaction(.server, opts, state, &moment, ctx.io, ctx.allocator, &updates, null, null); 1428 try push.writeUndo(opts, state, ctx.io, ctx.allocator, ctx.author, &updates); 1429 } 1430 }; 1431 1432 try transaction(io, repo, Ctx{ .core = &repo.core, .io = io, .allocator = allocator, .author = author }); 1433 } 1434 1435 // commit `events` onto `ref`, rooted at `parent`, as one transaction. 1436 // consume always roots a new branch at nothing, so the divergent fixtures 1437 // write their side branch here instead. nothing is consumed, so it records 1438 // xit's own commit action rather than one of haxy's event actions 1439 fn commitEventsAtRef( 1440 io: std.Io, 1441 allocator: std.mem.Allocator, 1442 repo: *rp.Repo(.xit, .{}), 1443 ref: xit.ref.Ref, 1444 events: []const evt.EventWithId, 1445 parent: [hash.hexLen(.sha1)]u8, 1446 ) !void { 1447 const Repo = rp.Repo(.xit, .{}); 1448 const DB = Repo.DB; 1449 const Ctx = struct { 1450 core: *Repo.Core, 1451 io: std.Io, 1452 allocator: std.mem.Allocator, 1453 ref: xit.ref.Ref, 1454 events: []const evt.EventWithId, 1455 parent: [hash.hexLen(.sha1)]u8, 1456 1457 pub fn run(ctx: @This(), cursor: *DB.Cursor(.read_write)) !void { 1458 const opts: rp.RepoOpts(.xit) = .{}; 1459 var moment = try DB.HashMap(.read_write).init(cursor.*); 1460 const state = Repo.State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1461 try evt.commitEvents(.xit, opts, state, ctx.io, ctx.allocator, ctx.ref, ctx.events, .{ctx.parent}); 1462 const tip = (try xit.ref.readRecur(.xit, opts, state.readOnly(), ctx.io, .{ .ref = ctx.ref })) orelse return error.NotFound; 1463 try xit.undo.write(opts, state, std.Io.Timestamp.now(ctx.io, .real).toSeconds(), .{ 1464 .commit = try .init("seed conflicting events", tip, opts.max_read_size), 1465 }); 1466 } 1467 }; 1468 1469 try transaction(io, repo, Ctx{ 1470 .core = &repo.core, 1471 .io = io, 1472 .allocator = allocator, 1473 .ref = ref, 1474 .events = events, 1475 .parent = parent, 1476 }); 1477 } 1478 1479 // append `ctx` to the repo's history as one transaction. the fixtures write a 1480 // few states the normal paths have no way to produce 1481 // fixtures commit directly, so the ref tips are indexed by hand. a fork gets 1482 // no commit index, as in production. 1483 const Reindex = struct { 1484 io: std.Io, 1485 allocator: std.mem.Allocator, 1486 core: *rp.Repo(.xit, .{}).Core, 1487 commits: bool, 1488 1489 pub fn run(ctx: @This(), cursor: *rp.Repo(.xit, .{}).DB.Cursor(.read_write)) !void { 1490 var moment = try rp.Repo(.xit, .{}).DB.HashMap(.read_write).init(cursor.*); 1491 const state = rp.Repo(.xit, .{}).State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1492 _ = try find.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, null); 1493 if (ctx.commits) _ = try srch_cmmt.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, &.{}, null); 1494 } 1495 }; 1496 1497 fn transaction(io: std.Io, repo: *rp.Repo(.xit, .{}), ctx: anytype) !void { 1498 const DB = rp.Repo(.xit, .{}).DB; 1499 try repo.core.db_file.lock(io, .exclusive); 1500 defer repo.core.db_file.unlock(io); 1501 1502 const history = try DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 1503 try history.appendContext(.{ .slot = try history.getSlot(-1) }, ctx); 1504 } 1505 1506 // recursively copy the contents of src_dir into dest_dir 1507 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 1508 var iter = src_dir.iterate(); 1509 while (try iter.next(io)) |entry| { 1510 switch (entry.kind) { 1511 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 1512 .directory => { 1513 try dest_dir.createDirPath(io, entry.name); 1514 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1515 defer dest_entry_dir.close(io); 1516 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1517 defer src_entry_dir.close(io); 1518 try copyDir(io, src_entry_dir, dest_entry_dir); 1519 }, 1520 else => {}, 1521 } 1522 } 1523 } 1524