╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2037 ref: rf.Ref, 2038 ) !void { 2039 const map = try DB.HashMap(.read_write).init(self.db.rootCursor()); 2040 2041 const walk_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "walk-queue")); 2042 const walk_queue = try DB.ArrayList(.read_write).init(walk_queue_cursor); 2043 var walk_queue_index: u64 = 0; 2044 2045 const seen_object_ids_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-object-ids")); 2046 const seen_object_ids = try DB.HashSet(.read_write).init(seen_object_ids_cursor); 2047 2048 const head_oid_hex = (try rf.readRecur(repo_kind, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound; 2049 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 2050 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 2051 try walk_queue.append(.{ .bytes = &head_oid }); 2052 2053 while (walk_queue_index < try walk_queue.count()) { 2054 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 2055 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 2056 2057 walk_queue_index += 1; 2058 2059 // if we've seen this object id, skip it 2060 if (null != try seen_object_ids.getCursor(oid_int)) { 2061 continue; 2062 } 2063 2064 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 2065 2066 var commit_object = try obj.Object(repo_kind, repo_opts).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 2067 defer commit_object.deinit(); 2068 2069 // if this object id has already been consumed, skip it 2070 if (null != try consumed_object_ids.getCursor(oid_int)) { 2071 continue; 2072 } 2073 2074 if (self.newest_object_id == null) self.newest_object_id = oid; 2075 self.oldest_object_id = oid; 2076 2077 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 2078 var pending_parent_count: u64 = 0; 2079 for (parent_oids) |*parent_oid| { 2080 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 2081 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 2082 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 2083 2084 // if this object id has already been consumed, skip it 2085 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 2086 continue; 2087 } 2088 2089 // if this object id hasn't already been seen, add it to the walk queue 2090 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 2091 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 2092 } 2093 2094 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 2095 const children = try DB.HashSet(.read_write).init(children_cursor); 2096 try children.put(oid_int, .{ .bytes = &oid }); 2097 pending_parent_count += 1; 2098 } 2099 2100 if (pending_parent_count == 0) { 2101 try self.ready_queue.append(.{ .bytes = &oid }); 2102 } else { 2103 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 2104 } 2105 } 2106 } 2107 2108 fn enqueueChildren(self: *CommitIterator(repo_kind, repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 2109 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 2110 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 2111 const children = try DB.HashSet(.read_only).init(children_cursor); 2112 var children_iter = try children.iterator(); 2113 2114 while (try children_iter.next()) |*child_cursor| { 2115 const kv_pair = try child_cursor.readKeyValuePair(); 2116 const child_oid_int = kv_pair.hash; 2117 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 2118 const pending_parent_count = try pending_parent_cursor.readUint(); 2119 2120 if (pending_parent_count <= 1) { 2121 _ = try self.child_to_pending_parents.remove(child_oid_int); 2122 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 2123 try self.ready_queue.append(.{ .bytes = &child_oid }); 2124 } else { 2125 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 2126 } 2127 } 2128 } 2129 2130 fn readOidFromList(list: DB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 2131 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 2132 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 2133 _ = try oid_cursor.readBytes(&oid); 2134 return oid; 2135 } 2136 }; 2137 } 2138