╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2892 const walk_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "walk-queue")); 2893 const walk_queue = try TempDB.ArrayList(.read_write).init(walk_queue_cursor); 2894 var walk_queue_index: u64 = 0; 2895 2896 const seen_object_ids_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-object-ids")); 2897 const seen_object_ids = try TempDB.HashSet(.read_write).init(seen_object_ids_cursor); 2898 2899 const head_oid_hex = (try rf.readRecur(repo_kind, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound; 2900 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 2901 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 2902 try walk_queue.append(.{ .bytes = &head_oid }); 2903 2904 while (walk_queue_index < try walk_queue.count()) { 2905 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 2906 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 2907 2908 walk_queue_index += 1; 2909 2910 // if we've seen this object id, skip it 2911 if (null != try seen_object_ids.getCursor(oid_int)) { 2912 continue; 2913 } 2914 2915 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 2916 2917 var commit_object = try obj.Object(repo_kind, repo_opts).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 2918 defer commit_object.deinit(); 2919 2920 // if this object id has already been consumed, skip it 2921 if (null != try consumed_object_ids.getCursor(oid_int)) { 2922 continue; 2923 } 2924 2925 if (self.newest_object_id == null) self.newest_object_id = oid; 2926 self.oldest_object_id = oid; 2927 2928 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 2929 var pending_parent_count: u64 = 0; 2930 for (parent_oids) |*parent_oid| { 2931 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 2932 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 2933 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 2934 2935 // if this object id has already been consumed, skip it 2936 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 2937 continue; 2938 } 2939 2940 // if this object id hasn't already been seen, add it to the walk queue 2941 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 2942 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 2943 } 2944 2945 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 2946 const children = try TempDB.HashSet(.read_write).init(children_cursor); 2947 try children.put(oid_int, .{ .bytes = &oid }); 2948 pending_parent_count += 1; 2949 } 2950 2951 if (pending_parent_count == 0) { 2952 try self.ready_queue.append(.{ .bytes = &oid }); 2953 } else { 2954 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 2955 } 2956 } 2957 } 2958 2959 fn enqueueChildren(self: *CommitIterator(repo_kind, repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 2960 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 2961 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 2962 const children = try TempDB.HashSet(.read_only).init(children_cursor); 2963 var children_iter = try children.iterator(); 2964 2965 while (try children_iter.next()) |*child_cursor| { 2966 const kv_pair = try child_cursor.readKeyValuePair(); 2967 const child_oid_int = kv_pair.hash; 2968 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 2969 const pending_parent_count = try pending_parent_cursor.readUint(); 2970 2971 if (pending_parent_count <= 1) { 2972 _ = try self.child_to_pending_parents.remove(child_oid_int); 2973 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 2974 try self.ready_queue.append(.{ .bytes = &child_oid }); 2975 } else { 2976 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 2977 } 2978 } 2979 } 2980 2981 fn readOidFromList(list: TempDB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 2982 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 2983 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 2984 _ = try oid_cursor.readBytes(&oid); 2985 return oid; 2986 } 2987 }; 2988 } 2989