╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ patch.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
687 var draft = try Repo.open(io, allocator, .{ .path = draft_path }); 688 defer draft.deinit(io, allocator); 689 _ = arena.reset(.retain_capacity); 690 const draft_moment = try evt.currentMoment(repo_opts, &draft); 691 const removed = (try evt.Patch.readById(Repo.DB, repo_opts.hash, draft_moment, &arena, &patch_id)) orelse return error.NotFound; 692 try std.testing.expect(removed.removed); 693 const revision = (try evt.PatchRev.readById(Repo.DB, repo_opts.hash, draft_moment, &arena, &first_patchrev_id)) orelse return error.NotFound; 694 @memcpy(&squash_oid, revision.patch_oid); 695 try std.testing.expectEqualStrings("refs/heads/master", revision.event.target_ref); 696 try std.testing.expectEqual(hash.hexLen(repo_opts.hash), revision.event_oid.len); 697 var event_oid: [hash.hexLen(repo_opts.hash)]u8 = undefined; 698 @memcpy(&event_oid, revision.event_oid); 699 var repo_moment = try draft.core.latestMoment(); 700 const state = Repo.State(.read_only){ .core = &draft.core, .extra = .{ .moment = &repo_moment } }; 701 var event_object = try obj.Object(.xit, repo_opts).initCommit(state, io, allocator, &event_oid); 702 defer event_object.deinit(); 703 const trees = try evt.PatchRev.readTrees(.xit, repo_opts, state, io, allocator, &event_object.content.commit.tree); 704 try std.testing.expectEqualStrings(revision.base_tree_oid, &trees.base); 705 try std.testing.expectEqualStrings(revision.head_tree_oid, &trees.head); 706 } 707 708 // 709 // merge the selected revision into the target 710 // 711 712 const selected_oid = switch (merge_revision) { 713 .squash => squash_oid, 714 .source => source_oid, 715 }; 716 try pch.merge(repo_opts, io, allocator, repos_dir, &target, .{ 717 .id = patch_id_hex, 718 .revision = merge_revision, 719 .author = author, 720 .timestamp = 5, 721 }); 722 const target_oid = (try target.readRef(io, .{ .kind = .head, .name = "master" })) orelse return error.NotFound; 723 try std.testing.expectEqualStrings(&selected_oid, &target_oid); 724 725 _ = arena.reset(.retain_capacity); 726 const merged_moment = try evt.currentMoment(repo_opts, &target); 727 const merged = (try evt.Patch.readById(Repo.DB, repo_opts.hash, merged_moment, &arena, &patch_id)) orelse return error.NotFound; 728 try std.testing.expectEqual(.merged, merged.event.status); 729 try std.testing.expect(null != try evt.PatchRev.readById(Repo.DB, repo_opts.hash, merged_moment, &arena, &first_patchrev_id)); 730 } 731 732 fn indexedForkCount( 733 moment: evt.AdminDB.HashMap(.read_only), 734 index_key: []const u8, 735 parent_id: []const u8, 736 ) !u64 { 737 const index_cursor = try moment.getCursor(hash.hashInt(evt.admin_repo_opts.hash, index_key)) orelse return 0; 738 const index = try evt.AdminDB.HashMap(.read_only).init(index_cursor); 739 const ids_cursor = try index.getCursor(hash.hashInt(evt.admin_repo_opts.hash, parent_id)) orelse return 0; 740 const ids = try evt.AdminDB.SortedSet(.read_only).init(ids_cursor); 741 return try ids.count(); 742 } 743 744 fn patchStatusCount(moment: Repo.DB.HashMap(.read_only), status: evt.Patch.Status) !u64 { 745 const statuses_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, evt.Patch.status_to_id_set_key)) orelse return 0; 746 const statuses = try Repo.DB.SortedMap(.read_only).init(statuses_cursor); 747 const ids_cursor = try statuses.getCursor(@tagName(status)) orelse return 0; 748 const ids = try Repo.DB.SortedSet(.read_only).init(ids_cursor); 749 return try ids.count(); 750 } 751 752 fn patchTagStatusCount(moment: Repo.DB.HashMap(.read_only), tag: []const u8, status: evt.Patch.Status) !u64 { 753 const tags_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, evt.Patch.tag_status_to_id_set_key)) orelse return 0; 754 const tags = try Repo.DB.SortedMap(.read_only).init(tags_cursor); 755 var key_buffer: evt.Patch.TagStatusKey = undefined; 756 const ids_cursor = try tags.getCursor(try evt.Patch.tagStatusKey(&key_buffer, tag, status)) orelse return 0; 757 const ids = try Repo.DB.SortedSet(.read_only).init(ids_cursor); 758 return try ids.count(); 759 } 760