╭──────────╮ │← previous│ ╰──────────╯ ╭ changed ─────────╮ │src/test/event.zig│ ╰──────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │606 +fn readEventsFromRepo( │ │607 + comptime Repo: type, │ │608 + comptime hash_kind: hash.HashKind, │ │609 + io: std.Io, │ │610 + arena: *std.heap.ArenaAllocator, │ │611 + repo: *Repo, │ │612 + branch_name: []const u8, │ │613 +) ![]evt.RepoEvent(hash_kind) { │ │614 + const allocator = arena.allocator(); │ │615 + │ │616 + var events: std.ArrayList(evt.RepoEvent(hash_kind)) = .empty; │ │617 + │ │618 + const ref = try repo.readRef(io, .{ .kind = .head, .name = branch_name }) orelse return error.RefNotFound; │ │619 + var commit_iter = try repo.log(io, allocator, &.{ref}); │ │620 + │ │621 + // read the message from each commit │ │622 + while (try commit_iter.next()) |commit_object| { │ │623 + var oid: [hash.byteLen(hash_kind)]u8 = undefined; │ │624 + _ = try std.fmt.hexToBytes(&oid, &commit_object.oid); │ │625 + │ │626 + const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound;│ │627 + │ │628 + if (parent_oids.len > 1) { │ │629 + // this is a merge commit │ │630 + try events.append(allocator, .{ .parent_oid = null, .oid = oid, .event = null }); │ │631 + } else { │ │632 + try commit_object.object_reader.seekTo(commit_object.content.commit.message_position); │ │633 + const message = try commit_object.object_reader.interface.allocRemaining(allocator, .unlimited); │ │634 + const event = try std.json.parseFromSliceLeaky(evt.Event, allocator, message, .{}); │ │635 + │ │636 + if (parent_oids.len == 0) { │ │637 + try events.append(allocator, .{ .parent_oid = null, .oid = oid, .event = event }); │ │638 + } else { │ │639 + var parent_oid: [hash.byteLen(hash_kind)]u8 = undefined; │ │640 + _ = try std.fmt.hexToBytes(&parent_oid, &parent_oids[0]); │ │641 + try events.append(allocator, .{ .parent_oid = parent_oid, .oid = oid, .event = event }); │ │642 + } │ │643 + } │ │644 + } │ │645 + │ │646 + return events.items; │ │647 +} │ │648 + │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯