╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2521 fn collect( 2522 self: *CommitIterator(repo_kind, repo_opts), 2523 state: rp.Repo(repo_kind, repo_opts).State(.read_only), 2524 io: std.Io, 2525 allocator: std.mem.Allocator, 2526 consumed_object_ids: DB.HashMap(.read_only), 2527 ref: rf.Ref, 2528 ) !void { 2529 const map = try TempDB.HashMap(.read_write).init(self.db.rootCursor()); 2530 2531 const walk_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "walk-queue")); 2532 const walk_queue = try TempDB.ArrayList(.read_write).init(walk_queue_cursor); 2533 var walk_queue_index: u64 = 0; 2534 2535 const seen_object_ids_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-object-ids")); 2536 const seen_object_ids = try TempDB.HashSet(.read_write).init(seen_object_ids_cursor); 2537 2538 const head_oid_hex = (try rf.readRecur(repo_kind, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound; 2539 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 2540 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 2541 try walk_queue.append(.{ .bytes = &head_oid }); 2542 2543 while (walk_queue_index < try walk_queue.count()) { 2544 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 2545 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 2546 2547 walk_queue_index += 1; 2548 2549 // if we've seen this object id, skip it 2550 if (null != try seen_object_ids.getCursor(oid_int)) { 2551 continue; 2552 } 2553 2554 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 2555 2556 var commit_object = try obj.Object(repo_kind, repo_opts).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 2557 defer commit_object.deinit(); 2558 2559 // if this object id has already been consumed, skip it 2560 if (null != try consumed_object_ids.getCursor(oid_int)) { 2561 continue; 2562 } 2563 2564 if (self.newest_object_id == null) self.newest_object_id = oid; 2565 self.oldest_object_id = oid; 2566 2567 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 2568 var pending_parent_count: u64 = 0; 2569 for (parent_oids) |*parent_oid| { 2570 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 2571 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 2572 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 2573 2574 // if this object id has already been consumed, skip it 2575 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 2576 continue; 2577 } 2578 2579 // if this object id hasn't already been seen, add it to the walk queue 2580 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 2581 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 2582 } 2583 2584 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 2585 const children = try TempDB.HashSet(.read_write).init(children_cursor); 2586 try children.put(oid_int, .{ .bytes = &oid }); 2587 pending_parent_count += 1; 2588 } 2589 2590 if (pending_parent_count == 0) { 2591 try self.ready_queue.append(.{ .bytes = &oid }); 2592 } else { 2593 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 2594 } 2595 } 2596 } 2597 2598 fn enqueueChildren(self: *CommitIterator(repo_kind, repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 2599 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 2600 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 2601 const children = try TempDB.HashSet(.read_only).init(children_cursor); 2602 var children_iter = try children.iterator(); 2603 2604 while (try children_iter.next()) |*child_cursor| { 2605 const kv_pair = try child_cursor.readKeyValuePair(); 2606 const child_oid_int = kv_pair.hash; 2607 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 2608 const pending_parent_count = try pending_parent_cursor.readUint(); 2609 2610 if (pending_parent_count <= 1) { 2611 _ = try self.child_to_pending_parents.remove(child_oid_int); 2612 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 2613 try self.ready_queue.append(.{ .bytes = &child_oid }); 2614 } else { 2615 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 2616 } 2617 } 2618 } 2619 2620 fn readOidFromList(list: TempDB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 2621 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 2622 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 2623 _ = try oid_cursor.readBytes(&oid); 2624 return oid; 2625 } 2626 }; 2627 } 2628