╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
954 const event = evt.EventWithId{ .id = events_to_consume2[0].id, .author = author, .event = .{ .issue = null } }; 955 try std.json.Stringify.value(event, .{}, &json.writer); 956 _ = try repo.commitAtRef(io, allocator, .{ .parent_oids = &.{base_oid}, .message = json.written() }, null, other_events_ref); 957 } 958 { 959 json.clearRetainingCapacity(); 960 const event = evt.EventWithId{ .id = events_to_consume2[1].id, .author = author, .event = .{ .issue = null } }; 961 try std.json.Stringify.value(event, .{}, &json.writer); 962 _ = try repo.commitAtRef(io, allocator, .{ .message = json.written() }, null, other_events_ref); 963 } 964 965 { 966 var result = try repo.switchDir(io, allocator, .{ .target = .{ .ref = evt.events_ref } }); 967 defer result.deinit(); 968 969 var merge = try repo.merge(io, allocator, .{ .kind = .full, .action = .{ .new = .{ .source = &.{.{ .ref = other_events_ref }} } } }, null); 970 defer merge.deinit(); 971 972 try std.testing.expect(.success == merge.result); 973 } 974 975 try evt.consume(.local, .repo, .xit, repo_opts, io, allocator, &repo, evt.events_ref, &.{}); 976 977 const haxy_moment = try evt.currentMoment(repo_opts, &repo); 978 979 // the one we left alone is removed, and its tags left the index 980 var dropped_id: [evt.event_id_size]u8 = undefined; 981 _ = try std.fmt.hexToBytes(&dropped_id, &events_to_consume2[0].id); 982 const dropped = try readIssue(Repo.DB, repo_opts.hash, haxy_moment, &arena, &dropped_id); 983 try std.testing.expect(dropped.removed); 984 985 const tag_to_issues_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, "tag+status->issue-id-set")) orelse return error.NotFound; 986 const tag_to_issues = try Repo.DB.SortedMap(.read_only).init(tag_to_issues_cursor); 987 try std.testing.expect(null == try tag_to_issues.getCursor("kanban open")); 988 989 // the one we edited survives, with our edit 990 var kept_id: [evt.event_id_size]u8 = undefined; 991 _ = try std.fmt.hexToBytes(&kept_id, &events_to_consume2[1].id); 992 const kept = try readIssue(Repo.DB, repo_opts.hash, haxy_moment, &arena, &kept_id); 993 try std.testing.expect(!kept.removed); 994 try std.testing.expectEqualStrings("Kept by the edit", kept.event.title); 995 } 996 } 997 998 // the commit that last set `field_name` on the issue `id` names 999 fn readOid( 1000 comptime DB: type, 1001 comptime hash_kind: hash.HashKind, 1002 haxy_moment: DB.HashMap(.read_only), 1003 id: *const [evt.event_id_size]u8, 1004 comptime field_name: []const u8, 1005 ) ![hash.byteLen(hash_kind)]u8 { 1006 const id_to_field_to_oid_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, evt.Issue.id_to_field_to_oid_key)) orelse return error.NotFound; 1007 const id_to_field_to_oid = try DB.HashMap(.read_only).init(id_to_field_to_oid_cursor); 1008 const field_oids_cursor = try id_to_field_to_oid.getCursor(hash.hashInt(hash_kind, id)) orelse return error.NotFound; 1009 const field_oids = try DB.SortedMap(.read_only).init(field_oids_cursor); 1010 const cursor = try field_oids.getCursor(field_name) orelse return error.NotFound; 1011 var oid: [hash.byteLen(hash_kind)]u8 = undefined; 1012 _ = try cursor.readBytes(&oid); 1013 return oid; 1014 } 1015 1016 // the issue `id` names, read out of `event-id->issue` 1017 fn readIssue( 1018 comptime DB: type, 1019 comptime hash_kind: hash.HashKind, 1020 haxy_moment: DB.HashMap(.read_only), 1021 arena: *std.heap.ArenaAllocator, 1022 id: *const [evt.event_id_size]u8, 1023 ) !evt.Issue.Record { 1024 const event_id_to_issue_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, "event-id->issue")) orelse return error.NotFound; 1025 const event_id_to_issue = try DB.HashMap(.read_only).init(event_id_to_issue_cursor); 1026 const issue_cursor = try event_id_to_issue.getCursor(hash.hashInt(hash_kind, id)) orelse return error.NotFound; 1027 const issue_map = try DB.HashMap(.read_only).init(issue_cursor); 1028 return try evt.read(evt.Issue.Record, DB, hash_kind, arena, issue_map); 1029 } 1030