╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ PatchRev.zig ─────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
238 comptime hash_kind: hash.HashKind, 239 haxy_moment: DB.HashMap(.read_only), 240 arena: *std.heap.ArenaAllocator, 241 id: *const [evt.event_id_size]u8, 242 ) !?Record { 243 const records_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, record_map_key)) orelse return null; 244 const records = try DB.HashMap(.read_only).init(records_cursor); 245 const record_cursor = try records.getCursor(hash.hashInt(hash_kind, id)) orelse return null; 246 return try evt.read(Record, DB, hash_kind, arena, try DB.HashMap(.read_only).init(record_cursor)); 247 } 248 249 pub const WithId = struct { 250 id: [evt.event_id_size]u8, 251 record: Record, 252 }; 253 254 pub fn readNewest( 255 comptime DB: type, 256 comptime hash_kind: hash.HashKind, 257 haxy_moment: DB.HashMap(.read_only), 258 arena: *std.heap.ArenaAllocator, 259 ) !?WithId { 260 const ids_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, all_id_set_key)) orelse return null; 261 const ids = try DB.SortedSet(.read_only).init(ids_cursor); 262 var iter = try ids.iteratorFromIndex(0); 263 while (try iter.next()) |cursor| { 264 const id = try evt.readOrderKeyId(DB, cursor); 265 const record = (try readById(DB, hash_kind, haxy_moment, arena, &id)) orelse continue; 266 if (!record.removed) return .{ .id = id, .record = record }; 267 } 268 return null; 269 } 270 271 // squash commits referenced only by patch revision records 272 pub fn gcRoots( 273 comptime DB: type, 274 comptime hash_kind: hash.HashKind, 275 allocator: std.mem.Allocator, 276 haxy_moment: DB.HashMap(.read_only), 277 ) ![][hash.hexLen(hash_kind)]u8 { 278 var roots: std.ArrayList([hash.hexLen(hash_kind)]u8) = .empty; 279 errdefer roots.deinit(allocator); 280 var arena = std.heap.ArenaAllocator.init(allocator); 281 defer arena.deinit(); 282 283 const ids_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, all_id_set_key)) orelse return try roots.toOwnedSlice(allocator); 284 const ids = try DB.SortedSet(.read_only).init(ids_cursor); 285 var iter = try ids.iteratorFromIndex(0); 286 while (try iter.next()) |cursor| { 287 _ = arena.reset(.retain_capacity); 288 const id = try evt.readOrderKeyId(DB, cursor); 289 const record = (try readById(DB, hash_kind, haxy_moment, &arena, &id)) orelse continue; 290 var oid: [hash.hexLen(hash_kind)]u8 = undefined; 291 if (record.patch_oid.len != oid.len) return error.InvalidOid; 292 @memcpy(&oid, record.patch_oid); 293 try roots.append(allocator, oid); 294 } 295 296 return try roots.toOwnedSlice(allocator); 297 } 298