╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
348 }, 349 null, 350 .{ .kind = .head, .name = "haxy/meta" }, 351 ); 352 } 353 } 354 355 // 356 // read and parse all of the events from the repo 357 // 358 359 events.clearRetainingCapacity(); 360 361 { 362 const commits = try Commit.readCommitsFromRepo(&arena, &repo, "haxy/meta"); 363 364 // parse commit messages as JSON into event values. 365 // add events in reverse order so the earliest event is first. 366 for (0..commits.len) |i| { 367 const commit = commits[commits.len - i - 1]; 368 const event = try std.json.parseFromSliceLeaky(evt.Event, arena.allocator(), commit.message, .{}); 369 try events.append(allocator, .{ 370 .parent_oid = commit.parent_oid, 371 .oid = commit.oid, 372 .event = event, 373 }); 374 } 375 } 376 377 // 378 // consume events into the database 379 // 380 381 { 382 try evt.consume(Repo.DB, repo_opts.hash, io, &repo.core.db, repo.core.db_file, events.items); 383 384 const history = try Repo.DB.ArrayList(.read_only).init(repo.core.db.rootCursor().readOnly()); 385 386 // read the moment we just created 387 const moment_cursor = try history.getCursor(-1) orelse return error.NotFound; 388 const moment = try Repo.DB.HashMap(.read_only).init(moment_cursor); 389 390 // get the last object id 391 const last_object_id_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy-last-object-id")) orelse return error.NotFound; 392 var last_object_id: [hash.byteLen(repo_opts.hash)]u8 = undefined; 393 _ = try last_object_id_cursor.readBytes(&last_object_id); 394 395 const haxy_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy")) orelse return error.NotFound; 396 const haxy = try Repo.DB.ArrayList(.read_only).init(haxy_cursor); 397 398 try std.testing.expectEqual(1, try haxy.count()); 399 400 const haxy_moments_cursor = try haxy.getCursor(-1) orelse return error.NotFound; 401 const haxy_moments = try Repo.DB.HashMap(.read_only).init(haxy_moments_cursor); 402 403 const haxy_moment_cursor = try haxy_moments.getCursor(hash.bytesToInt(repo_opts.hash, &last_object_id)) orelse return error.NotFound; 404 const haxy_moment = try Repo.DB.HashMap(.read_only).init(haxy_moment_cursor); 405 406 // get the map of issues 407 const event_id_to_issue_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, "event-id->issue")) orelse return error.NotFound; 408 const event_id_to_issue = try Repo.DB.HashMap(.read_only).init(event_id_to_issue_cursor); 409 410 // the first issue no longer exists 411 try std.testing.expect(null == try event_id_to_issue.getCursor(hash.hashInt(repo_opts.hash, &first_event_id))); 412 } 413 } 414