╭ changed ────╮ │src/event.zig│ ╰─────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │53 try file.writeStreamingAll(io, "# HAXY\n\nWelcome to your Haxy instance!\n\nEdit `admin/ABOUT.md` in the server dir to change what this page says.");│ │54 } │ │55 try repo.add(io, allocator, &.{admin_about_path}); │ │56 - _ = try repo.commit(io, allocator, .{ .author = "haxy <haxy@localhost>", .message = "init" }); │ │56 + const init_oid_hex = try repo.commit(io, allocator, .{ .author = "haxy <haxy@localhost>", .message = "init" }); │ │57 + │ │58 + // an empty haxy state on the init commit, so pages render before the first │ │59 + // event. that event's root commit is unrelated to init, so consume treats │ │60 + // it as rebased to the beginning and discards this state. │ │61 + { │ │62 + var init_oid: [hash.byteLen(admin_repo_opts.hash)]u8 = undefined; │ │63 + _ = try std.fmt.hexToBytes(&init_oid, &init_oid_hex); │ │64 + │ │65 + const Ctx = struct { │ │66 + init_oid: *const [hash.byteLen(admin_repo_opts.hash)]u8, │ │67 + │ │68 + pub fn run(ctx: @This(), cursor: *AdminDB.Cursor(.read_write)) !void { │ │69 + const moment = try AdminDB.HashMap(.read_write).init(cursor.*); │ │70 + try moment.put(hash.hashInt(admin_repo_opts.hash, last_object_id_key), .{ .bytes = ctx.init_oid }); │ │71 + const haxy_history = try AdminDB.ArrayList(.read_write).init(try moment.putCursor(hash.hashInt(admin_repo_opts.hash, history_key))); │ │72 + const haxy_moments = try AdminDB.HashMap(.read_write).init(try haxy_history.appendCursor()); │ │73 + const haxy_moment = try AdminDB.HashMap(.read_write).init(try haxy_moments.putCursor(hash.bytesToInt(admin_repo_opts.hash, ctx.init_oid))); │ │74 + try haxy_moment.put(hash.hashInt(admin_repo_opts.hash, moment_index_key), .{ .uint = 0 }); │ │75 + } │ │76 + }; │ │77 + │ │78 + try repo.core.db_file.lock(io, .exclusive); │ │79 + defer repo.core.db_file.unlock(io); │ │80 + │ │81 + const history = try AdminDB.ArrayList(.read_write).init(repo.core.db.rootCursor()); │ │82 + try history.appendContext(.{ .slot = try history.getSlot(-1) }, Ctx{ .init_oid = &init_oid }); │ │83 + } │ │84 + │ │85 return repo; │ │86 } │ │87 │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────╮ │1185 // we have a repo event with no parent, which means it is now│ │1186 // the very first event. all we need to do is set the haxy │ │1187 // history list to be empty and make a new haxy_moments map │ │1160 - // to work with. │ │1188 + // to work with. a new admin repo's first event lands here │ │1189 + // too, discarding the empty state initAdminRepo wrote. │ │1190 │ │1191 try haxy_history.slice(0); │ │1192 haxy_moments_cursor = try haxy_history.appendCursor(); │ ╰───────────────────────────────────────────────────────────────────────────────────────╯