╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1511 }); 1512 } 1513 }; 1514 1515 try transaction(io, repo, Ctx{ 1516 .core = &repo.core, 1517 .io = io, 1518 .allocator = allocator, 1519 .ref = ref, 1520 .events = events, 1521 .parent = parent, 1522 }); 1523 } 1524 1525 // append `ctx` to the repo's history as one transaction. the fixtures write a 1526 // few states the normal paths have no way to produce 1527 // fixtures commit directly, so the ref tips are indexed by hand. a fork gets 1528 // no commit index, as in production. 1529 const Reindex = struct { 1530 io: std.Io, 1531 allocator: std.mem.Allocator, 1532 core: *rp.Repo(.xit, .{}).Core, 1533 commits: bool, 1534 1535 pub fn run(ctx: @This(), cursor: *rp.Repo(.xit, .{}).DB.Cursor(.read_write)) !void { 1536 var moment = try rp.Repo(.xit, .{}).DB.HashMap(.read_write).init(cursor.*); 1537 const state = rp.Repo(.xit, .{}).State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1538 _ = try find.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, null); 1539 if (ctx.commits) _ = try srch_cmmt.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, &.{}, null); 1540 } 1541 }; 1542 1543 fn transaction(io: std.Io, repo: *rp.Repo(.xit, .{}), ctx: anytype) !void { 1544 const DB = rp.Repo(.xit, .{}).DB; 1545 try repo.core.db_file.lock(io, .exclusive); 1546 defer repo.core.db_file.unlock(io); 1547 1548 const history = try DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 1549 try history.appendContext(.{ .slot = try history.getSlot(-1) }, ctx); 1550 } 1551 1552 // recursively copy the contents of src_dir into dest_dir 1553 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 1554 var iter = src_dir.iterate(); 1555 while (try iter.next(io)) |entry| { 1556 switch (entry.kind) { 1557 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 1558 .directory => { 1559 try dest_dir.createDirPath(io, entry.name); 1560 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1561 defer dest_entry_dir.close(io); 1562 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1563 defer src_entry_dir.close(io); 1564 try copyDir(io, src_entry_dir, dest_entry_dir); 1565 }, 1566 else => {}, 1567 } 1568 } 1569 } 1570