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