╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
693 const walk_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "walk-queue")); 694 const walk_queue = try DB.ArrayList(.read_write).init(walk_queue_cursor); 695 var walk_queue_index: u64 = 0; 696 697 const seen_commits_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-commits")); 698 const seen_commits = try DB.HashSet(.read_write).init(seen_commits_cursor); 699 700 const head_oid_hex = (try rf.readRecur(.xit, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound; 701 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 702 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 703 try walk_queue.append(.{ .bytes = &head_oid }); 704 705 while (walk_queue_index < try walk_queue.count()) { 706 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 707 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 708 709 walk_queue_index += 1; 710 711 // if we've seen this object id, skip it 712 if (null != try seen_commits.getCursor(oid_int)) { 713 continue; 714 } 715 716 try seen_commits.put(oid_int, .{ .bytes = &oid }); 717 718 var commit_object = try obj.Object(.xit, repo_opts, .full).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 719 defer commit_object.deinit(); 720 721 // if this object id has already been consumed, skip it 722 if (null != try haxy_moments.getCursor(oid_int)) { 723 continue; 724 } 725 726 if (self.newest_object_id == null) self.newest_object_id = oid; 727 self.oldest_object_id = oid; 728 729 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 730 var pending_parent_count: u64 = 0; 731 for (parent_oids) |*parent_oid| { 732 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 733 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 734 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 735 736 // if this object id has already been consumed, skip it 737 if (null != try haxy_moments.getCursor(parent_oid_int)) { 738 continue; 739 } 740 741 // if this object id hasn't already been seen, add it to the walk queue 742 if (null == try seen_commits.getCursor(parent_oid_int)) { 743 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 744 } 745 746 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 747 const children = try DB.HashSet(.read_write).init(children_cursor); 748 try children.put(oid_int, .{ .bytes = &oid }); 749 pending_parent_count += 1; 750 } 751 752 if (pending_parent_count == 0) { 753 try self.ready_queue.append(.{ .bytes = &oid }); 754 } else { 755 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 756 } 757 } 758 } 759 760 fn enqueueChildren(self: *Self, oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 761 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 762 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 763 const children = try DB.HashSet(.read_only).init(children_cursor); 764 var children_iter = try children.iterator(); 765 766 while (try children_iter.next()) |*child_cursor| { 767 const kv_pair = try child_cursor.readKeyValuePair(); 768 const child_oid_int = kv_pair.hash; 769 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 770 const pending_parent_count = try pending_parent_cursor.readUint(); 771 772 if (pending_parent_count <= 1) { 773 _ = try self.child_to_pending_parents.remove(child_oid_int); 774 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 775 try self.ready_queue.append(.{ .bytes = &child_oid }); 776 } else { 777 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 778 } 779 } 780 } 781 782 fn readOidFromList(list: DB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 783 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 784 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 785 _ = try oid_cursor.readBytes(&oid); 786 return oid; 787 } 788 }; 789 } 790