╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2621 const seen_object_ids_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-object-ids")); 2622 const seen_object_ids = try TempDB.HashSet(.read_write).init(seen_object_ids_cursor); 2623 2624 const head_oid_hex = (try rf.readRecur(repo_kind, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound; 2625 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 2626 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 2627 try walk_queue.append(.{ .bytes = &head_oid }); 2628 2629 while (walk_queue_index < try walk_queue.count()) { 2630 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 2631 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 2632 2633 walk_queue_index += 1; 2634 2635 // if we've seen this object id, skip it 2636 if (null != try seen_object_ids.getCursor(oid_int)) { 2637 continue; 2638 } 2639 2640 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 2641 2642 var commit_object = try obj.Object(repo_kind, repo_opts).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 2643 defer commit_object.deinit(); 2644 2645 // if this object id has already been consumed, skip it 2646 if (null != try consumed_object_ids.getCursor(oid_int)) { 2647 continue; 2648 } 2649 2650 if (self.newest_object_id == null) self.newest_object_id = oid; 2651 self.oldest_object_id = oid; 2652 2653 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 2654 var pending_parent_count: u64 = 0; 2655 for (parent_oids) |*parent_oid| { 2656 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 2657 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 2658 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 2659 2660 // if this object id has already been consumed, skip it 2661 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 2662 continue; 2663 } 2664 2665 // if this object id hasn't already been seen, add it to the walk queue 2666 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 2667 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 2668 } 2669 2670 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 2671 const children = try TempDB.HashSet(.read_write).init(children_cursor); 2672 try children.put(oid_int, .{ .bytes = &oid }); 2673 pending_parent_count += 1; 2674 } 2675 2676 if (pending_parent_count == 0) { 2677 try self.ready_queue.append(.{ .bytes = &oid }); 2678 } else { 2679 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 2680 } 2681 } 2682 } 2683 2684 fn enqueueChildren(self: *CommitIterator(repo_kind, repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 2685 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 2686 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 2687 const children = try TempDB.HashSet(.read_only).init(children_cursor); 2688 var children_iter = try children.iterator(); 2689 2690 while (try children_iter.next()) |*child_cursor| { 2691 const kv_pair = try child_cursor.readKeyValuePair(); 2692 const child_oid_int = kv_pair.hash; 2693 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 2694 const pending_parent_count = try pending_parent_cursor.readUint(); 2695 2696 if (pending_parent_count <= 1) { 2697 _ = try self.child_to_pending_parents.remove(child_oid_int); 2698 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 2699 try self.ready_queue.append(.{ .bytes = &child_oid }); 2700 } else { 2701 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 2702 } 2703 } 2704 } 2705 2706 fn readOidFromList(list: TempDB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 2707 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 2708 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 2709 _ = try oid_cursor.readBytes(&oid); 2710 return oid; 2711 } 2712 }; 2713 } 2714