╭ changed ────╮ │build.zig.zon│ ╰─────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 3 .version = "0.0.0", │ │ 4 .dependencies = .{ │ │ 5 .xit = .{ │ │ 6 - .url = "git+https://github.com/xit-vcs/xit#1720974f8a5838911f49a1f0860903a486aad187",│ │ 7 - .hash = "xit-0.0.0-Ub3nDLTjTwFHd50Y_8iD0214P_5FvzxkG1P_Jgu64lcs", │ │ 6 + .url = "git+https://github.com/xit-vcs/xit#33d6feef019b1cbef6ef4a564437a05f53d66831",│ │ 7 + .hash = "xit-0.0.0-Ub3nDKXiTwGfl548rVnm4yhEw9MqGslV5qfV7ufEzyl5", │ │ 8 }, │ │ 9 }, │ │10 .paths = .{ │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ─────────╮ │src/event/Repo.zig│ ╰──────────────────╯ ╭────────────────────────────────╮ │ 7 name: []const u8, │ │ 8 description: []const u8, │ │ 9 enable_issue: bool, │ │10 + │ │11 +pub const name_max_len = 32;│ │12 │ │13 pub fn consume( │ │14 comptime DB: type, │ ╰────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │22 │ │23 const event_id_to_repo_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, "event-id->repo")); │ │24 const event_id_to_repo = try DB.HashMap(.read_write).init(event_id_to_repo_cursor); │ │25 + │ │26 + const name_to_repo_id_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, "name->repo-id")); │ │27 + const name_to_repo_id = try DB.HashMap(.read_write).init(name_to_repo_id_cursor); │ │28 │ │29 if (event_maybe) |event| { │ │30 + if (event.name.len > name_max_len) return error.NameTooLong; │ │31 + │ │32 + // the index is keyed by "user-id/repo-name": a repo is unique per │ │33 + // owner, and the read side resolves the url's username to its user id. │ │34 + const repo_path = try std.fmt.allocPrint(arena.allocator(), "{s}/{s}", .{ event.user_id, event.name }); │ │35 + │ │36 + // if this event_id already maps to a repo under a different key (its │ │37 + // name or owner changed), drop the stale name->id entry first │ │38 + if (try event_id_to_repo.getCursor(repo_key)) |existing_cursor| { │ │39 + const existing_repo = try DB.HashMap(.read_only).init(existing_cursor); │ │40 + const existing_event = try evt.read(@This(), DB, hash_kind, arena, existing_repo); │ │41 + const existing_path = try std.fmt.allocPrint(arena.allocator(), "{s}/{s}", .{ existing_event.user_id, existing_event.name });│ │42 + if (!std.mem.eql(u8, existing_path, repo_path)) { │ │43 + _ = try name_to_repo_id.remove(hash.hashInt(hash_kind, existing_path)); │ │44 + } │ │45 + } │ │46 + │ │47 const repo_cursor = try event_id_to_repo.putCursor(repo_key); │ │48 const repo = try DB.HashMap(.read_write).init(repo_cursor); │ │49 try evt.upsert(@This(), DB, hash_kind, repo, event); │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │50 │ │51 + try name_to_repo_id.put(hash.hashInt(hash_kind, repo_path), .{ .bytes = event_id }); │ │52 + │ │53 const user_id_to_repos_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, "user-id->repos"));│ │54 const user_id_to_repos = try DB.HashMap(.read_write).init(user_id_to_repos_cursor); │ │55 │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │60 if (try event_id_to_repo.getCursor(repo_key)) |existing_repo_cursor| { │ │61 const existing_repo = try DB.HashMap(.read_only).init(existing_repo_cursor); │ │62 const existing_repo_event = try evt.read(@This(), DB, hash_kind, arena, existing_repo); │ │63 + │ │64 + const existing_path = try std.fmt.allocPrint(arena.allocator(), "{s}/{s}", .{ existing_repo_event.user_id, existing_repo_event.name });│ │65 + _ = try name_to_repo_id.remove(hash.hashInt(hash_kind, existing_path)); │ │66 │ │67 const user_id_to_repos_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, "user-id->repos")); │ │68 const user_id_to_repos = try DB.HashMap(.read_write).init(user_id_to_repos_cursor); │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 74 } │ │ 75 if (!try event_id_to_repo.remove(repo_key)) return error.EventNotFound; │ │ 76 } │ │ 77 +} │ │ 78 + │ │ 79 +// read a repo by its owner's name and repo name. the owner name is resolved to │ │ 80 +// a user id via name->user-id (the repo index is keyed by "user-id/repo-name"), │ │ 81 +// matching the /repo/username/reponame url. │ │ 82 +pub fn readByOwnerAndName( │ │ 83 + comptime DB: type, │ │ 84 + comptime hash_kind: hash.HashKind, │ │ 85 + haxy_moment: DB.HashMap(.read_only), │ │ 86 + arena: *std.heap.ArenaAllocator, │ │ 87 + owner_name: []const u8, │ │ 88 + repo_name: []const u8, │ │ 89 +) !?@This() { │ │ 90 + // owner name -> user id │ │ 91 + const name_to_user_id_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, "name->user-id")) orelse return null; │ │ 92 + const name_to_user_id = try DB.HashMap(.read_only).init(name_to_user_id_cursor); │ │ 93 + const user_id_cursor = try name_to_user_id.getCursor(hash.hashInt(hash_kind, owner_name)) orelse return null; │ │ 94 + var user_id: [evt.event_id_size]u8 = undefined; │ │ 95 + _ = try user_id_cursor.readBytes(&user_id); │ │ 96 + │ │ 97 + // "user-id/repo-name" -> repo event id │ │ 98 + const repo_path = try std.fmt.allocPrint(arena.allocator(), "{s}/{s}", .{ user_id[0..], repo_name }); │ │ 99 + const name_to_repo_id_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, "name->repo-id")) orelse return null; │ │100 + const name_to_repo_id = try DB.HashMap(.read_only).init(name_to_repo_id_cursor); │ │101 + const repo_id_cursor = try name_to_repo_id.getCursor(hash.hashInt(hash_kind, repo_path)) orelse return null; │ │102 + var repo_id: [evt.event_id_size]u8 = undefined; │ │103 + _ = try repo_id_cursor.readBytes(&repo_id); │ │104 + │ │105 + const event_id_to_repo_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, "event-id->repo")) orelse return null;│ │106 + const event_id_to_repo = try DB.HashMap(.read_only).init(event_id_to_repo_cursor); │ │107 + const repo_cursor = try event_id_to_repo.getCursor(hash.hashInt(hash_kind, &repo_id)) orelse return null; │ │108 + const repo_map = try DB.HashMap(.read_only).init(repo_cursor); │ │109 + return try evt.read(@This(), DB, hash_kind, arena, repo_map); │ │110 } │ │111 │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ─╮ │src/ui.zig│ ╰──────────╯ ╭────────────────────────────────────────────────╮ │12 │ │13 pub const Home = @import("./ui/Home.zig"); │ │14 pub const User = @import("./ui/User.zig"); │ │15 +pub const Repo = @import("./ui/Repo.zig"); │ │16 pub const Title = @import("./ui/Title.zig");│ │17 pub const Quit = @import("./ui/Quit.zig"); │ │18 │ ╰────────────────────────────────────────────────╯ ╭──────────────────────────────────────╮ │19 pub const PageKind = enum { │ │20 home, │ │21 user, │ │22 + repo, │ │23 }; │ │24 │ │25 pub const Page = union(PageKind) {│ ╰──────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │26 home: Home, │ │27 user: User, │ │28 + repo: Repo, │ │29 │ │30 pub fn init(arena: *std.heap.ArenaAllocator, haxy_moment: evt.AdminDB.HashMap(.read_only), route: RoutablePage) !Page {│ │31 return switch (route.parent()) { │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │34 .user, .user_settings, .user_auth => |name| .{ .user = try User.init(arena, haxy_moment, name) },│ │35 else => return error.UnexpectedRoute, │ │36 }, │ │37 + .repo => switch (route) { │ │38 + .repo, .repo_settings, .repo_auth => |name| .{ .repo = try Repo.init(arena, haxy_moment, name) },│ │39 + else => return error.UnexpectedRoute, │ │40 + }, │ │41 }; │ │42 } │ │43 }; │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯