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