╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1426 } else { 1427 @compileError("unsupported read field type: " ++ @typeName(field.type)); 1428 } 1429 }, 1430 .array => |array_info| { 1431 if (array_info.child == u8) { 1432 const bytes = try readBytes(DB, hash_kind, arena.allocator(), map, field.name); 1433 if (bytes.len != array_info.len) return error.InvalidByteArrayLength; 1434 @memcpy(@field(event, field.name)[0..], bytes); 1435 } else { 1436 @compileError("unsupported read field type: " ++ @typeName(field.type)); 1437 } 1438 }, 1439 .bool => @field(event, field.name) = try readBool(DB, hash_kind, map, field.name), 1440 .int => |int_info| switch (int_info.signedness) { 1441 .unsigned => @field(event, field.name) = @intCast(try readUint(DB, hash_kind, map, field.name)), 1442 .signed => @field(event, field.name) = @intCast(try readInt(DB, hash_kind, map, field.name)), 1443 }, 1444 .@"enum" => { 1445 const bytes = try readBytes(DB, hash_kind, arena.allocator(), map, field.name); 1446 @field(event, field.name) = std.meta.stringToEnum(field.type, bytes) orelse return error.InvalidEnumTag; 1447 }, 1448 .optional => |optional_info| { 1449 if (optional_info.child != []const u8) @compileError("unsupported read field type: " ++ @typeName(field.type)); 1450 // a missing key is null 1451 @field(event, field.name) = if (try map.getCursor(hash.hashInt(hash_kind, field.name))) |cursor| 1452 try cursor.readBytesAlloc(arena.allocator(), null) 1453 else 1454 null; 1455 }, 1456 // a struct field's own fields are read from the same map 1457 .@"struct" => @field(event, field.name) = try read(field.type, DB, hash_kind, arena, map), 1458 else => @compileError("unsupported read field type: " ++ @typeName(field.type)), 1459 } 1460 } 1461 }, 1462 else => @compileError("read expects a struct"), 1463 } 1464 1465 return event; 1466 } 1467 1468 // whether two events carry the same data 1469 fn fieldsEqual(comptime T: type, a: T, b: T) bool { 1470 switch (@typeInfo(T)) { 1471 .@"struct" => |struct_info| { 1472 inline for (struct_info.fields) |field| { 1473 if (!fieldEqual(field.type, @field(a, field.name), @field(b, field.name))) return false; 1474 } 1475 }, 1476 else => @compileError("fieldsEqual expects a struct"), 1477 } 1478 1479 return true; 1480 } 1481 1482 pub fn fieldEqual(comptime Field: type, a: Field, b: Field) bool { 1483 switch (@typeInfo(Field)) { 1484 .pointer => |pointer_info| { 1485 if (pointer_info.size == .slice and pointer_info.child == u8) { 1486 return std.mem.eql(u8, a, b); 1487 } else { 1488 @compileError("unsupported field type: " ++ @typeName(Field)); 1489 } 1490 }, 1491 .array => |array_info| { 1492 if (array_info.child == u8) { 1493 return std.mem.eql(u8, &a, &b); 1494 } else { 1495 @compileError("unsupported field type: " ++ @typeName(Field)); 1496 } 1497 }, 1498 .bool, .int, .@"enum" => return a == b, 1499 else => @compileError("unsupported field type: " ++ @typeName(Field)), 1500 } 1501 } 1502 1503 fn readBytes( 1504 comptime DB: type, 1505 comptime hash_kind: hash.HashKind, 1506 allocator: std.mem.Allocator, 1507 map: DB.HashMap(.read_only), 1508 field_name: []const u8, 1509 ) ![]const u8 { 1510 const cursor = try map.getCursor(hash.hashInt(hash_kind, field_name)) orelse return error.NotFound; 1511 return try cursor.readBytesAlloc(allocator, null); 1512 } 1513 1514 fn readUint( 1515 comptime DB: type, 1516 comptime hash_kind: hash.HashKind, 1517 map: DB.HashMap(.read_only), 1518 field_name: []const u8, 1519 ) !u64 { 1520 const cursor = try map.getCursor(hash.hashInt(hash_kind, field_name)) orelse return error.NotFound; 1521 return try cursor.readUint(); 1522 } 1523 1524 fn readInt( 1525 comptime DB: type, 1526 comptime hash_kind: hash.HashKind, 1527 map: DB.HashMap(.read_only), 1528 field_name: []const u8, 1529 ) !i64 { 1530 const cursor = try map.getCursor(hash.hashInt(hash_kind, field_name)) orelse return error.NotFound; 1531 return try cursor.readInt(); 1532 } 1533 1534 fn readBool( 1535 comptime DB: type, 1536 comptime hash_kind: hash.HashKind, 1537 map: DB.HashMap(.read_only), 1538 field_name: []const u8, 1539 ) !bool { 1540 const cursor = try map.getCursor(hash.hashInt(hash_kind, field_name)) orelse return error.NotFound; 1541 var buffer: [5]u8 = undefined; 1542 const bytes = try cursor.readBytesObject(&buffer); 1543 const format_tag = bytes.format_tag orelse return error.InvalidFormatTag; 1544 if (!std.mem.eql(u8, &format_tag, "bl")) return error.InvalidFormatTag; 1545 if (std.mem.eql(u8, bytes.value, "true")) return true; 1546 if (std.mem.eql(u8, bytes.value, "false")) return false; 1547 return error.InvalidBool; 1548 } 1549 1550 // 1551 // writing to xitdb 1552 // 1553 1554 pub fn upsert( 1555 comptime T: type, 1556 comptime DB: type, 1557 comptime hash_kind: hash.HashKind, 1558 map: DB.HashMap(.read_write), 1559 event: T, 1560 ) !void { 1561 switch (@typeInfo(T)) { 1562 .@"struct" => |struct_info| { 1563 comptime validateFlattenedFields(T); 1564 inline for (struct_info.fields) |field| { 1565 try upsertField(DB, hash_kind, map, field.name, field.type, @field(event, field.name)); 1566 } 1567 }, 1568 else => @compileError("upsert expects a struct"), 1569 } 1570 } 1571 1572 fn upsertField( 1573 comptime DB: type, 1574 comptime hash_kind: hash.HashKind, 1575 map: DB.HashMap(.read_write), 1576 comptime field_name: []const u8, 1577 comptime Field: type, 1578 value: Field, 1579 ) !void { 1580 const key = hash.hashInt(hash_kind, field_name); 1581 1582 switch (@typeInfo(Field)) { 1583 .pointer => |pointer_info| { 1584 if (pointer_info.size == .slice and pointer_info.child == u8) { 1585 try upsertBytes(DB, hash_kind, map, key, value); 1586 } else { 1587 @compileError("unsupported upsert field type: " ++ @typeName(Field)); 1588 } 1589 }, 1590 .array => |array_info| { 1591 if (array_info.child == u8) { 1592 try upsertBytes(DB, hash_kind, map, key, &value); 1593 } else { 1594 @compileError("unsupported upsert field type: " ++ @typeName(Field)); 1595 } 1596 }, 1597 .int => |int_info| switch (int_info.signedness) { 1598 .unsigned => { 1599 if (try map.getCursor(key)) |value_cursor| { 1600 if (try value_cursor.readUint() == value) { 1601 return; 1602 } 1603 } 1604 1605 try map.put(key, .{ .uint = value }); 1606 }, 1607 .signed => { 1608 if (try map.getCursor(key)) |value_cursor| { 1609 if (try value_cursor.readInt() == value) { 1610 return; 1611 } 1612 } 1613 1614 try map.put(key, .{ .int = value }); 1615 }, 1616 }, 1617 .bool => { 1618 const bytes = if (value) "true" else "false"; 1619 if (try map.getCursor(key)) |value_cursor| { 1620 var buffer: [5]u8 = undefined; 1621 const existing = try value_cursor.readBytesObject(&buffer); 1622 if (existing.format_tag) |format_tag| { 1623 if (std.mem.eql(u8, &format_tag, "bl") and std.mem.eql(u8, existing.value, bytes)) { 1624 return; 1625 } 1626 } 1627 } 1628 1629 try map.put(key, .{ .bytes_object = .{ .value = bytes, .format_tag = "bl".* } }); 1630 }, 1631 .@"enum" => try upsertBytes(DB, hash_kind, map, key, @tagName(value)), 1632 .optional => |optional_info| { 1633 if (optional_info.child != []const u8) @compileError("unsupported upsert field type: " ++ @typeName(Field)); 1634 // a missing key is null 1635 if (value) |bytes| { 1636 try upsertBytes(DB, hash_kind, map, key, bytes); 1637 } else { 1638 _ = try map.remove(key); 1639 } 1640 }, 1641 // a struct field's own fields are stored in the same map 1642 .@"struct" => try upsert(Field, DB, hash_kind, map, value), 1643 else => @compileError("unsupported upsert field type: " ++ @typeName(Field)), 1644 } 1645 } 1646 1647 fn upsertBytes( 1648 comptime DB: type, 1649 comptime hash_kind: hash.HashKind, 1650 map: DB.HashMap(.read_write), 1651 key: hash.HashInt(hash_kind), 1652 value: []const u8, 1653 ) !void { 1654 var existing_cursor_maybe = try map.getCursor(key); 1655 if (existing_cursor_maybe) |*existing_cursor| { 1656 if (try bytesEqual(DB, existing_cursor, value)) { 1657 return; 1658 } 1659 } 1660 1661 var value_cursor = try map.putCursor(key); 1662 var write_buffer: [1024]u8 = undefined; 1663 var writer = try value_cursor.writer(&write_buffer); 1664 try writer.interface.writeAll(value); 1665 try writer.finish(); 1666 } 1667 1668 fn bytesEqual( 1669 comptime DB: type, 1670 cursor: *DB.Cursor(.read_only), 1671 value: []const u8, 1672 ) !bool { 1673 var read_buffer: [1024]u8 = undefined; 1674 var reader = try cursor.reader(&read_buffer); 1675 if (reader.size != value.len) { 1676 return false; 1677 } 1678 1679 var chunk_buffer: [1024]u8 = undefined; 1680 var offset: usize = 0; 1681 while (offset < value.len) { 1682 const chunk_len = @min(chunk_buffer.len, value.len - offset); 1683 try reader.interface.readSliceAll(chunk_buffer[0..chunk_len]); 1684 if (!std.mem.eql(u8, chunk_buffer[0..chunk_len], value[offset .. offset + chunk_len])) { 1685 return false; 1686 } 1687 offset += chunk_len; 1688 } 1689 1690 return true; 1691 } 1692 1693 // 1694 // CommitIterator 1695 // 1696 // differs from xit's ObjectIterator in a few ways: 1697 // 1698 // 1. iterates parents first, rather than children first 1699 // 2. `next` only returns the object id, not the full Object 1700 // 3. stores its temporary state in a file on disk to avoid OOMs 1701 // 1702 1703 pub fn CommitIterator(comptime repo_kind: rp.RepoKind, comptime repo_opts: rp.RepoOpts(repo_kind)) type { 1704 return struct { 1705 const DB = EventDB(repo_opts.hash); 1706 const db_name = "haxy-repo-events.db"; 1707 1708 repo_dir: std.Io.Dir, 1709 db_file: std.Io.File, 1710 db: *DB, 1711 // map of each object id to its children 1712 parent_to_children: DB.HashMap(.read_write), 1713 // tracking pending parents is necessary because a child can only 1714 // be returned after all of its unconsumed parents have been returned 1715 child_to_pending_parents: DB.HashMap(.read_write), 1716 // queue of object ids that are ready to be returned from `next` 1717 ready_queue: DB.ArrayList(.read_write), 1718 ready_queue_index: u64, 1719 // the object id at the tip of this branch 1720 newest_object_id: ?[hash.byteLen(repo_opts.hash)]u8, 1721 // the object id furthest back in the history that hasn't been consumed 1722 oldest_object_id: ?[hash.byteLen(repo_opts.hash)]u8, 1723 1724 pub fn init( 1725 state: rp.Repo(repo_kind, repo_opts).State(.read_only), 1726 io: std.Io, 1727 allocator: std.mem.Allocator, 1728 consumed_object_ids: DB.HashMap(.read_only), 1729 ref: rf.Ref, 1730 ) !CommitIterator(repo_kind, repo_opts) { 1731 const db_file = try state.core.repo_dir.createFile(io, db_name, .{ .truncate = true, .lock = .exclusive, .read = true }); 1732 errdefer { 1733 db_file.close(io); 1734 state.core.repo_dir.deleteFile(io, db_name) catch {}; 1735 } 1736 1737 const buffer_ptr = try allocator.create(std.Io.Writer.Allocating); 1738 errdefer allocator.destroy(buffer_ptr); 1739 1740 buffer_ptr.* = std.Io.Writer.Allocating.init(allocator); 1741 errdefer buffer_ptr.deinit(); 1742 1743 const db_ptr = try allocator.create(DB); 1744 errdefer allocator.destroy(db_ptr); 1745 // the db is scratch state that gets deleted after iteration, so 1746 // there is nothing worth fsyncing 1747 db_ptr.* = try DB.init(.{ .io = io, .file = db_file, .buffer = buffer_ptr, .fsync = false }); 1748 1749 const map = try DB.HashMap(.read_write).init(db_ptr.rootCursor()); 1750 1751 const parent_to_children_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "parent->children")); 1752 const parent_to_children = try DB.HashMap(.read_write).init(parent_to_children_cursor); 1753 1754 const child_to_pending_parents_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "child->pending-parents")); 1755 const child_to_pending_parents = try DB.HashMap(.read_write).init(child_to_pending_parents_cursor); 1756 1757 const ready_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "ready-queue")); 1758 const ready_queue = try DB.ArrayList(.read_write).init(ready_queue_cursor); 1759 1760 var self = CommitIterator(repo_kind, repo_opts){ 1761 .repo_dir = state.core.repo_dir, 1762 .db_file = db_file, 1763 .db = db_ptr, 1764 .parent_to_children = parent_to_children, 1765 .child_to_pending_parents = child_to_pending_parents, 1766 .ready_queue = ready_queue, 1767 .ready_queue_index = 0, 1768 .newest_object_id = null, 1769 .oldest_object_id = null, 1770 }; 1771 errdefer self.deinit(io, allocator); 1772 1773 try self.collect(state, io, allocator, consumed_object_ids, ref); 1774 1775 return self; 1776 } 1777 1778 pub fn deinit(self: *CommitIterator(repo_kind, repo_opts), io: std.Io, allocator: std.mem.Allocator) void { 1779 self.db_file.close(io); 1780 self.db.core.memory.buffer.deinit(); 1781 allocator.destroy(self.db.core.memory.buffer); 1782 self.repo_dir.deleteFile(io, db_name) catch {}; 1783 allocator.destroy(self.db); 1784 } 1785 1786 pub fn next(self: *CommitIterator(repo_kind, repo_opts)) !?[hash.byteLen(repo_opts.hash)]u8 { 1787 if (self.ready_queue_index >= try self.ready_queue.count()) return null; 1788 1789 const oid = try readOidFromList(self.ready_queue.readOnly(), self.ready_queue_index); 1790 self.ready_queue_index += 1; 1791 1792 try self.enqueueChildren(&oid); 1793 return oid; 1794 } 1795 1796 fn collect( 1797 self: *CommitIterator(repo_kind, repo_opts), 1798 state: rp.Repo(repo_kind, repo_opts).State(.read_only), 1799 io: std.Io, 1800 allocator: std.mem.Allocator, 1801 consumed_object_ids: DB.HashMap(.read_only), 1802 ref: rf.Ref, 1803 ) !void { 1804 const map = try DB.HashMap(.read_write).init(self.db.rootCursor()); 1805 1806 const walk_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "walk-queue")); 1807 const walk_queue = try DB.ArrayList(.read_write).init(walk_queue_cursor); 1808 var walk_queue_index: u64 = 0; 1809 1810 const seen_object_ids_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-object-ids")); 1811 const seen_object_ids = try DB.HashSet(.read_write).init(seen_object_ids_cursor); 1812 1813 const head_oid_hex = (try rf.readRecur(repo_kind, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound; 1814 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1815 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 1816 try walk_queue.append(.{ .bytes = &head_oid }); 1817 1818 while (walk_queue_index < try walk_queue.count()) { 1819 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 1820 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 1821 1822 walk_queue_index += 1; 1823 1824 // if we've seen this object id, skip it 1825 if (null != try seen_object_ids.getCursor(oid_int)) { 1826 continue; 1827 } 1828 1829 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 1830 1831 var commit_object = try obj.Object(repo_kind, repo_opts).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 1832 defer commit_object.deinit(); 1833 1834 // if this object id has already been consumed, skip it 1835 if (null != try consumed_object_ids.getCursor(oid_int)) { 1836 continue; 1837 } 1838 1839 if (self.newest_object_id == null) self.newest_object_id = oid; 1840 self.oldest_object_id = oid; 1841 1842 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 1843 var pending_parent_count: u64 = 0; 1844 for (parent_oids) |*parent_oid| { 1845 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1846 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 1847 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 1848 1849 // if this object id has already been consumed, skip it 1850 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 1851 continue; 1852 } 1853 1854 // if this object id hasn't already been seen, add it to the walk queue 1855 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 1856 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 1857 } 1858 1859 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 1860 const children = try DB.HashSet(.read_write).init(children_cursor); 1861 try children.put(oid_int, .{ .bytes = &oid }); 1862 pending_parent_count += 1; 1863 } 1864 1865 if (pending_parent_count == 0) { 1866 try self.ready_queue.append(.{ .bytes = &oid }); 1867 } else { 1868 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 1869 } 1870 } 1871 } 1872 1873 fn enqueueChildren(self: *CommitIterator(repo_kind, repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 1874 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 1875 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 1876 const children = try DB.HashSet(.read_only).init(children_cursor); 1877 var children_iter = try children.iterator(); 1878 1879 while (try children_iter.next()) |*child_cursor| { 1880 const kv_pair = try child_cursor.readKeyValuePair(); 1881 const child_oid_int = kv_pair.hash; 1882 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 1883 const pending_parent_count = try pending_parent_cursor.readUint(); 1884 1885 if (pending_parent_count <= 1) { 1886 _ = try self.child_to_pending_parents.remove(child_oid_int); 1887 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 1888 try self.ready_queue.append(.{ .bytes = &child_oid }); 1889 } else { 1890 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 1891 } 1892 } 1893 } 1894 1895 fn readOidFromList(list: DB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 1896 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 1897 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1898 _ = try oid_cursor.readBytes(&oid); 1899 return oid; 1900 } 1901 }; 1902 } 1903