╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ net.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1755 try index.addTreeEntryFile(&.{ .oid = oid, .mode = @bitCast(@as(u32, 0o100644)) }, path_parts, content.len, 0); 1756 } 1757 1758 fn addDir(ctx: @This(), state: R.State(.read_write), index: *Index, path: []const u8) anyerror!void { 1759 var dir = try std.Io.Dir.cwd().openDir(ctx.io, path, .{ .iterate = true }); 1760 defer dir.close(ctx.io); 1761 var entries = dir.iterate(); 1762 while (try entries.next(ctx.io)) |entry| { 1763 const child = try std.Io.Dir.path.join(ctx.allocator, &.{ path, entry.name }); 1764 defer ctx.allocator.free(child); 1765 switch (entry.kind) { 1766 .directory => try ctx.addDir(state, index, child), 1767 .file => { 1768 const content = try dir.readFileAlloc(ctx.io, entry.name, ctx.allocator, .unlimited); 1769 defer ctx.allocator.free(content); 1770 try ctx.addFile(state, index, child, content); 1771 }, 1772 else => {}, 1773 } 1774 } 1775 } 1776 1777 pub fn run(ctx: @This(), cursor: *R.DB.Cursor(.read_write)) !void { 1778 var moment = try R.DB.HashMap(.read_write).init(cursor.*); 1779 const state = R.State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1780 const head_oid = try rf.readHeadRecurMaybe(.xit, opts, state.readOnly(), ctx.io); 1781 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); 1782 defer index.deinit(); 1783 switch (ctx.files) { 1784 .files => |updates| for (updates) |file| try ctx.addFile(state, &index, file.path, file.content), 1785 .dirs => |dirs| for (dirs) |dir| try ctx.addDir(state, &index, dir), 1786 } 1787 var tree = try xit.object.Tree.initFromIndex(.xit, opts, state, ctx.io, ctx.allocator, &index); 1788 defer tree.deinit(); 1789 var head_buffer: [rf.MAX_REF_CONTENT_SIZE]u8 = undefined; 1790 const head = try rf.readHead(.xit, opts, state.readOnly(), ctx.io, &head_buffer) orelse return error.HeadNotFound; 1791 ctx.result.* = try xit.object.writeCommit(.xit, opts, state, ctx.io, ctx.allocator, ctx.metadata, &tree, head.ref); 1792 try xit.undo.write(opts, state, std.Io.Timestamp.now(ctx.io, .real).toSeconds(), .{ .commit = try .init(ctx.metadata.message, ctx.result.*, opts.max_read_size) }); 1793 } 1794 }; 1795 try repo.core.db_file.lock(io, .exclusive); 1796 defer repo.core.db_file.unlock(io); 1797 const history = try R.DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 1798 try history.appendContext(.{ .slot = try history.getSlot(-1) }, Ctx{ 1799 .core = &repo.core, 1800 .io = io, 1801 .allocator = allocator, 1802 .files = files, 1803 .metadata = metadata, 1804 .result = &result, 1805 }); 1806 return result; 1807 } 1808