╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
154 if (!existing_record.removed) { 155 _ = try name_to_repo_id.remove(existing_record.event.name); 156 } 157 } 158 159 const repo_cursor = try event_id_to_repo.putCursor(repo_key); 160 const repo = try DB.HashMap(.read_write).init(repo_cursor); 161 try evt.upsert(Record, DB, hash_kind, repo, record_to_write); 162 try evt.indexEvent(DB, hash_kind, haxy_moment, event_id, .repo, existing_record_maybe, record_to_write); 163 164 const order_key = evt.orderKeyDesc(record_to_write.created_order, event_id); 165 166 // the id set retains removed records so merges can carry removals 167 if (existing_cursor_maybe == null) { 168 const repo_id_set_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, all_id_set_key)); 169 const repo_id_set = try DB.SortedSet(.read_write).init(repo_id_set_cursor); 170 try repo_id_set.put(&order_key); 171 } 172 173 if (!record_to_write.removed) { 174 try name_to_repo_id.put(record_to_write.event.name, .{ .bytes = event_id }); 175 } 176 } 177 178 // a repo plus its event id (the id is the on-disk repo directory name, so the 179 // caller can locate the working repo under <server>/repos/<hex event id>). 180 pub const RepoWithId = struct { 181 repo: Record, 182 event_id: [evt.event_id_size]u8, 183 }; 184 185 // a repo as one viewer sees it. without a role, the viewer may not see it. 186 pub const RepoWithRole = struct { 187 repo: Record, 188 event_id: [evt.event_id_size]u8, 189 role: ?Role, 190 }; 191 192 // read a repo by its name from its owner's user repo 193 pub fn readByName( 194 comptime DB: type, 195 comptime hash_kind: hash.HashKind, 196 user_moment: DB.HashMap(.read_only), 197 arena: *std.heap.ArenaAllocator, 198 name: []const u8, 199 ) !?RepoWithId { 200 const name_to_repo_id_cursor = try user_moment.getCursor(hash.hashInt(hash_kind, name_index_key)) orelse return null; 201 const name_to_repo_id = try DB.SortedMap(.read_only).init(name_to_repo_id_cursor); 202 const repo_id_cursor = try name_to_repo_id.getCursor(name) orelse return null; 203 var repo_id: [evt.event_id_size]u8 = undefined; 204 _ = try repo_id_cursor.readBytes(&repo_id); 205 const repo = (try readById(DB, hash_kind, user_moment, arena, &repo_id)) orelse return null; 206 return .{ .repo = repo, .event_id = repo_id }; 207 } 208 209 pub fn readById( 210 comptime DB: type, 211 comptime hash_kind: hash.HashKind, 212 haxy_moment: DB.HashMap(.read_only), 213 arena: *std.heap.ArenaAllocator, 214 id: []const u8, 215 ) !?Record { 216 const records_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, record_map_key)) orelse return null; 217 const records = try DB.HashMap(.read_only).init(records_cursor); 218 const record_cursor = try records.getCursor(hash.hashInt(hash_kind, id)) orelse return null; 219 return try evt.read(Record, DB, hash_kind, arena, try DB.HashMap(.read_only).init(record_cursor)); 220 } 221