╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
1560 events: []const evt.EventWithId, 1561 parent: [hash.hexLen(.sha1)]u8, 1562 ) !void { 1563 const Repo = rp.Repo(.xit, .{}); 1564 const DB = Repo.DB; 1565 const Ctx = struct { 1566 core: *Repo.Core, 1567 io: std.Io, 1568 allocator: std.mem.Allocator, 1569 ref: xit.ref.Ref, 1570 events: []const evt.EventWithId, 1571 parent: [hash.hexLen(.sha1)]u8, 1572 1573 pub fn run(ctx: @This(), cursor: *DB.Cursor(.read_write)) !void { 1574 const opts: rp.RepoOpts(.xit) = .{}; 1575 var moment = try DB.HashMap(.read_write).init(cursor.*); 1576 const state = Repo.State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1577 try evt.commitEvents(.xit, opts, state, ctx.io, ctx.allocator, ctx.ref, ctx.events, .{ctx.parent}); 1578 const tip = (try xit.ref.readRecur(.xit, opts, state.readOnly(), ctx.io, .{ .ref = ctx.ref })) orelse return error.NotFound; 1579 try xit.undo.write(opts, state, std.Io.Timestamp.now(ctx.io, .real).toSeconds(), .{ 1580 .commit = try .init("seed conflicting events", tip, opts.max_read_size), 1581 }); 1582 } 1583 }; 1584 1585 try transaction(io, repo, Ctx{ 1586 .core = &repo.core, 1587 .io = io, 1588 .allocator = allocator, 1589 .ref = ref, 1590 .events = events, 1591 .parent = parent, 1592 }); 1593 } 1594 1595 // append `ctx` to the repo's history as one transaction. the fixtures write a 1596 // few states the normal paths have no way to produce 1597 // fixtures commit directly, so the ref tips are indexed by hand. a fork gets 1598 // no commit index, as in production. 1599 const Reindex = struct { 1600 io: std.Io, 1601 allocator: std.mem.Allocator, 1602 core: *rp.Repo(.xit, .{}).Core, 1603 commits: bool, 1604 1605 pub fn run(ctx: @This(), cursor: *rp.Repo(.xit, .{}).DB.Cursor(.read_write)) !void { 1606 var moment = try rp.Repo(.xit, .{}).DB.HashMap(.read_write).init(cursor.*); 1607 const state = rp.Repo(.xit, .{}).State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1608 _ = try find.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, null); 1609 if (ctx.commits) _ = try srch_cmmt.refreshInTransaction(.{}, state, &moment, ctx.io, ctx.allocator, &.{}, null); 1610 } 1611 }; 1612 1613 fn transaction(io: std.Io, repo: *rp.Repo(.xit, .{}), ctx: anytype) !void { 1614 const DB = rp.Repo(.xit, .{}).DB; 1615 try repo.core.db_file.lock(io, .exclusive); 1616 defer repo.core.db_file.unlock(io); 1617 1618 const history = try DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 1619 try history.appendContext(.{ .slot = try history.getSlot(-1) }, ctx); 1620 } 1621 1622 // recursively copy the contents of src_dir into dest_dir 1623 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 1624 var iter = src_dir.iterate(); 1625 while (try iter.next(io)) |entry| { 1626 switch (entry.kind) { 1627 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 1628 .directory => { 1629 try dest_dir.createDirPath(io, entry.name); 1630 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1631 defer dest_entry_dir.close(io); 1632 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1633 defer src_entry_dir.close(io); 1634 try copyDir(io, src_entry_dir, dest_entry_dir); 1635 }, 1636 else => {}, 1637 } 1638 } 1639 } 1640