╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1644 if (self.ready_queue_index >= try self.ready_queue.count()) return null; 1645 1646 const oid = try readOidFromList(self.ready_queue.readOnly(), self.ready_queue_index); 1647 self.ready_queue_index += 1; 1648 1649 try self.enqueueChildren(&oid); 1650 return oid; 1651 } 1652 1653 fn collect( 1654 self: *CommitIterator(repo_kind, repo_opts), 1655 state: rp.Repo(repo_kind, repo_opts).State(.read_only), 1656 io: std.Io, 1657 allocator: std.mem.Allocator, 1658 consumed_object_ids: DB.HashMap(.read_only), 1659 ref: rf.Ref, 1660 ) !void { 1661 const map = try DB.HashMap(.read_write).init(self.db.rootCursor()); 1662 1663 const walk_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "walk-queue")); 1664 const walk_queue = try DB.ArrayList(.read_write).init(walk_queue_cursor); 1665 var walk_queue_index: u64 = 0; 1666 1667 const seen_object_ids_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-object-ids")); 1668 const seen_object_ids = try DB.HashSet(.read_write).init(seen_object_ids_cursor); 1669 1670 const head_oid_hex = (try rf.readRecur(repo_kind, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound; 1671 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1672 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 1673 try walk_queue.append(.{ .bytes = &head_oid }); 1674 1675 while (walk_queue_index < try walk_queue.count()) { 1676 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 1677 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 1678 1679 walk_queue_index += 1; 1680 1681 // if we've seen this object id, skip it 1682 if (null != try seen_object_ids.getCursor(oid_int)) { 1683 continue; 1684 } 1685 1686 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 1687 1688 var commit_object = try obj.Object(repo_kind, repo_opts).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 1689 defer commit_object.deinit(); 1690 1691 // if this object id has already been consumed, skip it 1692 if (null != try consumed_object_ids.getCursor(oid_int)) { 1693 continue; 1694 } 1695 1696 if (self.newest_object_id == null) self.newest_object_id = oid; 1697 self.oldest_object_id = oid; 1698 1699 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 1700 var pending_parent_count: u64 = 0; 1701 for (parent_oids) |*parent_oid| { 1702 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1703 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 1704 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 1705 1706 // if this object id has already been consumed, skip it 1707 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 1708 continue; 1709 } 1710 1711 // if this object id hasn't already been seen, add it to the walk queue 1712 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 1713 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 1714 } 1715 1716 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 1717 const children = try DB.HashSet(.read_write).init(children_cursor); 1718 try children.put(oid_int, .{ .bytes = &oid }); 1719 pending_parent_count += 1; 1720 } 1721 1722 if (pending_parent_count == 0) { 1723 try self.ready_queue.append(.{ .bytes = &oid }); 1724 } else { 1725 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 1726 } 1727 } 1728 } 1729 1730 fn enqueueChildren(self: *CommitIterator(repo_kind, repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 1731 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 1732 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 1733 const children = try DB.HashSet(.read_only).init(children_cursor); 1734 var children_iter = try children.iterator(); 1735 1736 while (try children_iter.next()) |*child_cursor| { 1737 const kv_pair = try child_cursor.readKeyValuePair(); 1738 const child_oid_int = kv_pair.hash; 1739 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 1740 const pending_parent_count = try pending_parent_cursor.readUint(); 1741 1742 if (pending_parent_count <= 1) { 1743 _ = try self.child_to_pending_parents.remove(child_oid_int); 1744 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 1745 try self.ready_queue.append(.{ .bytes = &child_oid }); 1746 } else { 1747 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 1748 } 1749 } 1750 } 1751 1752 fn readOidFromList(list: DB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 1753 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 1754 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1755 _ = try oid_cursor.readBytes(&oid); 1756 return oid; 1757 } 1758 }; 1759 } 1760