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