╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1427 1428 pub fn run(ctx: @This(), cursor: *DB.Cursor(.read_write)) !void { 1429 const opts: rp.RepoOpts(.xit) = .{}; 1430 var moment = try DB.HashMap(.read_write).init(cursor.*); 1431 const state = Repo.State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1432 try evt.commitEvents(.xit, opts, state, ctx.io, ctx.allocator, ctx.ref, ctx.events, .{ctx.parent}); 1433 const tip = (try xit.ref.readRecur(.xit, opts, state.readOnly(), ctx.io, .{ .ref = ctx.ref })) orelse return error.NotFound; 1434 try xit.undo.write(opts, state, std.Io.Timestamp.now(ctx.io, .real).toSeconds(), .{ 1435 .commit = try .init("seed conflicting events", tip, opts.max_read_size), 1436 }); 1437 } 1438 }; 1439 1440 try transaction(io, repo, Ctx{ 1441 .core = &repo.core, 1442 .io = io, 1443 .allocator = allocator, 1444 .ref = ref, 1445 .events = events, 1446 .parent = parent, 1447 }); 1448 } 1449 1450 // append `ctx` to the repo's history as one transaction. the fixtures write a 1451 // few states the normal paths have no way to produce 1452 fn transaction(io: std.Io, repo: *rp.Repo(.xit, .{}), ctx: anytype) !void { 1453 const DB = rp.Repo(.xit, .{}).DB; 1454 try repo.core.db_file.lock(io, .exclusive); 1455 defer repo.core.db_file.unlock(io); 1456 1457 const history = try DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 1458 try history.appendContext(.{ .slot = try history.getSlot(-1) }, ctx); 1459 } 1460 1461 // recursively copy the contents of src_dir into dest_dir 1462 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 1463 var iter = src_dir.iterate(); 1464 while (try iter.next(io)) |entry| { 1465 switch (entry.kind) { 1466 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 1467 .directory => { 1468 try dest_dir.createDirPath(io, entry.name); 1469 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1470 defer dest_entry_dir.close(io); 1471 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1472 defer src_entry_dir.close(io); 1473 try copyDir(io, src_entry_dir, dest_entry_dir); 1474 }, 1475 else => {}, 1476 } 1477 } 1478 } 1479