╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
162 _ = try user_repos.remove(&order_key); 163 164 _ = try conflicts.remove(&order_key); 165 _ = try repo_id_to_field_to_oid.remove(repo_key); 166 } 167 if (!try event_id_to_repo.remove(repo_key)) return error.EventNotFound; 168 } 169 } 170 171 // a repo plus its event id (the id is the on-disk repo directory name, so the 172 // caller can locate the working repo under <server>/repos/<hex event id>). 173 pub const RepoWithId = struct { 174 repo: Self, 175 event_id: [evt.event_id_size]u8, 176 }; 177 178 // read a repo by its owner's name and repo name. the owner name is resolved to 179 // a user id via name->user-id (the repo index is keyed by "user-id/repo-name"), 180 // matching the /repo/username/reponame url. 181 pub fn readByOwnerAndName( 182 comptime DB: type, 183 comptime hash_kind: hash.HashKind, 184 haxy_moment: DB.HashMap(.read_only), 185 arena: *std.heap.ArenaAllocator, 186 owner_name: []const u8, 187 repo_name: []const u8, 188 ) !?RepoWithId { 189 // owner name -> user id 190 const name_to_user_id_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, "name->user-id")) orelse return null; 191 const name_to_user_id = try DB.HashMap(.read_only).init(name_to_user_id_cursor); 192 const user_id_cursor = try name_to_user_id.getCursor(hash.hashInt(hash_kind, owner_name)) orelse return null; 193 var user_id: [evt.event_id_size]u8 = undefined; 194 _ = try user_id_cursor.readBytes(&user_id); 195 196 // "user-id/repo-name" -> repo event id 197 const repo_path = try (Self{ .user_id = user_id[0..], .name = repo_name, .description = "" }).indexKey(arena.allocator()); 198 const name_to_repo_id_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, "name->repo-id")) orelse return null; 199 const name_to_repo_id = try DB.HashMap(.read_only).init(name_to_repo_id_cursor); 200 const repo_id_cursor = try name_to_repo_id.getCursor(hash.hashInt(hash_kind, repo_path)) orelse return null; 201 var repo_id: [evt.event_id_size]u8 = undefined; 202 _ = try repo_id_cursor.readBytes(&repo_id); 203 204 const event_id_to_repo_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, "event-id->repo")) orelse return null; 205 const event_id_to_repo = try DB.HashMap(.read_only).init(event_id_to_repo_cursor); 206 const repo_cursor = try event_id_to_repo.getCursor(hash.hashInt(hash_kind, &repo_id)) orelse return null; 207 const repo_map = try DB.HashMap(.read_only).init(repo_cursor); 208 return .{ .repo = try evt.read(@This(), DB, hash_kind, arena, repo_map), .event_id = repo_id }; 209 } 210