╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
1594 } 1595 1596 // append `ctx` to the repo's history as one transaction. the fixtures write a 1597 // few states the normal paths have no way to produce 1598 // fixtures commit directly, so the ref tips are indexed by hand. a fork gets 1599 // no commit index, as in production. 1600 const Reindex = struct { 1601 io: std.Io, 1602 allocator: std.mem.Allocator, 1603 core: *rp.Repo(.xit, .{}).Core, 1604 commits: bool, 1605 1606 pub fn run(ctx: @This(), cursor: *rp.Repo(.xit, .{}).DB.Cursor(.read_write)) !void { 1607 var moment = try rp.Repo(.xit, .{}).DB.HashMap(.read_write).init(cursor.*); 1608 const state = rp.Repo(.xit, .{}).State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1609 _ = try find.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, null); 1610 if (ctx.commits) _ = try srch_cmmt.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, &.{}, null); 1611 } 1612 }; 1613 1614 fn transaction(io: std.Io, repo: *rp.Repo(.xit, .{}), ctx: anytype) !void { 1615 const DB = rp.Repo(.xit, .{}).DB; 1616 try repo.core.db_file.lock(io, .exclusive); 1617 defer repo.core.db_file.unlock(io); 1618 1619 const history = try DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 1620 try history.appendContext(.{ .slot = try history.getSlot(-1) }, ctx); 1621 } 1622 1623 // recursively copy the contents of src_dir into dest_dir 1624 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 1625 var iter = src_dir.iterate(); 1626 while (try iter.next(io)) |entry| { 1627 switch (entry.kind) { 1628 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 1629 .directory => { 1630 try dest_dir.createDirPath(io, entry.name); 1631 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1632 defer dest_entry_dir.close(io); 1633 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1634 defer src_entry_dir.close(io); 1635 try copyDir(io, src_entry_dir, dest_entry_dir); 1636 }, 1637 else => {}, 1638 } 1639 } 1640 } 1641