Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

main

Checks out a commit of a packfile. Intended for experimenting with and benchmarking possible optimizations to the indexing and checkout behavior.

git.main
pub fn main() !void

File

Code

pub fn main() !void {
    const allocator = std.heap.smp_allocator;

    var threaded: Io.Threaded = .init(allocator, .{});
    defer threaded.deinit();
    const io = threaded.io();

    const args = try std.process.argsAlloc(allocator);
    defer std.process.argsFree(allocator, args);
    if (args.len != 5) {
        return error.InvalidArguments; // Arguments: format packfile commit worktree
    }

    const format = std.meta.stringToEnum(Oid.Format, args[1]) orelse return error.InvalidFormat;

    var pack_file = try Io.Dir.cwd().openFile(io, args[2], .{});
    defer pack_file.close(io);
    var pack_file_buffer: [4096]u8 = undefined;
    var pack_file_reader = pack_file.reader(io, &pack_file_buffer);

    const commit = try Oid.parse(format, args[3]);
    var worktree = try Io.Dir.cwd().createDirPathOpen(io, args[4], .{});
    defer worktree.close(io);

    var git_dir = try worktree.createDirPathOpen(io, ".git", .{});
    defer git_dir.close(io);

    std.debug.print("Starting index...\n", .{});
    var index_file = try git_dir.createFile(io, "idx", .{ .read = true });
    defer index_file.close(io);
    var index_file_buffer: [4096]u8 = undefined;
    var index_file_writer = index_file.writer(io, &index_file_buffer);
    try indexPack(allocator, format, &pack_file_reader, &index_file_writer);

    std.debug.print("Starting checkout...\n", .{});
    var index_file_reader = index_file.reader(io, &index_file_buffer);
    var repository: Repository = undefined;
    try repository.init(allocator, format, &pack_file_reader, &index_file_reader);
    defer repository.deinit();
    var diagnostics: Diagnostics = .{ .allocator = allocator };
    defer diagnostics.deinit();
    try repository.checkout(io, worktree, commit, &diagnostics);

    for (diagnostics.errors.items) |err| {
        std.debug.print("Diagnostic: {}\n", .{err});
    }
}