╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
811 state: rp.Repo(.xit, repo_opts).State(.read_only), 812 io: std.Io, 813 allocator: std.mem.Allocator, 814 consumed_object_ids: DB.HashMap(.read_only), 815 ref: rf.Ref, 816 ) !void { 817 const map = try DB.HashMap(.read_write).init(self.db.rootCursor()); 818 819 const walk_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "walk-queue")); 820 const walk_queue = try DB.ArrayList(.read_write).init(walk_queue_cursor); 821 var walk_queue_index: u64 = 0; 822 823 const seen_object_ids_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-object-ids")); 824 const seen_object_ids = try DB.HashSet(.read_write).init(seen_object_ids_cursor); 825 826 const head_oid_hex = (try rf.readRecur(.xit, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound; 827 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 828 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 829 try walk_queue.append(.{ .bytes = &head_oid }); 830 831 while (walk_queue_index < try walk_queue.count()) { 832 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 833 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 834 835 walk_queue_index += 1; 836 837 // if we've seen this object id, skip it 838 if (null != try seen_object_ids.getCursor(oid_int)) { 839 continue; 840 } 841 842 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 843 844 var commit_object = try obj.Object(.xit, repo_opts, .full).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 845 defer commit_object.deinit(); 846 847 // if this object id has already been consumed, skip it 848 if (null != try consumed_object_ids.getCursor(oid_int)) { 849 continue; 850 } 851 852 if (self.newest_object_id == null) self.newest_object_id = oid; 853 self.oldest_object_id = oid; 854 855 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 856 var pending_parent_count: u64 = 0; 857 for (parent_oids) |*parent_oid| { 858 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 859 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 860 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 861 862 // if this object id has already been consumed, skip it 863 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 864 continue; 865 } 866 867 // if this object id hasn't already been seen, add it to the walk queue 868 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 869 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 870 } 871 872 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 873 const children = try DB.HashSet(.read_write).init(children_cursor); 874 try children.put(oid_int, .{ .bytes = &oid }); 875 pending_parent_count += 1; 876 } 877 878 if (pending_parent_count == 0) { 879 try self.ready_queue.append(.{ .bytes = &oid }); 880 } else { 881 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 882 } 883 } 884 } 885 886 fn enqueueChildren(self: *CommitIterator(repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 887 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 888 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 889 const children = try DB.HashSet(.read_only).init(children_cursor); 890 var children_iter = try children.iterator(); 891 892 while (try children_iter.next()) |*child_cursor| { 893 const kv_pair = try child_cursor.readKeyValuePair(); 894 const child_oid_int = kv_pair.hash; 895 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 896 const pending_parent_count = try pending_parent_cursor.readUint(); 897 898 if (pending_parent_count <= 1) { 899 _ = try self.child_to_pending_parents.remove(child_oid_int); 900 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 901 try self.ready_queue.append(.{ .bytes = &child_oid }); 902 } else { 903 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 904 } 905 } 906 } 907 908 fn readOidFromList(list: DB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 909 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 910 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 911 _ = try oid_cursor.readBytes(&oid); 912 return oid; 913 } 914 }; 915 } 916