╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Patches.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
640 }; 641 const event_id_to_patch = try DB.HashMap(.read_only).init(event_id_to_patch_cursor); 642 643 // the conflicted patches' container: a set view for membership and 644 // windowing, a map view for the resolve entry, over the same cursor. 645 var conflict_set: ?DB.SortedSet(.read_only) = null; 646 var conflicts_map: ?DB.SortedMap(.read_only) = null; 647 if (try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Patch.conflicts_key))) |cursor| { 648 conflict_set = try DB.SortedSet(.read_only).init(cursor); 649 conflicts_map = try DB.SortedMap(.read_only).init(cursor); 650 } 651 652 // a named patch roots its own status's window at itself (the conflicts 653 // view's window instead); the other windows start at the beginning. 654 var resolved_view = empty.view; 655 var open_root: ?[]const u8 = null; 656 var closed_root: ?[]const u8 = null; 657 var merged_root: ?[]const u8 = null; 658 var conflicts_root: ?[]const u8 = null; 659 var conflict_data: ?Conflict = null; 660 if (rooted and !draft_selected) { 661 const id_bytes = evt.parseEventId(empty.selected_id) catch return error.NotFound; 662 const patch_cursor = try event_id_to_patch.getCursor(hash.hashInt(repo_opts.hash, &id_bytes)) orelse return error.NotFound; 663 const patch_map = try DB.HashMap(.read_only).init(patch_cursor); 664 const patch_event = try evt.read(evt.Patch.Record, DB, repo_opts.hash, arena, patch_map); 665 const order_key = try aa.dupe(u8, &evt.orderKeyDesc(patch_event.created_order, &id_bytes)); 666 667 if (view == .conflicts) { 668 // the id roots the conflicts window, so it must be conflicted 669 const set = conflict_set orelse return error.NotFound; 670 if (!try set.contains(order_key)) return error.NotFound; 671 conflicts_root = order_key; 672 } else { 673 // the named patch must be in its windowed set (a tag url can name 674 // an patch that doesn't carry the tag). 675 const set = (switch (patch_event.event.status) { 676 .open => open_set, 677 .closed => closed_set, 678 .merged => merged_set, 679 }) orelse return error.NotFound; 680 if (!try set.contains(order_key)) return error.NotFound; 681 682 switch (patch_event.event.status) { 683 .open => open_root = order_key, 684 .closed => closed_root = order_key, 685 .merged => merged_root = order_key, 686 } 687 // form urls keep their view; otherwise the patch's status picks it. 688 if (view != .edit and view != .merge and view != .new_comment and view != .edit_comment and view != .remove) resolved_view = switch (patch_event.event.status) { 689 .open => .open, 690 .closed => .closed, 691 .merged => .merged, 692 }; 693 694 // a resolve url shows the resolve view only while the patch still 695 // has a conflict entry; otherwise the status list stands. the 696 // wasm client renders from the snapshot, so the diff machinery 697 // this pulls in is gated out of its build. 698 if (comptime !wasm) { 699 if (view == .resolve) { 700 if (conflicts_map) |map| { 701 if (try map.getCursor(order_key)) |conflict_cursor| { 702 const conflict_entry = try DB.HashMap(.read_only).init(conflict_cursor); 703 conflict_data = try thread.readConflict(Self, repo_kind, repo_opts, arena, repo, io, admin_moment, haxy_moment, &id_bytes, patch_event, conflict_entry); 704 resolved_view = .resolve; 705 } 706 } 707 } 708 } 709 } 710 } 711 const thread_comments_start = if (empty.comment_id.len == 0) comments_start else 0; 712 var open_window = try thread.loadWindow(Self, .patch, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_patch, open_set, open_root, conflict_set, empty.selected_id, thread_comments_start, empty.search); 713 var closed_window = try thread.loadWindow(Self, .patch, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_patch, closed_set, closed_root, conflict_set, empty.selected_id, thread_comments_start, empty.search); 714 var merged_window = try thread.loadWindow(Self, .patch, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_patch, merged_set, merged_root, conflict_set, empty.selected_id, thread_comments_start, empty.search); 715 var conflicts_window = try thread.loadWindow(Self, .patch, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_patch, conflict_set, conflicts_root, conflict_set, empty.selected_id, thread_comments_start, null); 716 try setPatchDetails(repo_kind, repo_opts, io, arena, admin_moment, haxy_moment, repo, &open_window); 717 try setPatchDetails(repo_kind, repo_opts, io, arena, admin_moment, haxy_moment, repo, &closed_window); 718 try setPatchDetails(repo_kind, repo_opts, io, arena, admin_moment, haxy_moment, repo, &merged_window); 719 try setPatchDetails(repo_kind, repo_opts, io, arena, admin_moment, haxy_moment, repo, &conflicts_window); 720 if (view == .conflicts and conflicts_window.count > 0) resolved_view = .conflicts; 721 722 const comment_page = if (empty.comment_id.len == 0) 723 null 724 else 725 try Comment.init(repo_opts.hash, arena, admin_moment, haxy_moment, empty.selected_id, empty.comment_id, comments_start); 726 727 const tags = try thread.loadTags(Self, repo_opts.hash, arena, haxy_moment); 728 729 return .{ 730 .identity = empty.identity, 731 .default_target_branch = empty.default_target_branch, 732 .tag = empty.tag, 733 .search = empty.search, 734 .selected_id = empty.selected_id, 735 .comment_id = empty.comment_id, 736 .comments_start = comments_start, 737 .comment_page = comment_page, 738 .open = open_window, 739 .closed = closed_window, 740 .merged = merged_window, 741 .drafts = drafts_window, 742 .conflicts = conflicts_window, 743 .conflict = conflict_data, 744 .theirs_picks = empty.theirs_picks, 745 .view = resolved_view, 746 .description_page = empty.description_page, 747 .tags = tags, 748 }; 749 } 750 751 fn setPatchDetails( 752 comptime repo_kind: rp.RepoKind, 753 comptime repo_opts: rp.RepoOpts(repo_kind), 754 io: std.Io, 755 arena: *std.heap.ArenaAllocator, 756 admin_moment: ?evt.AdminDB.HashMap(.read_only), 757 haxy_moment: evt.EventDB(repo_opts.hash).HashMap(.read_only), 758 repo: *rp.Repo(repo_kind, repo_opts), 759 target: *Window, 760 ) !void { 761 if (target.items.len == 0) return; 762 const items = try arena.allocator().dupe(PatchWithId, target.items); 763 for (items) |*item| { 764 const id = try evt.parseEventId(item.id); 765 const status = item.record.event.status.kind(); 766 if (admin_moment) |moment| { 767 const record = try evt.Fork.readById(evt.AdminDB, evt.admin_repo_opts.hash, moment, arena, &id); 768 item.fork_exists = if (record) |value| !value.removed else false; 769 } 770 const target_branch = item.record.event.target_branch; 771 const revision = item.record.event.revision orelse continue; 772 item.commit_count = revision.commit_count; 773 const merge_revision: evt.Patch.MergeRevision = switch (item.record.event.status) { 774 .merged => |merged| merged.revision, 775 else => .source, 776 }; 777 item.revision_oid = switch (merge_revision) { 778 .source => revision.source_oid, 779 .squash => revision.squash_oid, 780 }; 781 if (!item.fork_exists or status == .merged) { 782 const revision_id = try evt.parseEventId(&revision.id); 783 if (try evt.PatchRev.readById(evt.EventDB(repo_opts.hash), repo_opts.hash, haxy_moment, arena, &revision_id)) |record| { 784 item.base_oid = record.event.base_oid; 785 } 786 } 787 if (status == .merged) { 788 if (merge_revision == .squash) item.commit_count = 1; 789 continue; 790 } 791 if (comptime repo_kind == .xit) { 792 var moment = try repo.core.latestMoment(); 793 const state = rp.Repo(.xit, repo_opts).State(.read_only){ .core = &repo.core, .extra = .{ .moment = &moment } }; 794 item.mergeability = pch.readMergeability(repo_opts, state, io, arena, &id, item.record.event) catch .{}; 795 } 796 const target_oid = try repo.readRef(io, .{ .kind = .head, .name = target_branch }); 797 item.no_changes = if (target_oid) |oid| std.mem.eql(u8, &oid, revision.source_oid) else false; 798 } 799 target.items = items; 800 } 801 802 fn loadDraftWindow( 803 comptime repo_kind: rp.RepoKind, 804 comptime repo_opts: rp.RepoOpts(repo_kind), 805 arena: *std.heap.ArenaAllocator, 806 session: *ui.Session, 807 admin_moment: evt.AdminDB.HashMap(.read_only), 808 repo_id: *const [evt.event_id_size]u8, 809 selected_id: []const u8, 810 target_repo: *rp.Repo(repo_kind, repo_opts), 811 ) !Window { 812 const user_id = session.data.user_id orelse return .empty; 813 if (user_id.len != evt.event_id_size) return .empty; 814 const repos_dir = session.repos_dir orelse return .empty; 815 const io = session.io orelse return .empty; 816 const key = evt.Fork.draftKey(repo_id, user_id); 817 const drafts_cursor = try admin_moment.getCursor(hash.hashInt(evt.admin_repo_opts.hash, evt.Fork.repo_user_to_draft_id_set_key)) orelse return .empty; 818 const drafts = try evt.AdminDB.HashMap(.read_only).init(drafts_cursor); 819 const set_cursor = try drafts.getCursor(hash.hashInt(evt.admin_repo_opts.hash, &key)) orelse return .empty; 820 const set = try evt.AdminDB.SortedSet(.read_only).init(set_cursor); 821 const aa = arena.allocator(); 822 823 var root_key: ?[]const u8 = null; 824 if (selected_id.len != 0) { 825 const id = evt.parseEventId(selected_id) catch return error.NotFound; 826 if (try evt.Fork.readById(evt.AdminDB, evt.admin_repo_opts.hash, admin_moment, arena, &id)) |record| { 827 if (!record.removed and record.event.stage == .draft) { 828 const order_key = try aa.dupe(u8, &evt.orderKeyDesc(record.created_order, &id)); 829 if (!try set.contains(order_key)) return error.NotFound; 830 root_key = order_key; 831 } 832 } 833 } 834 835 var prev_id: ?[]const u8 = null; 836 var iter = if (root_key) |root| blk: { 837 const rank = try set.rank(root); 838 if (rank > 0 and rank <= page_size) { 839 prev_id = ""; 840 } else if (rank > page_size) { 841 const pair = try set.getIndexKeyValuePair(@intCast(rank - page_size)) orelse return error.NotFound; 842 var previous: [@sizeOf(u64) + evt.event_id_size]u8 = undefined; 843 _ = try pair.key_cursor.readBytes(&previous); 844 const hex = std.fmt.bytesToHex(previous[@sizeOf(u64)..].*, .lower); 845 prev_id = try aa.dupe(u8, &hex); 846 } 847 break :blk try set.iteratorFrom(root); 848 } else try set.iteratorFromIndex(0); 849 850 var items: std.ArrayList(PatchWithId) = .empty; 851 var next_id: ?[]const u8 = null; 852 while (try iter.next()) |cursor| { 853 const id = try evt.readOrderKeyId(evt.AdminDB, cursor); 854 const id_hex = std.fmt.bytesToHex(id, .lower); 855 if (items.items.len == page_size) { 856 next_id = try aa.dupe(u8, &id_hex); 857 break; 858 } 859 const path = try fork.forkPath(aa, repos_dir, &id_hex); 860 var fork_repo = rp.Repo(.xit, .{}).open(io, arena.child_allocator, .{ .path = path, .require_repo_root = true }) catch continue; 861 defer fork_repo.deinit(io, arena.child_allocator); 862 const entry = (try loadDraftEntry(repo_kind, repo_opts, arena, io, admin_moment, &fork_repo, target_repo, id)) orelse continue; 863 try items.append(aa, entry); 864 } 865 return .{ 866 .items = items.items, 867 .prev_id = prev_id, 868 .next_id = next_id, 869 .count = @intCast(try set.count()), 870 }; 871 } 872 873 pub fn loadDraftEntry( 874 comptime repo_kind: rp.RepoKind, 875 comptime repo_opts: rp.RepoOpts(repo_kind), 876 arena: *std.heap.ArenaAllocator, 877 io: std.Io, 878 admin_moment: ?evt.AdminDB.HashMap(.read_only), 879 fork_repo: *rp.Repo(.xit, .{}), 880 target_repo: *rp.Repo(repo_kind, repo_opts), 881 id: [evt.event_id_size]u8, 882 ) !?PatchWithId { 883 const aa = arena.allocator(); 884 const id_hex = std.fmt.bytesToHex(id, .lower); 885 const fork_oid = (try fork_repo.readRef(io, fork.ref)) orelse return null; 886 const moment = evt.currentMoment(.{}, fork_repo) catch return null; 887 const patch = (try evt.Patch.readById(evt.EventDB(.sha1), .sha1, moment, arena, &id)) orelse return null; 888 const target_branch = patch.event.target_branch; 889 const target_oid = try target_repo.readRef(io, .{ .kind = .head, .name = target_branch }); 890 const commit_count: ?u64 = blk: { 891 const newest = evt.PatchRev.readNewest(evt.EventDB(.sha1), .sha1, moment, arena) catch break :blk null; 892 break :blk if (newest) |revision| revision.record.commit_count else 0; 893 }; 894 return .{ 895 .id = try aa.dupe(u8, &id_hex), 896 .record = patch, 897 .author = try ui.Author.initFromEmail(admin_moment, arena, patch.author_email), 898 .draft = true, 899 .revision_oid = try aa.dupe(u8, &fork_oid), 900 .commit_count = commit_count, 901 .no_changes = if (target_oid) |oid| std.mem.eql(u8, &oid, &fork_oid) else false, 902 .fork_exists = true, 903 }; 904 } 905 906 pub const View = thread.View(.patch, Self); 907 pub const Detail = thread.Detail(.patch, Self); 908 pub const detail_widget_name = "repo_patch_detail"; 909 910 pub const Header = thread.Header; 911 912 const open_tab_label = "open"; 913 const closed_tab_label = "closed"; 914 const merged_tab_label = "merged"; 915 const tags_tab_label = "tags"; 916 const edit_tab_label = "edit"; 917 const publish_tab_label = "publish"; 918 const merge_tab_label = "merge"; 919 const reply_tab_label = "reply"; 920 const remove_tab_label = "remove"; 921 const resolve_tab_label = "resolve"; 922 const new_tab_label = "new"; 923 const drafts_tab_label = "drafts"; 924 const conflicts_tab_label = "conflicts"; 925 926 pub fn appendDetails(self: *const Self, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), session: *ui.Session, entry: Entry) !void { 927 const aa = session.page_arena.allocator(); 928 const status_kind = entry.record.event.status.kind(); 929 const target_branch = entry.record.event.target_branch; 930 931 if (status_kind != .merged and entry.fork_exists) if (session.data.git_ssh_port) |port| { 932 const url = try std.fmt.allocPrint(aa, "ssh://localhost:{d}/fork/{s}/patch:{s}", .{ port, self.identity, entry.id }); 933 const push_command = try std.fmt.allocPrint(aa, "git push {s} HEAD:patch", .{url}); 934 const clone_name = try cloneDirectoryName(aa, entry.record.event.title); 935 const clone_command = if (clone_name.len == 0) 936 try std.fmt.allocPrint(aa, "git clone {s}", .{url}) 937 else 938 try std.fmt.allocPrint(aa, "git clone {s} {s}", .{ url, clone_name }); 939 const merge_command = try std.fmt.allocPrint(aa, "git fetch '{s}' refs/heads/patch && git merge FETCH_HEAD", .{url}); 940 const choices: [3]ui.widget.CopyableText.Choice = .{ 941 .{ 942 .selector = "push", 943 .text = push_command, 944 .copyable_text = try std.fmt.allocPrint(aa, "{s}{s}", .{ session.data.git_ssh_prefix, push_command }), 945 .label = " push to this patch from existing repo ", 946 }, 947 .{ 948 .selector = "clone", 949 .text = clone_command, 950 .copyable_text = try std.fmt.allocPrint(aa, "{s}{s}", .{ session.data.git_ssh_prefix, clone_command }), 951 .label = " clone this patch ", 952 }, 953 .{ 954 .selector = "merge", 955 .text = merge_command, 956 .copyable_text = try std.fmt.allocPrint(aa, "{s}{s}", .{ session.data.git_ssh_prefix, merge_command }), 957 .label = " merge this patch locally ", 958 }, 959 }; 960 var copyable_text = try ui.widget.CopyableText.init(allocator, session, &choices); 961 errdefer copyable_text.deinit(allocator); 962 try box.children.put(allocator, copyable_text.getFocus().id, .{ .widget = .{ .copyable_text = copyable_text }, .rect = null, .min_size = null }); 963 }; 964 if (entry.record.event.source_branch) |branch| { 965 var source = try wgt.TextBox.init(allocator, branch, .{ .label = " source branch ", .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 966 errdefer source.deinit(allocator); 967 source.getFocus().mode = .all; 968 try box.children.put(allocator, source.getFocus().id, .{ .widget = .{ .text_box = source }, .rect = null, .min_size = null }); 969 } 970 const fields = [_]ui.widget.CopyableText.Choice{ 971 .{ 972 .selector = "from", 973 .text = entry.revision_oid, 974 .label = if (entry.no_changes) " object id of this patch (no changes) " else " object id of this patch ", 975 }, 976 .{ 977 .selector = "to", 978 .text = target_branch, 979 .label = if (status_kind == .merged) " target branch this patch was merged into " else " target branch this patch will go to ", 980 }, 981 }; 982 var copyable_text = try ui.widget.CopyableText.init(allocator, session, fields[@intFromBool(entry.revision_oid.len == 0)..]); 983 errdefer copyable_text.deinit(allocator); 984 try box.children.put(allocator, copyable_text.getFocus().id, .{ .widget = .{ .copyable_text = copyable_text }, .rect = null, .min_size = null }); 985 } 986 987 fn cloneDirectoryName(allocator: std.mem.Allocator, title: []const u8) ![]const u8 { 988 var name: [64]u8 = undefined; 989 var len: usize = 0; 990 var pending: ?u8 = null; 991 992 for (title) |char| { 993 if (std.ascii.isAlphanumeric(char)) { 994 const needed: usize = if (pending == null) 1 else 2; 995 if (len + needed > name.len) break; 996 if (pending) |value| { 997 name[len] = value; 998 len += 1; 999 } 1000 name[len] = std.ascii.toLower(char); 1001 len += 1; 1002 pending = null; 1003 } else if (char == ' ') { 1004 if (len != 0) pending = '-'; 1005 } else if (char == '.') { 1006 if (len != 0 and pending != '-') pending = '.'; 1007 } 1008 } 1009 if (len == 0) return ""; 1010 return allocator.dupe(u8, name[0..len]); 1011 } 1012 1013 // tabs switching between the patches page's views 1014 pub fn initHeader(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 1015 var header = try Header.init(allocator, session, data.search); 1016 errdefer header.deinit(allocator); 1017 const aa = session.page_arena.allocator(); 1018 const selected_index = View.viewIndex(data.view); 1019 const page_selected = std.meta.activeTag(session.data.current_page) == .repo_patches; 1020 1021 // a list tab per status, labeled with its listing's patch count 1022 const status_labels = [_][]const u8{ open_tab_label, closed_tab_label, merged_tab_label }; 1023 for ([_]Status{ .open, .closed, .merged }, status_labels, 0..) |status, status_label, index| { 1024 const route = try thread.searchRoute(ui.RoutablePage.repoPatchesRoute(data.identity, status, data.tag, ""), data.search); 1025 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == index); 1026 var label_buf: [64]u8 = undefined; 1027 const label = try thread.countLabel(&label_buf, status_label, data.window(status).*); 1028 try header.addTab(allocator, label, link, index); 1029 } 1030 1031 // tags tab, labeled with the active tag filter 1032 { 1033 const tags_route = try thread.searchRoute(ui.RoutablePage.repoThreadTagsRoute(.patch, data.identity, data.tag), data.search); 1034 const tags_link = try ui.inPageTabLink(session, tags_route, page_selected and selected_index == View.viewIndex(.tags)); 1035 const label = if (data.tag.len == 0) tags_tab_label else blk: { 1036 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 1037 break :blk try std.fmt.allocPrint(aa, tags_tab_label ++ " ({s})", .{decoded}); 1038 }; 1039 try header.addTab(allocator, label, tags_link, View.viewIndex(.tags)); 1040 } 1041 1042 // new-patch tab; an edit or resolve url shows its tab in this place 1043 { 1044 const route = switch (data.view) { 1045 .edit => ui.RoutablePage.repoThreadEditRoute(.patch, data.identity, data.selected_id) orelse return error.RouteTooLong, 1046 .publish => ui.RoutablePage.repoPatchPublishRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 1047 .merge => ui.RoutablePage.repoPatchMergeRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 1048 .new_comment => ui.RoutablePage.repoThreadCommentNewRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1049 .edit_comment => ui.RoutablePage.repoThreadCommentEditRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1050 .remove => ui.RoutablePage.repoThreadRemoveRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1051 .resolve => ui.RoutablePage.repoPatchesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 1052 else => ui.RoutablePage.repoThreadNewRoute(.patch, data.identity) orelse return error.RouteTooLong, 1053 }; 1054 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.new)); 1055 const label: []const u8 = switch (data.view) { 1056 .edit => edit_tab_label, 1057 .publish => publish_tab_label, 1058 .merge => merge_tab_label, 1059 .new_comment => reply_tab_label, 1060 .edit_comment => edit_tab_label, 1061 .remove => remove_tab_label, 1062 .resolve => resolve_tab_label, 1063 else => new_tab_label, 1064 }; 1065 try header.addTab(allocator, label, link, View.viewIndex(.new)); 1066 } 1067 1068 // drafts belong to the logged-in user and are not available locally 1069 if (session.data.host_kind != .local) { 1070 const route = ui.RoutablePage.repoPatchesDraftsRoute(data.identity) orelse return error.RouteTooLong; 1071 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.drafts)); 1072 var label_buf: [64]u8 = undefined; 1073 const label = try std.fmt.bufPrint(&label_buf, drafts_tab_label ++ " ({d})", .{data.drafts.count}); 1074 try header.addTab(allocator, label, link, View.viewIndex(.drafts)); 1075 } 1076 1077 // conflicts tab, labeled with the conflict count 1078 if (data.conflicts.count > 0) { 1079 const route = ui.RoutablePage.repoPatchesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 1080 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.conflicts)); 1081 var label_buf: [64]u8 = undefined; 1082 const label = try std.fmt.bufPrint(&label_buf, conflicts_tab_label ++ " ({d})", .{data.conflicts.count}); 1083 try header.addTab(allocator, label, link, View.viewIndex(.conflicts)); 1084 } 1085 1086 header.select(View.viewIndex(data.view)); 1087 return header; 1088 } 1089