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