╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
429 const owner_id_cursor = try name_to_user_id.getCursor(hash.hashInt(admin_repo_opts.hash, owner_name)) orelse return null; 430 var owner_user_id: [event_id_size]u8 = undefined; 431 _ = try owner_id_cursor.readBytes(&owner_user_id); 432 433 var id_bytes: [event_id_size]u8 = undefined; 434 io.random(&id_bytes); 435 const event_id_hex = std.fmt.bytesToHex(id_bytes, .lower); 436 437 try commitAndConsume(admin_repo_opts, io, allocator, &repo, events_ref, &[_]EventWithId{.{ 438 .id = event_id_hex, 439 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 440 .event = .{ .repo = .{ 441 .user_id = &owner_user_id, 442 .name = repo_name, 443 .description = "", 444 .enable_issue = true, 445 } }, 446 }}); 447 448 return event_id_hex; 449 } 450 451 // 452 // reading from xitdb 453 // 454 455 pub fn read( 456 comptime T: type, 457 comptime DB: type, 458 comptime hash_kind: hash.HashKind, 459 arena: *std.heap.ArenaAllocator, 460 map: DB.HashMap(.read_only), 461 ) !T { 462 var event: T = undefined; 463 464 switch (@typeInfo(T)) { 465 .@"struct" => |struct_info| { 466 inline for (struct_info.fields) |field| { 467 switch (@typeInfo(field.type)) { 468 .pointer => |pointer_info| { 469 if (pointer_info.size == .slice and pointer_info.child == u8 and pointer_info.is_const) { 470 @field(event, field.name) = try readBytes(DB, hash_kind, arena.allocator(), map, field.name); 471 } else { 472 @compileError("unsupported read field type: " ++ @typeName(field.type)); 473 } 474 }, 475 .array => |array_info| { 476 if (array_info.child == u8) { 477 const bytes = try readBytes(DB, hash_kind, arena.allocator(), map, field.name); 478 if (bytes.len != array_info.len) return error.InvalidByteArrayLength; 479 @memcpy(@field(event, field.name)[0..], bytes); 480 } else { 481 @compileError("unsupported read field type: " ++ @typeName(field.type)); 482 } 483 }, 484 .bool => @field(event, field.name) = try readBool(DB, hash_kind, map, field.name), 485 .int => |int_info| switch (int_info.signedness) { 486 .unsigned => @field(event, field.name) = @intCast(try readUint(DB, hash_kind, map, field.name)), 487 .signed => @field(event, field.name) = @intCast(try readInt(DB, hash_kind, map, field.name)), 488 }, 489 else => @compileError("unsupported read field type: " ++ @typeName(field.type)), 490 } 491 } 492 }, 493 else => @compileError("read expects a struct"), 494 } 495 496 return event; 497 } 498 499 fn readBytes( 500 comptime DB: type, 501 comptime hash_kind: hash.HashKind, 502 allocator: std.mem.Allocator, 503 map: DB.HashMap(.read_only), 504 field_name: []const u8, 505 ) ![]const u8 { 506 const cursor = try map.getCursor(hash.hashInt(hash_kind, field_name)) orelse return error.NotFound; 507 return try cursor.readBytesAlloc(allocator, null); 508 } 509 510 fn readUint( 511 comptime DB: type, 512 comptime hash_kind: hash.HashKind, 513 map: DB.HashMap(.read_only), 514 field_name: []const u8, 515 ) !u64 { 516 const cursor = try map.getCursor(hash.hashInt(hash_kind, field_name)) orelse return error.NotFound; 517 return try cursor.readUint(); 518 } 519 520 fn readInt( 521 comptime DB: type, 522 comptime hash_kind: hash.HashKind, 523 map: DB.HashMap(.read_only), 524 field_name: []const u8, 525 ) !i64 { 526 const cursor = try map.getCursor(hash.hashInt(hash_kind, field_name)) orelse return error.NotFound; 527 return try cursor.readInt(); 528 } 529 530 fn readBool( 531 comptime DB: type, 532 comptime hash_kind: hash.HashKind, 533 map: DB.HashMap(.read_only), 534 field_name: []const u8, 535 ) !bool { 536 const cursor = try map.getCursor(hash.hashInt(hash_kind, field_name)) orelse return error.NotFound; 537 var buffer: [5]u8 = undefined; 538 const bytes = try cursor.readBytesObject(&buffer); 539 const format_tag = bytes.format_tag orelse return error.InvalidFormatTag; 540 if (!std.mem.eql(u8, &format_tag, "bl")) return error.InvalidFormatTag; 541 if (std.mem.eql(u8, bytes.value, "true")) return true; 542 if (std.mem.eql(u8, bytes.value, "false")) return false; 543 return error.InvalidBool; 544 } 545 546 // 547 // writing to xitdb 548 // 549 550 pub fn upsert( 551 comptime T: type, 552 comptime DB: type, 553 comptime hash_kind: hash.HashKind, 554 map: DB.HashMap(.read_write), 555 event: T, 556 ) !void { 557 switch (@typeInfo(T)) { 558 .@"struct" => |struct_info| { 559 inline for (struct_info.fields) |field| { 560 try upsertField(DB, hash_kind, map, field.name, field.type, @field(event, field.name)); 561 } 562 }, 563 else => @compileError("upsert expects a struct"), 564 } 565 } 566 567 fn mergeChangedMapEntries( 568 comptime DB: type, 569 target: DB.HashMap(.read_write), 570 parent: DB.HashMap(.read_only), 571 baseline: DB.HashMap(.read_only), 572 comptime is_top_level: bool, 573 ) !void { 574 var parent_iter = try parent.iterator(); 575 while (try parent_iter.next()) |kv_pair_cursor| { 576 const kv_pair = try kv_pair_cursor.readKeyValuePair(); 577 578 const baseline_value_cursor = try baseline.getCursor(kv_pair.hash) orelse { 579 if ((try target.getCursor(kv_pair.hash)) != null) { 580 return error.MergeConflict; 581 } 582 583 try target.put(kv_pair.hash, .{ .slot = kv_pair.value_cursor.slot() }); 584 continue; 585 }; 586 587 const tag = kv_pair.value_cursor.slot().tag; 588 589 if (tag != baseline_value_cursor.slot().tag) { 590 return error.UnexpectedTag; 591 } 592 593 if (kv_pair.value_cursor.slot().value == baseline_value_cursor.slot().value) { 594 continue; 595 } 596 597 if (tag == .hash_map) { 598 const target_existing_cursor = try target.getCursor(kv_pair.hash) orelse return error.MergeConflict; 599 if (target_existing_cursor.slot().tag != .hash_map) { 600 return error.MergeConflict; 601 } 602 603 const target_child_cursor = try target.putCursor(kv_pair.hash); 604 const target_child = try DB.HashMap(.read_write).init(target_child_cursor); 605 const parent_child = try DB.HashMap(.read_only).init(kv_pair.value_cursor); 606 const baseline_child = try DB.HashMap(.read_only).init(baseline_value_cursor); 607 try mergeChangedMapEntries(DB, target_child, parent_child, baseline_child, false); 608 } else if (is_top_level) { 609 // the moment-index is a top-level key in the haxy moment 610 // and is not a map. we don't want to do any merge of this. 611 continue; 612 } else { 613 const target_value_cursor = try target.getCursor(kv_pair.hash) orelse return error.MergeConflict; 614 if (target_value_cursor.slot().value != baseline_value_cursor.slot().value) { 615 return error.MergeConflict; 616 } 617 618 try target.put(kv_pair.hash, .{ .slot = kv_pair.value_cursor.slot() }); 619 } 620 } 621 } 622 623 fn upsertField( 624 comptime DB: type, 625 comptime hash_kind: hash.HashKind, 626 map: DB.HashMap(.read_write), 627 comptime field_name: []const u8, 628 comptime Field: type, 629 value: Field, 630 ) !void { 631 const key = hash.hashInt(hash_kind, field_name); 632 633 switch (@typeInfo(Field)) { 634 .pointer => |pointer_info| { 635 if (pointer_info.size == .slice and pointer_info.child == u8) { 636 try upsertBytes(DB, hash_kind, map, key, value); 637 } else { 638 @compileError("unsupported upsert field type: " ++ @typeName(Field)); 639 } 640 }, 641 .array => |array_info| { 642 if (array_info.child == u8) { 643 try upsertBytes(DB, hash_kind, map, key, &value); 644 } else { 645 @compileError("unsupported upsert field type: " ++ @typeName(Field)); 646 } 647 }, 648 .int => |int_info| switch (int_info.signedness) { 649 .unsigned => { 650 if (try map.getCursor(key)) |value_cursor| { 651 if (try value_cursor.readUint() == value) { 652 return; 653 } 654 } 655 656 try map.put(key, .{ .uint = value }); 657 }, 658 .signed => { 659 if (try map.getCursor(key)) |value_cursor| { 660 if (try value_cursor.readInt() == value) { 661 return; 662 } 663 } 664 665 try map.put(key, .{ .int = value }); 666 }, 667 }, 668 .bool => { 669 const bytes = if (value) "true" else "false"; 670 if (try map.getCursor(key)) |value_cursor| { 671 var buffer: [5]u8 = undefined; 672 const existing = try value_cursor.readBytesObject(&buffer); 673 if (existing.format_tag) |format_tag| { 674 if (std.mem.eql(u8, &format_tag, "bl") and std.mem.eql(u8, existing.value, bytes)) { 675 return; 676 } 677 } 678 } 679 680 try map.put(key, .{ .bytes_object = .{ .value = bytes, .format_tag = "bl".* } }); 681 }, 682 else => @compileError("unsupported upsert field type: " ++ @typeName(Field)), 683 } 684 } 685 686 fn upsertBytes( 687 comptime DB: type, 688 comptime hash_kind: hash.HashKind, 689 map: DB.HashMap(.read_write), 690 key: hash.HashInt(hash_kind), 691 value: []const u8, 692 ) !void { 693 var existing_cursor_maybe = try map.getCursor(key); 694 if (existing_cursor_maybe) |*existing_cursor| { 695 if (try bytesEqual(DB, existing_cursor, value)) { 696 return; 697 } 698 } 699 700 var value_cursor = try map.putCursor(key); 701 var write_buffer: [1024]u8 = undefined; 702 var writer = try value_cursor.writer(&write_buffer); 703 try writer.interface.writeAll(value); 704 try writer.finish(); 705 } 706 707 fn bytesEqual( 708 comptime DB: type, 709 cursor: *DB.Cursor(.read_only), 710 value: []const u8, 711 ) !bool { 712 var read_buffer: [1024]u8 = undefined; 713 var reader = try cursor.reader(&read_buffer); 714 if (reader.size != value.len) { 715 return false; 716 } 717 718 var chunk_buffer: [1024]u8 = undefined; 719 var offset: usize = 0; 720 while (offset < value.len) { 721 const chunk_len = @min(chunk_buffer.len, value.len - offset); 722 try reader.interface.readSliceAll(chunk_buffer[0..chunk_len]); 723 if (!std.mem.eql(u8, chunk_buffer[0..chunk_len], value[offset .. offset + chunk_len])) { 724 return false; 725 } 726 offset += chunk_len; 727 } 728 729 return true; 730 } 731 732 // 733 // CommitIterator 734 // 735 // differs from xit's ObjectIterator in a few ways: 736 // 737 // 1. iterates parents first, rather than children first 738 // 2. `next` only returns the object id, not the full Object 739 // 3. stores its temporary state in a file on disk to avoid OOMs 740 // 741 742 pub fn CommitIterator(comptime repo_opts: rp.RepoOpts(.xit)) type { 743 return struct { 744 const DB = rp.Repo(.xit, repo_opts).DB; 745 const db_name = "haxy-repo-events.db"; 746 747 repo_dir: std.Io.Dir, 748 db_file: std.Io.File, 749 db: *DB, 750 // map of each object id to its children 751 parent_to_children: DB.HashMap(.read_write), 752 // tracking pending parents is necessary because a child can only 753 // be returned after all of its unconsumed parents have been returned 754 child_to_pending_parents: DB.HashMap(.read_write), 755 // queue of object ids that are ready to be returned from `next` 756 ready_queue: DB.ArrayList(.read_write), 757 ready_queue_index: u64, 758 // the object id at the tip of this branch 759 newest_object_id: ?[hash.byteLen(repo_opts.hash)]u8, 760 // the object id furthest back in the history that hasn't been consumed 761 oldest_object_id: ?[hash.byteLen(repo_opts.hash)]u8, 762 763 pub fn init( 764 state: rp.Repo(.xit, repo_opts).State(.read_only), 765 io: std.Io, 766 allocator: std.mem.Allocator, 767 consumed_object_ids: DB.HashMap(.read_only), 768 ref: rf.Ref, 769 ) !CommitIterator(repo_opts) { 770 const db_file = try state.core.repo_dir.createFile(io, db_name, .{ .truncate = true, .lock = .exclusive, .read = true }); 771 errdefer { 772 db_file.close(io); 773 state.core.repo_dir.deleteFile(io, db_name) catch {}; 774 } 775 776 const buffer_ptr = try allocator.create(std.Io.Writer.Allocating); 777 errdefer allocator.destroy(buffer_ptr); 778 779 buffer_ptr.* = std.Io.Writer.Allocating.init(allocator); 780 errdefer buffer_ptr.deinit(); 781 782 const db_ptr = try allocator.create(DB); 783 errdefer allocator.destroy(db_ptr); 784 db_ptr.* = try DB.init(.{ .io = io, .file = db_file, .buffer = buffer_ptr }); 785 786 const map = try DB.HashMap(.read_write).init(db_ptr.rootCursor()); 787 788 const parent_to_children_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "parent->children")); 789 const parent_to_children = try DB.HashMap(.read_write).init(parent_to_children_cursor); 790 791 const child_to_pending_parents_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "child->pending-parents")); 792 const child_to_pending_parents = try DB.HashMap(.read_write).init(child_to_pending_parents_cursor); 793 794 const ready_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "ready-queue")); 795 const ready_queue = try DB.ArrayList(.read_write).init(ready_queue_cursor); 796 797 var self = CommitIterator(repo_opts){ 798 .repo_dir = state.core.repo_dir, 799 .db_file = db_file, 800 .db = db_ptr, 801 .parent_to_children = parent_to_children, 802 .child_to_pending_parents = child_to_pending_parents, 803 .ready_queue = ready_queue, 804 .ready_queue_index = 0, 805 .newest_object_id = null, 806 .oldest_object_id = null, 807 }; 808 errdefer self.deinit(io, allocator); 809 810 try self.collect(state, io, allocator, consumed_object_ids, ref); 811 812 return self; 813 } 814 815 pub fn deinit(self: *CommitIterator(repo_opts), io: std.Io, allocator: std.mem.Allocator) void { 816 self.db_file.close(io); 817 self.db.core.memory.buffer.deinit(); 818 allocator.destroy(self.db.core.memory.buffer); 819 self.repo_dir.deleteFile(io, db_name) catch {}; 820 allocator.destroy(self.db); 821 } 822 823 pub fn next(self: *CommitIterator(repo_opts)) !?[hash.byteLen(repo_opts.hash)]u8 { 824 if (self.ready_queue_index >= try self.ready_queue.count()) return null; 825 826 const oid = try readOidFromList(self.ready_queue.readOnly(), self.ready_queue_index); 827 self.ready_queue_index += 1; 828 829 try self.enqueueChildren(&oid); 830 return oid; 831 } 832 833 fn collect( 834 self: *CommitIterator(repo_opts), 835 state: rp.Repo(.xit, repo_opts).State(.read_only), 836 io: std.Io, 837 allocator: std.mem.Allocator, 838 consumed_object_ids: DB.HashMap(.read_only), 839 ref: rf.Ref, 840 ) !void { 841 const map = try DB.HashMap(.read_write).init(self.db.rootCursor()); 842 843 const walk_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "walk-queue")); 844 const walk_queue = try DB.ArrayList(.read_write).init(walk_queue_cursor); 845 var walk_queue_index: u64 = 0; 846 847 const seen_object_ids_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-object-ids")); 848 const seen_object_ids = try DB.HashSet(.read_write).init(seen_object_ids_cursor); 849 850 const head_oid_hex = (try rf.readRecur(.xit, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound; 851 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 852 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 853 try walk_queue.append(.{ .bytes = &head_oid }); 854 855 while (walk_queue_index < try walk_queue.count()) { 856 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 857 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 858 859 walk_queue_index += 1; 860 861 // if we've seen this object id, skip it 862 if (null != try seen_object_ids.getCursor(oid_int)) { 863 continue; 864 } 865 866 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 867 868 var commit_object = try obj.Object(.xit, repo_opts, .full).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 869 defer commit_object.deinit(); 870 871 // if this object id has already been consumed, skip it 872 if (null != try consumed_object_ids.getCursor(oid_int)) { 873 continue; 874 } 875 876 if (self.newest_object_id == null) self.newest_object_id = oid; 877 self.oldest_object_id = oid; 878 879 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 880 var pending_parent_count: u64 = 0; 881 for (parent_oids) |*parent_oid| { 882 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 883 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 884 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 885 886 // if this object id has already been consumed, skip it 887 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 888 continue; 889 } 890 891 // if this object id hasn't already been seen, add it to the walk queue 892 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 893 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 894 } 895 896 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 897 const children = try DB.HashSet(.read_write).init(children_cursor); 898 try children.put(oid_int, .{ .bytes = &oid }); 899 pending_parent_count += 1; 900 } 901 902 if (pending_parent_count == 0) { 903 try self.ready_queue.append(.{ .bytes = &oid }); 904 } else { 905 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 906 } 907 } 908 } 909 910 fn enqueueChildren(self: *CommitIterator(repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 911 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 912 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 913 const children = try DB.HashSet(.read_only).init(children_cursor); 914 var children_iter = try children.iterator(); 915 916 while (try children_iter.next()) |*child_cursor| { 917 const kv_pair = try child_cursor.readKeyValuePair(); 918 const child_oid_int = kv_pair.hash; 919 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 920 const pending_parent_count = try pending_parent_cursor.readUint(); 921 922 if (pending_parent_count <= 1) { 923 _ = try self.child_to_pending_parents.remove(child_oid_int); 924 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 925 try self.ready_queue.append(.{ .bytes = &child_oid }); 926 } else { 927 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 928 } 929 } 930 } 931 932 fn readOidFromList(list: DB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 933 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 934 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 935 _ = try oid_cursor.readBytes(&oid); 936 return oid; 937 } 938 }; 939 } 940