╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ patch.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
765 // merge the selected revision into the target 766 // 767 768 try evt.Patch.update(.xit, repo_opts, io, allocator, &target, &patch_id, .{ .status = .closed }, author); 769 try std.testing.expectError(error.PatchClosed, pch.merge(repo_opts, io, allocator, repos_dir, &target, .{ 770 .id = patch_id_hex, 771 .revision = merge_revision, 772 .author = author, 773 .timestamp = 5, 774 })); 775 try evt.Patch.update(.xit, repo_opts, io, allocator, &target, &patch_id, .{ .status = .open }, author); 776 777 const selected_oid = switch (merge_revision) { 778 .squash => squash_oid, 779 .source => source_oid, 780 }; 781 try pch.mergeAndRemoveFork(repo_opts, io, allocator, repos_dir, &admin, &target, .{ 782 .id = patch_id_hex, 783 .revision = merge_revision, 784 .author = author, 785 .timestamp = 5, 786 }); 787 const target_oid = (try target.readRef(io, .{ .kind = .head, .name = "master" })) orelse return error.NotFound; 788 try std.testing.expectEqualStrings(&selected_oid, &target_oid); 789 790 _ = arena.reset(.retain_capacity); 791 const merged_moment = try evt.currentMoment(repo_opts, &target); 792 const merged = (try evt.Patch.readById(Repo.DB, repo_opts.hash, merged_moment, &arena, &patch_id)) orelse return error.NotFound; 793 try std.testing.expectEqual(.merged, merged.event.status.kind()); 794 const merged_oid = switch (merged.event.status) { 795 .merged => |oid| oid, 796 else => return error.InvalidPatch, 797 }; 798 try std.testing.expectEqualStrings(&selected_oid, merged_oid); 799 try std.testing.expect(null != try evt.PatchRev.readById(Repo.DB, repo_opts.hash, merged_moment, &arena, &first_patchrev_id)); 800 801 _ = arena.reset(.retain_capacity); 802 const removed_fork = (try evt.Fork.readById(evt.AdminDB, evt.admin_repo_opts.hash, try evt.currentMoment(evt.admin_repo_opts, &admin), &arena, &patch_id)) orelse return error.NotFound; 803 try std.testing.expect(removed_fork.removed); 804 } 805 806 fn indexedForkCount( 807 moment: evt.AdminDB.HashMap(.read_only), 808 index_key: []const u8, 809 parent_id: []const u8, 810 ) !u64 { 811 const index_cursor = try moment.getCursor(hash.hashInt(evt.admin_repo_opts.hash, index_key)) orelse return 0; 812 const index = try evt.AdminDB.HashMap(.read_only).init(index_cursor); 813 const ids_cursor = try index.getCursor(hash.hashInt(evt.admin_repo_opts.hash, parent_id)) orelse return 0; 814 const ids = try evt.AdminDB.SortedSet(.read_only).init(ids_cursor); 815 return try ids.count(); 816 } 817 818 fn patchStatusCount(moment: Repo.DB.HashMap(.read_only), status: evt.Patch.StatusKind) !u64 { 819 const statuses_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, evt.Patch.status_to_id_set_key)) orelse return 0; 820 const statuses = try Repo.DB.SortedMap(.read_only).init(statuses_cursor); 821 const ids_cursor = try statuses.getCursor(@tagName(status)) orelse return 0; 822 const ids = try Repo.DB.SortedSet(.read_only).init(ids_cursor); 823 return try ids.count(); 824 } 825 826 fn patchTagStatusCount(moment: Repo.DB.HashMap(.read_only), tag: []const u8, status: evt.Patch.StatusKind) !u64 { 827 const tags_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, evt.Patch.tag_status_to_id_set_key)) orelse return 0; 828 const tags = try Repo.DB.SortedMap(.read_only).init(tags_cursor); 829 var key_buffer: evt.Patch.TagStatusKey = undefined; 830 const ids_cursor = try tags.getCursor(try evt.Patch.tagStatusKey(&key_buffer, tag, status)) orelse return 0; 831 const ids = try Repo.DB.SortedSet(.read_only).init(ids_cursor); 832 return try ids.count(); 833 } 834