╭ changed ────╮ │src/event.zig│ ╰─────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭──────────╮ │← previous│ ╰──────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │341 │ │342 if (is_rebased) { │ │343 const oldest_object_id = commit_iter.oldest_object_id orelse return error.OidNotFound; │ │208 - var oldest_object = try obj.Object(.xit, repo_opts).init(state.readOnly(), io, allocator, &std.fmt.bytesToHex(oldest_object_id, .lower));│ │344 + var oldest_object = try obj.Object(repo_kind, repo_opts).init(read_state, io, allocator, &std.fmt.bytesToHex(oldest_object_id, .lower)); │ │345 defer oldest_object.deinit(); │ │346 │ │347 const parent_oids = oldest_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │386 } │ │387 │ │388 while (try commit_iter.next()) |repo_event_oid| { │ │253 - var commit_object = try obj.Object(.xit, repo_opts).init(state.readOnly(), io, allocator, &std.fmt.bytesToHex(repo_event_oid, .lower));│ │389 + var commit_object = try obj.Object(repo_kind, repo_opts).init(read_state, io, allocator, &std.fmt.bytesToHex(repo_event_oid, .lower)); │ │390 defer commit_object.deinit(); │ │391 │ │392 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │417 const parent_haxy_moment_cursor = try haxy_moments.getCursor(hash.bytesToInt(repo_opts.hash, &oid)) orelse return error.CursorNotFound; │ │418 const parent_haxy_moment = try DB.HashMap(.read_only).init(parent_haxy_moment_cursor); │ │419 │ │284 - const baseline_oid_hex = try mrg.commonAncestor(.xit, repo_opts, state.readOnly(), io, allocator, &parent_oids[0], parent_oid); │ │420 + const baseline_oid_hex = try mrg.commonAncestor(repo_kind, repo_opts, read_state, io, allocator, &parent_oids[0], parent_oid); │ │421 var baseline_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; │ │422 _ = try std.fmt.hexToBytes(&baseline_oid, &baseline_oid_hex); │ │423 const baseline_haxy_moment_cursor = try haxy_moments.getCursor(hash.bytesToInt(repo_opts.hash, &baseline_oid)) orelse return error.CursorNotFound;│ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │460 last_object_id_maybe = repo_event_oid; │ │461 │ │462 // prevent any of the data created above from being mutated by future iterations of this loop│ │327 - try state.core.db.freeze(); │ │463 + try db.freeze(); │ │464 } │ │465 │ │466 if (last_object_id_maybe) |*last_object_id| { │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │331 - try state.extra.moment.put(hash.hashInt(repo_opts.hash, "haxy-last-object-id"), .{ .bytes = last_object_id });│ │467 + try moment.put(hash.hashInt(repo_opts.hash, "haxy-last-object-id"), .{ .bytes = last_object_id }); │ │468 } │ │469 } │ │470 │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │472 comptime repo_opts: rp.RepoOpts(.xit), │ │473 repo: *rp.Repo(.xit, repo_opts), │ │474 ) !rp.Repo(.xit, repo_opts).DB.HashMap(.read_only) { │ │339 - const DB = rp.Repo(.xit, repo_opts).DB; │ │340 - const history = try DB.ArrayList(.read_only).init(repo.core.db.rootCursor().readOnly()); │ │341 - const moment_cursor = try history.getCursor(-1) orelse return error.NotFound; │ │475 + return currentMomentFromDb(repo_opts.hash, &repo.core.db); │ │476 +} │ │477 + │ │478 +// the oid of the last event commit consumed into `db`, or null before any │ │479 +// consume completed │ │480 +fn lastConsumedOid( │ │481 + comptime hash_kind: hash.HashKind, │ │482 + db: *EventDB(hash_kind), │ │483 +) !?[hash.byteLen(hash_kind)]u8 { │ │484 + const DB = EventDB(hash_kind); │ │485 + const history = try DB.ArrayList(.read_only).init(db.rootCursor().readOnly()); │ │486 + const moment_cursor = try history.getCursor(-1) orelse return null; │ │487 const moment = try DB.HashMap(.read_only).init(moment_cursor); │ │343 - const last_object_id_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy-last-object-id")) orelse return error.NotFound;│ │344 - var last_object_id: [hash.byteLen(repo_opts.hash)]u8 = undefined; │ │488 + const last_object_id_cursor = try moment.getCursor(hash.hashInt(hash_kind, "haxy-last-object-id")) orelse return null; │ │489 + var last_object_id: [hash.byteLen(hash_kind)]u8 = undefined; │ │490 _ = try last_object_id_cursor.readBytes(&last_object_id); │ │346 - const haxy_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy")) orelse return error.NotFound; │ │491 + return last_object_id; │ │492 +} │ │493 + │ │494 +pub fn currentMomentFromDb( │ │495 + comptime hash_kind: hash.HashKind, │ │496 + db: *EventDB(hash_kind), │ │497 +) !EventDB(hash_kind).HashMap(.read_only) { │ │498 + const DB = EventDB(hash_kind); │ │499 + const last_object_id = (try lastConsumedOid(hash_kind, db)) orelse return error.NotFound; │ │500 + const history = try DB.ArrayList(.read_only).init(db.rootCursor().readOnly()); │ │501 + const moment_cursor = try history.getCursor(-1) orelse return error.NotFound; │ │502 + const moment = try DB.HashMap(.read_only).init(moment_cursor); │ │503 + const haxy_cursor = try moment.getCursor(hash.hashInt(hash_kind, "haxy")) orelse return error.NotFound; │ │504 const haxy = try DB.ArrayList(.read_only).init(haxy_cursor); │ │505 const haxy_moments_cursor = try haxy.getCursor(-1) orelse return error.NotFound; │ │506 const haxy_moments = try DB.HashMap(.read_only).init(haxy_moments_cursor); │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │350 - const haxy_moment_cursor = try haxy_moments.getCursor(hash.bytesToInt(repo_opts.hash, &last_object_id)) orelse return error.NotFound;│ │507 + const haxy_moment_cursor = try haxy_moments.getCursor(hash.bytesToInt(hash_kind, &last_object_id)) orelse return error.NotFound; │ │508 return try DB.HashMap(.read_only).init(haxy_moment_cursor); │ │509 } │ │510 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1027 // 3. stores its temporary state in a file on disk to avoid OOMs │ │1028 // │ │1029 │ │ 873 -pub fn CommitIterator(comptime repo_opts: rp.RepoOpts(.xit)) type { │ │1030 +pub fn CommitIterator(comptime repo_kind: rp.RepoKind, comptime repo_opts: rp.RepoOpts(repo_kind)) type {│ │1031 return struct { │ │ 875 - const DB = rp.Repo(.xit, repo_opts).DB; │ │1032 + const DB = EventDB(repo_opts.hash); │ │1033 const db_name = "haxy-repo-events.db"; │ │1034 │ │1035 repo_dir: std.Io.Dir, │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────╮ │1049 oldest_object_id: ?[hash.byteLen(repo_opts.hash)]u8, │ │1050 │ │1051 pub fn init( │ │ 895 - state: rp.Repo(.xit, repo_opts).State(.read_only), │ │1052 + state: rp.Repo(repo_kind, repo_opts).State(.read_only),│ │1053 io: std.Io, │ │1054 allocator: std.mem.Allocator, │ │1055 consumed_object_ids: DB.HashMap(.read_only), │ ╰─────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1056 ref: rf.Ref, │ │ 900 - ) !CommitIterator(repo_opts) { │ │1057 + ) !CommitIterator(repo_kind, repo_opts) { │ │1058 const db_file = try state.core.repo_dir.createFile(io, db_name, .{ .truncate = true, .lock = .exclusive, .read = true });│ │1059 errdefer { │ │1060 db_file.close(io); │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯