╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
842 843 const walk_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "walk-queue")); 844 const walk_queue = try DB.ArrayList(.read_write).init(walk_queue_cursor); 845 var walk_queue_index: u64 = 0; 846 847 const seen_object_ids_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-object-ids")); 848 const seen_object_ids = try DB.HashSet(.read_write).init(seen_object_ids_cursor); 849 850 const head_oid_hex = (try rf.readRecur(.xit, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound; 851 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 852 _ = try std.fmt.hexToBytes(&head_oid, &head_oid_hex); 853 try walk_queue.append(.{ .bytes = &head_oid }); 854 855 while (walk_queue_index < try walk_queue.count()) { 856 const oid = try readOidFromList(walk_queue.readOnly(), walk_queue_index); 857 const oid_int = hash.bytesToInt(repo_opts.hash, &oid); 858 859 walk_queue_index += 1; 860 861 // if we've seen this object id, skip it 862 if (null != try seen_object_ids.getCursor(oid_int)) { 863 continue; 864 } 865 866 try seen_object_ids.put(oid_int, .{ .bytes = &oid }); 867 868 var commit_object = try obj.Object(.xit, repo_opts, .full).init(state, io, allocator, &std.fmt.bytesToHex(oid, .lower)); 869 defer commit_object.deinit(); 870 871 // if this object id has already been consumed, skip it 872 if (null != try consumed_object_ids.getCursor(oid_int)) { 873 continue; 874 } 875 876 if (self.newest_object_id == null) self.newest_object_id = oid; 877 self.oldest_object_id = oid; 878 879 const parent_oids = commit_object.content.commit.metadata.parent_oids orelse return error.ParentOidsNotFound; 880 var pending_parent_count: u64 = 0; 881 for (parent_oids) |*parent_oid| { 882 var parent_oid_bytes: [hash.byteLen(repo_opts.hash)]u8 = undefined; 883 _ = try std.fmt.hexToBytes(&parent_oid_bytes, parent_oid); 884 const parent_oid_int = hash.bytesToInt(repo_opts.hash, &parent_oid_bytes); 885 886 // if this object id has already been consumed, skip it 887 if (null != try consumed_object_ids.getCursor(parent_oid_int)) { 888 continue; 889 } 890 891 // if this object id hasn't already been seen, add it to the walk queue 892 if (null == try seen_object_ids.getCursor(parent_oid_int)) { 893 try walk_queue.append(.{ .bytes = &parent_oid_bytes }); 894 } 895 896 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int); 897 const children = try DB.HashSet(.read_write).init(children_cursor); 898 try children.put(oid_int, .{ .bytes = &oid }); 899 pending_parent_count += 1; 900 } 901 902 if (pending_parent_count == 0) { 903 try self.ready_queue.append(.{ .bytes = &oid }); 904 } else { 905 try self.child_to_pending_parents.put(oid_int, .{ .uint = pending_parent_count }); 906 } 907 } 908 } 909 910 fn enqueueChildren(self: *CommitIterator(repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void { 911 const oid_int = hash.bytesToInt(repo_opts.hash, oid); 912 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; 913 const children = try DB.HashSet(.read_only).init(children_cursor); 914 var children_iter = try children.iterator(); 915 916 while (try children_iter.next()) |*child_cursor| { 917 const kv_pair = try child_cursor.readKeyValuePair(); 918 const child_oid_int = kv_pair.hash; 919 const pending_parent_cursor = try self.child_to_pending_parents.getCursor(child_oid_int) orelse return error.CursorNotFound; 920 const pending_parent_count = try pending_parent_cursor.readUint(); 921 922 if (pending_parent_count <= 1) { 923 _ = try self.child_to_pending_parents.remove(child_oid_int); 924 const child_oid = hash.intToBytes(hash.HashInt(repo_opts.hash), child_oid_int); 925 try self.ready_queue.append(.{ .bytes = &child_oid }); 926 } else { 927 try self.child_to_pending_parents.put(child_oid_int, .{ .uint = pending_parent_count - 1 }); 928 } 929 } 930 } 931 932 fn readOidFromList(list: DB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { 933 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; 934 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; 935 _ = try oid_cursor.readBytes(&oid); 936 return oid; 937 } 938 }; 939 } 940