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