╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
699 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 700 try walk_queue.append(.{ .bytes = &head_oid }); 701 702 while (walk_queue_index < try walk_queue.count()) { 703 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 704 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 705 706 walk_queue_index += 1; 707 708 // if we've seen this object id, skip it 709 if (null != try seen_object_ids.getCursor(oid_int)) { 710 continue; 711 } 712 713 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 714 715 var commit_object = try obj.Object(.xit, repo_opts, .full).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 716 defer commit_object.deinit(); 717 718 // if this object id has already been consumed, skip it 719 if (null != try consumed_object_ids.getCursor(oid_int)) { 720 continue; 721 } 722 723 if (self.newest_object_id == null) self.newest_object_id = oid; 724 self.oldest_object_id = oid; 725 726 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 727 var pending_parent_count: u64 = 0; 728 for (parent_oids) |*parent_oid| { 729 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 730 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 731 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 732 733 // if this object id has already been consumed, skip it 734 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 735 continue; 736 } 737 738 // if this object id hasn't already been seen, add it to the walk queue 739 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 740 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 741 } 742 743 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 744 const children = try DB.HashSet(.read_write).init(children_cursor); 745 try children.put(oid_int, .{ .bytes = &oid }); 746 pending_parent_count += 1; 747 } 748 749 if (pending_parent_count == 0) { 750 try self.ready_queue.append(.{ .bytes = &oid }); 751 } else { 752 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 753 } 754 } 755 } 756 757 fn enqueueChildren(self: *CommitIterator(repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 758 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 759 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 760 const children = try DB.HashSet(.read_only).init(children_cursor); 761 var children_iter = try children.iterator(); 762 763 while (try children_iter.next()) |*child_cursor| { 764 const kv_pair = try child_cursor.readKeyValuePair(); 765 const child_oid_int = kv_pair.hash; 766 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 767 const pending_parent_count = try pending_parent_cursor.readUint(); 768 769 if (pending_parent_count <= 1) { 770 _ = try self.child_to_pending_parents.remove(child_oid_int); 771 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 772 try self.ready_queue.append(.{ .bytes = &child_oid }); 773 } else { 774 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 775 } 776 } 777 } 778 779 fn readOidFromList(list: DB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 780 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 781 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 782 _ = try oid_cursor.readBytes(&oid); 783 return oid; 784 } 785 }; 786 } 787