╭ changed ─────────────╮ │src/ui/Repo/Issues.zig│ ╰──────────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │38 │ │39 const Self = @This(); │ │40 │ │41 -pub fn init( │ │42 - arena: *std.heap.ArenaAllocator, │ │43 - session: *ui.Session, │ │44 - source_maybe: ?ui.RepoSource, │ │45 - identity: []const u8, │ │46 - tag: []const u8, │ │47 - selected_id: []const u8, │ │48 -) !Self { │ │49 - const aa = arena.allocator(); │ │50 - const empty: Self = .{ │ │41 +// an empty listing, for the wasm / no-repo paths. │ │42 +pub fn emptyResult(aa: std.mem.Allocator, identity: []const u8, tag: []const u8, selected_id: []const u8) !Self {│ │43 + return .{ │ │44 .identity = try aa.dupe(u8, identity), │ │45 .tag = try aa.dupe(u8, tag), │ │46 .selected_id = try aa.dupe(u8, selected_id), │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │47 .issues = &.{}, │ │48 .prev_id = null, │ │49 .next_id = null, │ │57 - }; │ │58 - │ │59 - // no filesystem (wasm) or nowhere to look: empty listing. the wasm path │ │60 - // never calls init anyway — it rebuilds from the serialized snapshot. │ │61 - const io = session.io orelse return empty; │ │62 - const source = source_maybe orelse return empty; │ │63 - │ │64 - // issues live in the repo's own xit db, so a git-backed repo has none. │ │65 - if (source.repo_kind == .git) return empty; │ │66 - │ │67 - // open with the arena's backing allocator (transient; the issue strings are │ │68 - // duped into the page arena so they outlive the repo handle). │ │69 - const gpa = arena.child_allocator; │ │70 - var any_repo = rp.AnyRepo(.xit, .{}).open(io, gpa, .{ .path = source.path }) catch return empty;│ │71 - defer any_repo.deinit(io, gpa); │ │72 - │ │73 - return switch (any_repo) { │ │74 - inline else => |*repo| collect(repo.self_repo_opts, arena, repo, empty), │ │50 }; │ │51 } │ │52 │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────╮ │78 -// read one window of the repo's issues (filtered to empty.tag when set), │ │53 +// read one window of an opened repo's issues (filtered to `tag` when set), │ │54 // ordered by creation time (oldest first), starting at the issue │ │80 -// empty.selected_id names ("" = the beginning). │ │81 -fn collect( │ │82 - comptime repo_opts: rp.RepoOpts(.xit), │ │55 +// `selected_id` names ("" = the beginning). issues live in the repo's own │ │56 +// xit db, so a git-backed repo has none. │ │57 +pub fn init( │ │58 + comptime repo_kind: rp.RepoKind, │ │59 + comptime repo_opts: rp.RepoOpts(repo_kind), │ │60 arena: *std.heap.ArenaAllocator, │ │84 - repo: *rp.Repo(.xit, repo_opts), │ │85 - empty: Self, │ │61 + repo: *rp.Repo(repo_kind, repo_opts), │ │62 + identity: []const u8, │ │63 + tag: []const u8, │ │64 + selected_id: []const u8, │ │65 ) !Self { │ │66 + const empty = try emptyResult(arena.allocator(), identity, tag, selected_id);│ │67 + if (repo_kind == .git) return empty; │ │68 + │ │69 const aa = arena.allocator(); │ │88 - const DB = rp.Repo(.xit, repo_opts).DB; │ │70 + const DB = rp.Repo(repo_kind, repo_opts).DB; │ │71 const rooted = empty.selected_id.len != 0; │ │72 const tagged = empty.tag.len != 0; │ │73 // an explicitly named issue or tag that doesn't exist is a bad url │ ╰─────────────────────────────────────────────────────────────────────────────────────╯