X-Git-Url: https://gitweb.ps.run/ziggit/blobdiff_plain/f8e639c5f6c9ce6eb04a851cc3d90dce8f71cf4f..8bb933882251b1c52c42f95af32c163149005396:/git.zig diff --git a/git.zig b/git.zig index 22bdf5d..80e9aac 100644 --- a/git.zig +++ b/git.zig @@ -410,7 +410,10 @@ const Repo = struct { }; test "print HEAD" { - const alloc = std.testing.allocator; + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + const alloc = arena.allocator(); + var repo = try Repo.open(alloc, "../imgui/.git"); defer repo.close(); @@ -420,7 +423,10 @@ test "print HEAD" { } test "parse idx" { - const alloc = std.testing.allocator; + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + const alloc = arena.allocator(); + var repo = try Repo.open(alloc, "../imgui/.git"); defer repo.close(); @@ -431,7 +437,10 @@ test "parse idx" { } test "get object" { - const alloc = std.testing.allocator; + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + const alloc = arena.allocator(); + var repo = try Repo.open(alloc, "../imgui/.git"); defer repo.close(); @@ -445,7 +454,10 @@ test "get object" { } test "parse commit" { - const alloc = std.testing.allocator; + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + const alloc = arena.allocator(); + var repo = try Repo.open(alloc, "../imgui/.git"); defer repo.close(); @@ -464,7 +476,10 @@ test "parse commit" { } test "get tree" { - const alloc = std.testing.allocator; + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + const alloc = arena.allocator(); + var repo = try Repo.open(alloc, "../imgui/.git"); defer repo.close(); @@ -476,7 +491,10 @@ test "get tree" { } test "parse tree" { - const alloc = std.testing.allocator; + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + const alloc = arena.allocator(); + var repo = try Repo.open(alloc, "../imgui/.git"); defer repo.close(); @@ -496,7 +514,10 @@ test "parse tree" { } test "list commits" { - const alloc = std.testing.allocator; + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + const alloc = arena.allocator(); + var repo = try Repo.open(alloc, "../imgui/.git"); defer repo.close(); @@ -520,7 +541,10 @@ test "list commits" { } test "list blobs" { - const alloc = std.testing.allocator; + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + const alloc = arena.allocator(); + var repo = try Repo.open(alloc, "../imgui/.git"); defer repo.close(); @@ -546,3 +570,30 @@ test "list blobs" { } } } + +test "basic frontend" { + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + const alloc = arena.allocator(); + + var repo = try Repo.open(alloc, "../imgui/.git"); + defer repo.close(); + + const head = try repo.getHead(); + + var id = head; + + for (0..3) |_| { + if (try repo.getObject(id)) |o| { + defer alloc.free(o.data); + + switch (try o.parse(alloc)) { + .c => |c| { + std.debug.print("commit {x}:\n tree: {x}\n parent: {x}\n author: {s}\n committer: {s}\n message: {s}\n", .{ id, c.tree, c.parent, c.author, c.committer, c.message }); + id = c.parent; + }, + else => {}, + } + } + } +}