╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2148 while (walk_queue_index < try walk_queue.count()) { 2149 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 2150 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 2151 2152 walk_queue_index += 1; 2153 2154 // if we've seen this object id, skip it 2155 if (null != try seen_object_ids.getCursor(oid_int)) { 2156 continue; 2157 } 2158 2159 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 2160 2161 var commit_object = try obj.Object(repo_kind, repo_opts).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 2162 defer commit_object.deinit(); 2163 2164 // if this object id has already been consumed, skip it 2165 if (null != try consumed_object_ids.getCursor(oid_int)) { 2166 continue; 2167 } 2168 2169 if (self.newest_object_id == null) self.newest_object_id = oid; 2170 self.oldest_object_id = oid; 2171 2172 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 2173 var pending_parent_count: u64 = 0; 2174 for (parent_oids) |*parent_oid| { 2175 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 2176 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 2177 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 2178 2179 // if this object id has already been consumed, skip it 2180 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 2181 continue; 2182 } 2183 2184 // if this object id hasn't already been seen, add it to the walk queue 2185 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 2186 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 2187 } 2188 2189 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 2190 const children = try TempDB.HashSet(.read_write).init(children_cursor); 2191 try children.put(oid_int, .{ .bytes = &oid }); 2192 pending_parent_count += 1; 2193 } 2194 2195 if (pending_parent_count == 0) { 2196 try self.ready_queue.append(.{ .bytes = &oid }); 2197 } else { 2198 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 2199 } 2200 } 2201 } 2202 2203 fn enqueueChildren(self: *CommitIterator(repo_kind, repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 2204 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 2205 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 2206 const children = try TempDB.HashSet(.read_only).init(children_cursor); 2207 var children_iter = try children.iterator(); 2208 2209 while (try children_iter.next()) |*child_cursor| { 2210 const kv_pair = try child_cursor.readKeyValuePair(); 2211 const child_oid_int = kv_pair.hash; 2212 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 2213 const pending_parent_count = try pending_parent_cursor.readUint(); 2214 2215 if (pending_parent_count <= 1) { 2216 _ = try self.child_to_pending_parents.remove(child_oid_int); 2217 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 2218 try self.ready_queue.append(.{ .bytes = &child_oid }); 2219 } else { 2220 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 2221 } 2222 } 2223 } 2224 2225 fn readOidFromList(list: TempDB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 2226 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 2227 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 2228 _ = try oid_cursor.readBytes(&oid); 2229 return oid; 2230 } 2231 }; 2232 } 2233