╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1165 io: std.Io, 1166 allocator: std.mem.Allocator, 1167 consumed_object_ids: DB.HashMap(.read_only), 1168 ref: rf.Ref, 1169 ) !void { 1170 const map = try DB.HashMap(.read_write).init(self.db.rootCursor()); 1171 1172 const walk_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "walk-queue")); 1173 const walk_queue = try DB.ArrayList(.read_write).init(walk_queue_cursor); 1174 var walk_queue_index: u64 = 0; 1175 1176 const seen_object_ids_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-object-ids")); 1177 const seen_object_ids = try DB.HashSet(.read_write).init(seen_object_ids_cursor); 1178 1179 const head_oid_hex = (try rf.readRecur(repo_kind, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound; 1180 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1181 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 1182 try walk_queue.append(.{ .bytes = &head_oid }); 1183 1184 while (walk_queue_index < try walk_queue.count()) { 1185 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 1186 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 1187 1188 walk_queue_index += 1; 1189 1190 // if we've seen this object id, skip it 1191 if (null != try seen_object_ids.getCursor(oid_int)) { 1192 continue; 1193 } 1194 1195 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 1196 1197 var commit_object = try obj.Object(repo_kind, repo_opts).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 1198 defer commit_object.deinit(); 1199 1200 // if this object id has already been consumed, skip it 1201 if (null != try consumed_object_ids.getCursor(oid_int)) { 1202 continue; 1203 } 1204 1205 if (self.newest_object_id == null) self.newest_object_id = oid; 1206 self.oldest_object_id = oid; 1207 1208 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 1209 var pending_parent_count: u64 = 0; 1210 for (parent_oids) |*parent_oid| { 1211 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1212 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 1213 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 1214 1215 // if this object id has already been consumed, skip it 1216 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 1217 continue; 1218 } 1219 1220 // if this object id hasn't already been seen, add it to the walk queue 1221 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 1222 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 1223 } 1224 1225 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 1226 const children = try DB.HashSet(.read_write).init(children_cursor); 1227 try children.put(oid_int, .{ .bytes = &oid }); 1228 pending_parent_count += 1; 1229 } 1230 1231 if (pending_parent_count == 0) { 1232 try self.ready_queue.append(.{ .bytes = &oid }); 1233 } else { 1234 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 1235 } 1236 } 1237 } 1238 1239 fn enqueueChildren(self: *CommitIterator(repo_kind, repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 1240 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 1241 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 1242 const children = try DB.HashSet(.read_only).init(children_cursor); 1243 var children_iter = try children.iterator(); 1244 1245 while (try children_iter.next()) |*child_cursor| { 1246 const kv_pair = try child_cursor.readKeyValuePair(); 1247 const child_oid_int = kv_pair.hash; 1248 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 1249 const pending_parent_count = try pending_parent_cursor.readUint(); 1250 1251 if (pending_parent_count <= 1) { 1252 _ = try self.child_to_pending_parents.remove(child_oid_int); 1253 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 1254 try self.ready_queue.append(.{ .bytes = &child_oid }); 1255 } else { 1256 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 1257 } 1258 } 1259 } 1260 1261 fn readOidFromList(list: DB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 1262 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 1263 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1264 _ = try oid_cursor.readBytes(&oid); 1265 return oid; 1266 } 1267 }; 1268 } 1269