╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
137 } 138 139 if (!record_to_write.removed) { 140 try name_to_repo_id.put(record_to_write.event.name, .{ .bytes = event_id }); 141 } 142 } 143 144 // a repo plus its event id (the id is the on-disk repo directory name, so the 145 // caller can locate the working repo under <server>/repos/<hex event id>). 146 pub const RepoWithId = struct { 147 repo: Record, 148 event_id: [evt.event_id_size]u8, 149 }; 150 151 // a repo as one viewer sees it 152 pub const RepoWithRole = struct { 153 repo: Record, 154 event_id: [evt.event_id_size]u8, 155 role: Role, 156 }; 157 158 // read a repo by its name from its owner's user repo 159 pub fn readByName( 160 comptime DB: type, 161 comptime hash_kind: hash.HashKind, 162 user_moment: DB.HashMap(.read_only), 163 arena: *std.heap.ArenaAllocator, 164 name: []const u8, 165 ) !?RepoWithId { 166 const name_to_repo_id_cursor = try user_moment.getCursor(hash.hashInt(hash_kind, name_index_key)) orelse return null; 167 const name_to_repo_id = try DB.SortedMap(.read_only).init(name_to_repo_id_cursor); 168 const repo_id_cursor = try name_to_repo_id.getCursor(name) orelse return null; 169 var repo_id: [evt.event_id_size]u8 = undefined; 170 _ = try repo_id_cursor.readBytes(&repo_id); 171 const repo = (try readById(DB, hash_kind, user_moment, arena, &repo_id)) orelse return null; 172 return .{ .repo = repo, .event_id = repo_id }; 173 } 174 175 pub fn readById( 176 comptime DB: type, 177 comptime hash_kind: hash.HashKind, 178 haxy_moment: DB.HashMap(.read_only), 179 arena: *std.heap.ArenaAllocator, 180 id: []const u8, 181 ) !?Record { 182 const records_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, record_map_key)) orelse return null; 183 const records = try DB.HashMap(.read_only).init(records_cursor); 184 const record_cursor = try records.getCursor(hash.hashInt(hash_kind, id)) orelse return null; 185 return try evt.read(Record, DB, hash_kind, arena, try DB.HashMap(.read_only).init(record_cursor)); 186 } 187