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