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