╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1528 io: std.Io, 1529 allocator: std.mem.Allocator, 1530 ref: xit.ref.Ref, 1531 events: []const evt.EventWithId, 1532 parent: [hash.hexLen(.sha1)]u8, 1533 1534 pub fn run(ctx: @This(), cursor: *DB.Cursor(.read_write)) !void { 1535 const opts: rp.RepoOpts(.xit) = .{}; 1536 var moment = try DB.HashMap(.read_write).init(cursor.*); 1537 const state = Repo.State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1538 try evt.commitEvents(.xit, opts, state, ctx.io, ctx.allocator, ctx.ref, ctx.events, .{ctx.parent}); 1539 const tip = (try xit.ref.readRecur(.xit, opts, state.readOnly(), ctx.io, .{ .ref = ctx.ref })) orelse return error.NotFound; 1540 try xit.undo.write(opts, state, std.Io.Timestamp.now(ctx.io, .real).toSeconds(), .{ 1541 .commit = try .init("seed conflicting events", tip, opts.max_read_size), 1542 }); 1543 } 1544 }; 1545 1546 try transaction(io, repo, Ctx{ 1547 .core = &repo.core, 1548 .io = io, 1549 .allocator = allocator, 1550 .ref = ref, 1551 .events = events, 1552 .parent = parent, 1553 }); 1554 } 1555 1556 // append `ctx` to the repo's history as one transaction. the fixtures write a 1557 // few states the normal paths have no way to produce 1558 // fixtures commit directly, so the ref tips are indexed by hand. a fork gets 1559 // no commit index, as in production. 1560 const Reindex = struct { 1561 io: std.Io, 1562 allocator: std.mem.Allocator, 1563 core: *rp.Repo(.xit, .{}).Core, 1564 commits: bool, 1565 1566 pub fn run(ctx: @This(), cursor: *rp.Repo(.xit, .{}).DB.Cursor(.read_write)) !void { 1567 var moment = try rp.Repo(.xit, .{}).DB.HashMap(.read_write).init(cursor.*); 1568 const state = rp.Repo(.xit, .{}).State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1569 _ = try find.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, null); 1570 if (ctx.commits) _ = try srch_cmmt.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, &.{}, null); 1571 } 1572 }; 1573 1574 fn transaction(io: std.Io, repo: *rp.Repo(.xit, .{}), ctx: anytype) !void { 1575 const DB = rp.Repo(.xit, .{}).DB; 1576 try repo.core.db_file.lock(io, .exclusive); 1577 defer repo.core.db_file.unlock(io); 1578 1579 const history = try DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 1580 try history.appendContext(.{ .slot = try history.getSlot(-1) }, ctx); 1581 } 1582 1583 // recursively copy the contents of src_dir into dest_dir 1584 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 1585 var iter = src_dir.iterate(); 1586 while (try iter.next(io)) |entry| { 1587 switch (entry.kind) { 1588 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 1589 .directory => { 1590 try dest_dir.createDirPath(io, entry.name); 1591 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1592 defer dest_entry_dir.close(io); 1593 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1594 defer src_entry_dir.close(io); 1595 try copyDir(io, src_entry_dir, dest_entry_dir); 1596 }, 1597 else => {}, 1598 } 1599 } 1600 } 1601