╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
140 // a repo plus its event id (the id is the on-disk repo directory name, so the 141 // caller can locate the working repo under <server>/repos/<hex event id>). 142 pub const RepoWithId = struct { 143 repo: Record, 144 event_id: [evt.event_id_size]u8, 145 }; 146 147 // read a repo by its owner's name and repo name. the owner name is resolved to 148 // a user id via name->user-id (the repo index is keyed by "user-id/repo-name"), 149 // matching the /repo/username/reponame url. 150 pub fn readByOwnerAndName( 151 comptime DB: type, 152 comptime hash_kind: hash.HashKind, 153 haxy_moment: DB.HashMap(.read_only), 154 arena: *std.heap.ArenaAllocator, 155 owner_name: []const u8, 156 repo_name: []const u8, 157 ) !?RepoWithId { 158 // owner name -> user id 159 const name_to_user_id_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, "name->user-id")) orelse return null; 160 const name_to_user_id = try DB.HashMap(.read_only).init(name_to_user_id_cursor); 161 const user_id_cursor = try name_to_user_id.getCursor(hash.hashInt(hash_kind, owner_name)) orelse return null; 162 var user_id: [evt.event_id_size]u8 = undefined; 163 _ = try user_id_cursor.readBytes(&user_id); 164 165 // "user-id/repo-name" -> repo event id 166 const repo_path = try (Record{ .event = .{ .user_id = user_id[0..], .name = repo_name, .description = "" } }).indexKey(arena.allocator()); 167 const name_to_repo_id_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, "name->repo-id")) orelse return null; 168 const name_to_repo_id = try DB.HashMap(.read_only).init(name_to_repo_id_cursor); 169 const repo_id_cursor = try name_to_repo_id.getCursor(hash.hashInt(hash_kind, repo_path)) orelse return null; 170 var repo_id: [evt.event_id_size]u8 = undefined; 171 _ = try repo_id_cursor.readBytes(&repo_id); 172 173 const event_id_to_repo_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, "event-id->repo")) orelse return null; 174 const event_id_to_repo = try DB.HashMap(.read_only).init(event_id_to_repo_cursor); 175 const repo_cursor = try event_id_to_repo.getCursor(hash.hashInt(hash_kind, &repo_id)) orelse return null; 176 const repo_map = try DB.HashMap(.read_only).init(repo_cursor); 177 return .{ .repo = try evt.read(Record, DB, hash_kind, arena, repo_map), .event_id = repo_id }; 178 } 179 180 pub fn readById( 181 comptime DB: type, 182 comptime hash_kind: hash.HashKind, 183 haxy_moment: DB.HashMap(.read_only), 184 arena: *std.heap.ArenaAllocator, 185 id: []const u8, 186 ) !?Record { 187 const records_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, record_map_key)) orelse return null; 188 const records = try DB.HashMap(.read_only).init(records_cursor); 189 const record_cursor = try records.getCursor(hash.hashInt(hash_kind, id)) orelse return null; 190 return try evt.read(Record, DB, hash_kind, arena, try DB.HashMap(.read_only).init(record_cursor)); 191 } 192