╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
1009 } 1010 { 1011 json.clearRetainingCapacity(); 1012 const event = evt.EventWithId{ .id = events_to_consume2[1].id, .author = author, .event = .{ .issue = null } }; 1013 try std.json.Stringify.value(event, .{}, &json.writer); 1014 _ = try repo.commitAtRef(io, allocator, .{ .message = json.written() }, null, other_events_ref); 1015 } 1016 1017 { 1018 var result = try repo.switchDir(io, allocator, .{ .target = .{ .ref = evt.events_ref } }); 1019 defer result.deinit(); 1020 1021 var merge = try repo.merge(io, allocator, .{ .kind = .full, .action = .{ .new = .{ .source = &.{.{ .ref = other_events_ref }} } } }, null); 1022 defer merge.deinit(); 1023 1024 try std.testing.expect(.success == merge.result); 1025 } 1026 1027 try evt.consume(.local, .repo, .xit, repo_opts, io, allocator, &repo, evt.events_ref, &.{}); 1028 1029 const haxy_moment = try evt.currentMoment(repo_opts, &repo); 1030 1031 // the one we left alone is removed, and its labels left the index 1032 var dropped_id: [evt.event_id_size]u8 = undefined; 1033 _ = try std.fmt.hexToBytes(&dropped_id, &events_to_consume2[0].id); 1034 const dropped = try readIssue(Repo.DB, repo_opts.hash, haxy_moment, &arena, &dropped_id); 1035 try std.testing.expect(dropped.removed); 1036 1037 const label_to_issues_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, "label+status->issue-id-set")) orelse return error.NotFound; 1038 const label_to_issues = try Repo.DB.SortedMap(.read_only).init(label_to_issues_cursor); 1039 try std.testing.expect(null == try label_to_issues.getCursor("kanban open")); 1040 1041 // the one we edited survives, with our edit 1042 var kept_id: [evt.event_id_size]u8 = undefined; 1043 _ = try std.fmt.hexToBytes(&kept_id, &events_to_consume2[1].id); 1044 const kept = try readIssue(Repo.DB, repo_opts.hash, haxy_moment, &arena, &kept_id); 1045 try std.testing.expect(!kept.removed); 1046 try std.testing.expectEqualStrings("Kept by the edit", kept.event.title); 1047 } 1048 } 1049 1050 // the commit that last set `field_name` on the issue `id` names 1051 fn readOid( 1052 comptime DB: type, 1053 comptime hash_kind: hash.HashKind, 1054 haxy_moment: DB.HashMap(.read_only), 1055 id: *const [evt.event_id_size]u8, 1056 comptime field_name: []const u8, 1057 ) ![hash.byteLen(hash_kind)]u8 { 1058 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; 1059 const id_to_field_to_oid = try DB.HashMap(.read_only).init(id_to_field_to_oid_cursor); 1060 const field_oids_cursor = try id_to_field_to_oid.getCursor(hash.hashInt(hash_kind, id)) orelse return error.NotFound; 1061 const field_oids = try DB.SortedMap(.read_only).init(field_oids_cursor); 1062 const cursor = try field_oids.getCursor(field_name) orelse return error.NotFound; 1063 var oid: [hash.byteLen(hash_kind)]u8 = undefined; 1064 _ = try cursor.readBytes(&oid); 1065 return oid; 1066 } 1067 1068 // the issue `id` names, read out of `event-id->issue` 1069 fn readIssue( 1070 comptime DB: type, 1071 comptime hash_kind: hash.HashKind, 1072 haxy_moment: DB.HashMap(.read_only), 1073 arena: *std.heap.ArenaAllocator, 1074 id: *const [evt.event_id_size]u8, 1075 ) !evt.Issue.Record { 1076 const event_id_to_issue_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, "event-id->issue")) orelse return error.NotFound; 1077 const event_id_to_issue = try DB.HashMap(.read_only).init(event_id_to_issue_cursor); 1078 const issue_cursor = try event_id_to_issue.getCursor(hash.hashInt(hash_kind, id)) orelse return error.NotFound; 1079 const issue_map = try DB.HashMap(.read_only).init(issue_cursor); 1080 return try evt.read(evt.Issue.Record, DB, hash_kind, arena, issue_map); 1081 } 1082