╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ net.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1736 const child = try std.fs.path.join(ctx.allocator, &.{ path, entry.name }); 1737 defer ctx.allocator.free(child); 1738 switch (entry.kind) { 1739 .directory => try ctx.addDir(state, index, child), 1740 .file => { 1741 const content = try dir.readFileAlloc(ctx.io, entry.name, ctx.allocator, .unlimited); 1742 defer ctx.allocator.free(content); 1743 try ctx.addFile(state, index, child, content); 1744 }, 1745 else => {}, 1746 } 1747 } 1748 } 1749 1750 pub fn run(ctx: @This(), cursor: *R.DB.Cursor(.read_write)) !void { 1751 var moment = try R.DB.HashMap(.read_write).init(cursor.*); 1752 const state = R.State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1753 const head_oid = try rf.readHeadRecurMaybe(.xit, opts, state.readOnly(), ctx.io); 1754 var index = if (head_oid) |oid| try Index.initFromCommit(state.readOnly(), ctx.io, ctx.allocator, &oid) else try Index.init(state.readOnly(), ctx.io, ctx.allocator); 1755 defer index.deinit(); 1756 switch (ctx.files) { 1757 .files => |updates| for (updates) |file| try ctx.addFile(state, &index, file.path, file.content), 1758 .dirs => |dirs| for (dirs) |dir| try ctx.addDir(state, &index, dir), 1759 } 1760 var tree = try xit.object.Tree.initFromIndex(.xit, opts, state, ctx.io, ctx.allocator, &index); 1761 defer tree.deinit(); 1762 var head_buffer: [rf.MAX_REF_CONTENT_SIZE]u8 = undefined; 1763 const head = try rf.readHead(.xit, opts, state.readOnly(), ctx.io, &head_buffer) orelse return error.HeadNotFound; 1764 ctx.result.* = try xit.object.writeCommit(.xit, opts, state, ctx.io, ctx.allocator, ctx.metadata, &tree, head.ref); 1765 try xit.undo.writeMessage(opts, state, .{ .commit = ctx.metadata }); 1766 } 1767 }; 1768 try repo.core.db_file.lock(io, .exclusive); 1769 defer repo.core.db_file.unlock(io); 1770 const history = try R.DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 1771 try history.appendContext(.{ .slot = try history.getSlot(-1) }, Ctx{ 1772 .core = &repo.core, 1773 .io = io, 1774 .allocator = allocator, 1775 .files = files, 1776 .metadata = metadata, 1777 .result = &result, 1778 }); 1779 return result; 1780 } 1781