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