╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
725 726 const oid = try readOidFromList(self.ready_queue.readOnly(), self.ready_queue_index); 727 self.ready_queue_index += 1; 728 729 try self.enqueueChildren(&oid); 730 return oid; 731 } 732 733 fn collect( 734 self: *CommitIterator(repo_opts), 735 state: rp.Repo(.xit, repo_opts).State(.read_only), 736 io: std.Io, 737 allocator: std.mem.Allocator, 738 consumed_object_ids: DB.HashMap(.read_only), 739 ref: rf.Ref, 740 ) !void { 741 const map = try DB.HashMap(.read_write).init(self.db.rootCursor()); 742 743 const walk_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "walk-queue")); 744 const walk_queue = try DB.ArrayList(.read_write).init(walk_queue_cursor); 745 var walk_queue_index: u64 = 0; 746 747 const seen_object_ids_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-object-ids")); 748 const seen_object_ids = try DB.HashSet(.read_write).init(seen_object_ids_cursor); 749 750 const head_oid_hex = (try rf.readRecur(.xit, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound; 751 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 752 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 753 try walk_queue.append(.{ .bytes = &head_oid }); 754 755 while (walk_queue_index < try walk_queue.count()) { 756 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 757 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 758 759 walk_queue_index += 1; 760 761 // if we've seen this object id, skip it 762 if (null != try seen_object_ids.getCursor(oid_int)) { 763 continue; 764 } 765 766 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 767 768 var commit_object = try obj.Object(.xit, repo_opts, .full).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 769 defer commit_object.deinit(); 770 771 // if this object id has already been consumed, skip it 772 if (null != try consumed_object_ids.getCursor(oid_int)) { 773 continue; 774 } 775 776 if (self.newest_object_id == null) self.newest_object_id = oid; 777 self.oldest_object_id = oid; 778 779 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 780 var pending_parent_count: u64 = 0; 781 for (parent_oids) |*parent_oid| { 782 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 783 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 784 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 785 786 // if this object id has already been consumed, skip it 787 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 788 continue; 789 } 790 791 // if this object id hasn't already been seen, add it to the walk queue 792 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 793 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 794 } 795 796 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 797 const children = try DB.HashSet(.read_write).init(children_cursor); 798 try children.put(oid_int, .{ .bytes = &oid }); 799 pending_parent_count += 1; 800 } 801 802 if (pending_parent_count == 0) { 803 try self.ready_queue.append(.{ .bytes = &oid }); 804 } else { 805 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 806 } 807 } 808 } 809 810 fn enqueueChildren(self: *CommitIterator(repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 811 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 812 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 813 const children = try DB.HashSet(.read_only).init(children_cursor); 814 var children_iter = try children.iterator(); 815 816 while (try children_iter.next()) |*child_cursor| { 817 const kv_pair = try child_cursor.readKeyValuePair(); 818 const child_oid_int = kv_pair.hash; 819 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 820 const pending_parent_count = try pending_parent_cursor.readUint(); 821 822 if (pending_parent_count <= 1) { 823 _ = try self.child_to_pending_parents.remove(child_oid_int); 824 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 825 try self.ready_queue.append(.{ .bytes = &child_oid }); 826 } else { 827 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 828 } 829 } 830 } 831 832 fn readOidFromList(list: DB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 833 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 834 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 835 _ = try oid_cursor.readBytes(&oid); 836 return oid; 837 } 838 }; 839 } 840