╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
3012 ) !void { 3013 const map = try TempDB.HashMap(.read_write).init(self.db.rootCursor()); 3014 3015 const walk_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "walk-queue")); 3016 const walk_queue = try TempDB.ArrayList(.read_write).init(walk_queue_cursor); 3017 var walk_queue_index: u64 = 0; 3018 3019 const seen_object_ids_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-object-ids")); 3020 const seen_object_ids = try TempDB.HashSet(.read_write).init(seen_object_ids_cursor); 3021 3022 const head_oid_hex = (try rf.readRecur(repo_kind, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound; 3023 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 3024 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 3025 try walk_queue.append(.{ .bytes = &head_oid }); 3026 3027 while (walk_queue_index < try walk_queue.count()) { 3028 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 3029 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 3030 3031 walk_queue_index += 1; 3032 3033 // if we've seen this object id, skip it 3034 if (null != try seen_object_ids.getCursor(oid_int)) { 3035 continue; 3036 } 3037 3038 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 3039 3040 var commit_object = try obj.Object(repo_kind, repo_opts).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 3041 defer commit_object.deinit(); 3042 3043 // if this object id has already been consumed, skip it 3044 if (null != try consumed_object_ids.getCursor(oid_int)) { 3045 continue; 3046 } 3047 3048 if (self.newest_object_id == null) self.newest_object_id = oid; 3049 self.oldest_object_id = oid; 3050 3051 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 3052 var pending_parent_count: u64 = 0; 3053 for (parent_oids) |*parent_oid| { 3054 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 3055 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 3056 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 3057 3058 // if this object id has already been consumed, skip it 3059 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 3060 continue; 3061 } 3062 3063 // if this object id hasn't already been seen, add it to the walk queue 3064 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 3065 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 3066 } 3067 3068 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 3069 const children = try TempDB.HashSet(.read_write).init(children_cursor); 3070 try children.put(oid_int, .{ .bytes = &oid }); 3071 pending_parent_count += 1; 3072 } 3073 3074 if (pending_parent_count == 0) { 3075 try self.ready_queue.append(.{ .bytes = &oid }); 3076 } else { 3077 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 3078 } 3079 } 3080 } 3081 3082 fn enqueueChildren(self: *CommitIterator(repo_kind, repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 3083 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 3084 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 3085 const children = try TempDB.HashSet(.read_only).init(children_cursor); 3086 var children_iter = try children.iterator(); 3087 3088 while (try children_iter.next()) |*child_cursor| { 3089 const kv_pair = try child_cursor.readKeyValuePair(); 3090 const child_oid_int = kv_pair.hash; 3091 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 3092 const pending_parent_count = try pending_parent_cursor.readUint(); 3093 3094 if (pending_parent_count <= 1) { 3095 _ = try self.child_to_pending_parents.remove(child_oid_int); 3096 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 3097 try self.ready_queue.append(.{ .bytes = &child_oid }); 3098 } else { 3099 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 3100 } 3101 } 3102 } 3103 3104 fn readOidFromList(list: TempDB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 3105 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 3106 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 3107 _ = try oid_cursor.readBytes(&oid); 3108 return oid; 3109 } 3110 }; 3111 } 3112