╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1499 fn collect( 1500 self: *CommitIterator(repo_kind, repo_opts), 1501 state: rp.Repo(repo_kind, repo_opts).State(.read_only), 1502 io: std.Io, 1503 allocator: std.mem.Allocator, 1504 consumed_object_ids: DB.HashMap(.read_only), 1505 ref: rf.Ref, 1506 ) !void { 1507 const map = try DB.HashMap(.read_write).init(self.db.rootCursor()); 1508 1509 const walk_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "walk-queue")); 1510 const walk_queue = try DB.ArrayList(.read_write).init(walk_queue_cursor); 1511 var walk_queue_index: u64 = 0; 1512 1513 const seen_object_ids_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-object-ids")); 1514 const seen_object_ids = try DB.HashSet(.read_write).init(seen_object_ids_cursor); 1515 1516 const head_oid_hex = (try rf.readRecur(repo_kind, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound; 1517 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1518 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 1519 try walk_queue.append(.{ .bytes = &head_oid }); 1520 1521 while (walk_queue_index < try walk_queue.count()) { 1522 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 1523 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 1524 1525 walk_queue_index += 1; 1526 1527 // if we've seen this object id, skip it 1528 if (null != try seen_object_ids.getCursor(oid_int)) { 1529 continue; 1530 } 1531 1532 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 1533 1534 var commit_object = try obj.Object(repo_kind, repo_opts).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 1535 defer commit_object.deinit(); 1536 1537 // if this object id has already been consumed, skip it 1538 if (null != try consumed_object_ids.getCursor(oid_int)) { 1539 continue; 1540 } 1541 1542 if (self.newest_object_id == null) self.newest_object_id = oid; 1543 self.oldest_object_id = oid; 1544 1545 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 1546 var pending_parent_count: u64 = 0; 1547 for (parent_oids) |*parent_oid| { 1548 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1549 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 1550 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 1551 1552 // if this object id has already been consumed, skip it 1553 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 1554 continue; 1555 } 1556 1557 // if this object id hasn't already been seen, add it to the walk queue 1558 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 1559 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 1560 } 1561 1562 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 1563 const children = try DB.HashSet(.read_write).init(children_cursor); 1564 try children.put(oid_int, .{ .bytes = &oid }); 1565 pending_parent_count += 1; 1566 } 1567 1568 if (pending_parent_count == 0) { 1569 try self.ready_queue.append(.{ .bytes = &oid }); 1570 } else { 1571 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 1572 } 1573 } 1574 } 1575 1576 fn enqueueChildren(self: *CommitIterator(repo_kind, repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 1577 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 1578 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 1579 const children = try DB.HashSet(.read_only).init(children_cursor); 1580 var children_iter = try children.iterator(); 1581 1582 while (try children_iter.next()) |*child_cursor| { 1583 const kv_pair = try child_cursor.readKeyValuePair(); 1584 const child_oid_int = kv_pair.hash; 1585 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 1586 const pending_parent_count = try pending_parent_cursor.readUint(); 1587 1588 if (pending_parent_count <= 1) { 1589 _ = try self.child_to_pending_parents.remove(child_oid_int); 1590 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 1591 try self.ready_queue.append(.{ .bytes = &child_oid }); 1592 } else { 1593 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 1594 } 1595 } 1596 } 1597 1598 fn readOidFromList(list: DB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 1599 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 1600 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1601 _ = try oid_cursor.readBytes(&oid); 1602 return oid; 1603 } 1604 }; 1605 } 1606