╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ net.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
1889 var dir = try std.Io.Dir.cwd().openDir(ctx.io, path, .{ .iterate = true }); 1890 defer dir.close(ctx.io); 1891 var entries = dir.iterate(); 1892 while (try entries.next(ctx.io)) |entry| { 1893 const child = try std.Io.Dir.path.join(ctx.allocator, &.{ path, entry.name }); 1894 defer ctx.allocator.free(child); 1895 switch (entry.kind) { 1896 .directory => try ctx.addDir(state, index, child), 1897 .file => { 1898 const content = try dir.readFileAlloc(ctx.io, entry.name, ctx.allocator, .unlimited); 1899 defer ctx.allocator.free(content); 1900 try ctx.addFile(state, index, child, content); 1901 }, 1902 else => {}, 1903 } 1904 } 1905 } 1906 1907 pub fn run(ctx: @This(), cursor: *R.DB.Cursor(.read_write)) !void { 1908 var moment = try R.DB.HashMap(.read_write).init(cursor.*); 1909 const state = R.State(.read_write){ .core = ctx.core, .extra = .{ .moment = &moment } }; 1910 const head_oid = try rf.readHeadRecurMaybe(.xit, opts, state.readOnly(), ctx.io); 1911 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); 1912 defer index.deinit(); 1913 switch (ctx.files) { 1914 .files => |updates| for (updates) |file| try ctx.addFile(state, &index, file.path, file.content), 1915 .dirs => |dirs| for (dirs) |dir| try ctx.addDir(state, &index, dir), 1916 } 1917 var tree = try xit.object.Tree.initFromIndex(.xit, opts, state, ctx.io, ctx.allocator, &index); 1918 defer tree.deinit(); 1919 var head_buffer: [rf.MAX_REF_CONTENT_SIZE]u8 = undefined; 1920 const head = try rf.readHead(.xit, opts, state.readOnly(), ctx.io, &head_buffer) orelse return error.HeadNotFound; 1921 ctx.result.* = try xit.object.writeCommit(.xit, opts, state, ctx.io, ctx.allocator, ctx.metadata, &tree, head.ref); 1922 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) }); 1923 } 1924 }; 1925 try repo.core.db_file.lock(io, .exclusive); 1926 defer repo.core.db_file.unlock(io); 1927 const history = try R.DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 1928 try history.appendContext(.{ .slot = try history.getSlot(-1) }, Ctx{ 1929 .core = &repo.core, 1930 .io = io, 1931 .allocator = allocator, 1932 .files = files, 1933 .metadata = metadata, 1934 .result = &result, 1935 }); 1936 return result; 1937 } 1938