╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1483 }; 1484 1485 try transaction(io, repo, Ctx{ 1486 .core = &repo.core, 1487 .io = io, 1488 .allocator = allocator, 1489 .ref = ref, 1490 .events = events, 1491 .parent = parent, 1492 }); 1493 } 1494 1495 // append `ctx` to the repo's history as one transaction. the fixtures write a 1496 // few states the normal paths have no way to produce 1497 // fixtures commit directly, so the ref tips are indexed by hand. a fork gets 1498 // no commit index, as in production. 1499 const Reindex = struct { 1500 io: std.Io, 1501 allocator: std.mem.Allocator, 1502 core: *rp.Repo(.xit, .{}).Core, 1503 commits: bool, 1504 1505 pub fn run(ctx: @This(), cursor: *rp.Repo(.xit, .{}).DB.Cursor(.read_write)) !void { 1506 var moment = try rp.Repo(.xit, .{}).DB.HashMap(.read_write).init(cursor.*); 1507 const state = rp.Repo(.xit, .{}).State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1508 _ = try find.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, null); 1509 if (ctx.commits) _ = try srch_cmmt.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, &.{}, null); 1510 } 1511 }; 1512 1513 fn transaction(io: std.Io, repo: *rp.Repo(.xit, .{}), ctx: anytype) !void { 1514 const DB = rp.Repo(.xit, .{}).DB; 1515 try repo.core.db_file.lock(io, .exclusive); 1516 defer repo.core.db_file.unlock(io); 1517 1518 const history = try DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 1519 try history.appendContext(.{ .slot = try history.getSlot(-1) }, ctx); 1520 } 1521 1522 // recursively copy the contents of src_dir into dest_dir 1523 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 1524 var iter = src_dir.iterate(); 1525 while (try iter.next(io)) |entry| { 1526 switch (entry.kind) { 1527 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 1528 .directory => { 1529 try dest_dir.createDirPath(io, entry.name); 1530 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1531 defer dest_entry_dir.close(io); 1532 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1533 defer src_entry_dir.close(io); 1534 try copyDir(io, src_entry_dir, dest_entry_dir); 1535 }, 1536 else => {}, 1537 } 1538 } 1539 } 1540