╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Patches.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
899 const target_branch = patch.event.target_branch; 900 const target_oid = try target_repo.readRef(io, .{ .kind = .head, .name = target_branch }); 901 const commit_count: ?u64 = blk: { 902 const newest = evt.PatchRev.readNewest(evt.EventDB(repo_opts.hash), repo_opts.hash, moment, arena) catch break :blk null; 903 break :blk if (newest) |revision| revision.record.commit_count else 0; 904 }; 905 return .{ 906 .id = try aa.dupe(u8, &id_hex), 907 .record = patch, 908 .author = try ui.Author.initFromEmail(admin_moment, arena, patch.author_email), 909 .draft = true, 910 .revision_oid = try aa.dupe(u8, &fork_oid), 911 .commit_count = commit_count, 912 .no_changes = if (target_oid) |oid| std.mem.eql(u8, &oid, &fork_oid) else false, 913 .fork_exists = true, 914 .forker = try aa.dupe(u8, forker), 915 }; 916 } 917 918 pub const View = thread.View(.patch, Self); 919 pub const Detail = thread.Detail(.patch, Self); 920 pub const detail_widget_name = "repo_patch_detail"; 921 922 pub const Header = thread.Header; 923 924 const open_tab_label = "open"; 925 const closed_tab_label = "closed"; 926 const merged_tab_label = "merged"; 927 const labels_tab_label = "labels"; 928 const edit_tab_label = "edit"; 929 const publish_tab_label = "publish"; 930 const merge_tab_label = "merge"; 931 const reply_tab_label = "reply"; 932 const remove_tab_label = "remove"; 933 const resolve_tab_label = "resolve"; 934 const new_tab_label = "new"; 935 const drafts_tab_label = "drafts"; 936 const conflicts_tab_label = "conflicts"; 937 938 pub fn appendDetails(self: *const Self, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), session: *ui.Session, entry: Entry) !void { 939 const aa = session.page_arena.allocator(); 940 const status_kind = entry.record.event.status.kind(); 941 const target_branch = entry.record.event.target_branch; 942 943 if (status_kind != .merged and entry.fork_exists) if (session.data.git_ssh_port) |port| { 944 var buffer: [ui.RoutablePage.repo_identity_max_len]u8 = undefined; 945 const url = try aa.print("ssh://localhost:{d}/{s}+{s}", .{ port, try forkIdentity(&buffer, self.identity, entry), entry.id }); 946 const push_command = try aa.print("git push {s} HEAD:patch", .{url}); 947 const clone_command = try aa.print("git clone {s}", .{url}); 948 const merge_command = try aa.print("git fetch '{s}' refs/heads/patch && git merge FETCH_HEAD", .{url}); 949 const choices: [3]ui.widget.CopyableText.Choice = .{ 950 .{ 951 .selector = "push", 952 .text = push_command, 953 .copyable_text = try aa.print("{s}{s}", .{ session.data.git_ssh_prefix, push_command }), 954 .label = " push to this patch from existing repo ", 955 }, 956 .{ 957 .selector = "clone", 958 .text = clone_command, 959 .copyable_text = try aa.print("{s}{s}", .{ session.data.git_ssh_prefix, clone_command }), 960 .label = " clone this patch ", 961 }, 962 .{ 963 .selector = "merge", 964 .text = merge_command, 965 .copyable_text = try aa.print("{s}{s}", .{ session.data.git_ssh_prefix, merge_command }), 966 .label = " merge this patch locally ", 967 }, 968 }; 969 var copyable_text = try ui.widget.CopyableText.init(allocator, session, &choices, 0); 970 errdefer copyable_text.deinit(allocator); 971 try box.children.put(allocator, copyable_text.getFocus().id, .{ .widget = .{ .copyable_text = copyable_text }, .rect = null, .min_size = null }); 972 }; 973 if (entry.record.event.source_branch) |branch| { 974 var source = try wgt.TextBox.init(allocator, branch, .{ .top_label = .{ .text = " source branch " }, .border = .single, .round_corners = true, .wrap_kind = .none }); 975 errdefer source.deinit(allocator); 976 source.getFocus().mode = .all; 977 try box.children.put(allocator, source.getFocus().id, .{ .widget = .{ .text_box = source }, .rect = null, .min_size = null }); 978 } 979 const fields = [_]ui.widget.CopyableText.Choice{ 980 .{ 981 .selector = "from", 982 .text = entry.revision_oid, 983 .label = if (entry.no_changes) " object id of this patch (no changes) " else " object id of this patch ", 984 }, 985 .{ 986 .selector = "to", 987 .text = target_branch, 988 .label = if (status_kind == .merged) " target branch this patch was merged into " else " target branch this patch will go to ", 989 }, 990 }; 991 var copyable_text = try ui.widget.CopyableText.init(allocator, session, fields[@intFromBool(entry.revision_oid.len == 0)..], 0); 992 errdefer copyable_text.deinit(allocator); 993 try box.children.put(allocator, copyable_text.getFocus().id, .{ .widget = .{ .copyable_text = copyable_text }, .rect = null, .min_size = null }); 994 } 995 996 // tabs switching between the patches page's views 997 pub fn initHeader(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 998 var header = try Header.init(allocator, session, data.search, " search "); 999 errdefer header.deinit(allocator); 1000 const selected_index = View.viewIndex(data.view); 1001 const page_selected = std.meta.activeTag(session.data.current_page) == .repo_patches; 1002 1003 // a list tab per status, labeled with its listing's patch count 1004 const status_labels = [_][]const u8{ open_tab_label, closed_tab_label, merged_tab_label }; 1005 for ([_]Status{ .open, .closed, .merged }, status_labels, 0..) |status, status_label, index| { 1006 const route = try thread.searchRoute(ui.RoutablePage.repoPatchesRoute(data.identity, status, ""), data.search); 1007 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == index); 1008 var label_buf: [64]u8 = undefined; 1009 const label = try thread.countLabel(&label_buf, status_label, data.window(status).*); 1010 try header.addTab(allocator, label, link, index); 1011 } 1012 1013 // labels tab 1014 { 1015 const labels_route = try thread.searchRoute(ui.RoutablePage.repoThreadLabelsRoute(.patch, data.identity), data.search); 1016 const labels_link = try ui.inPageTabLink(session, labels_route, page_selected and selected_index == View.viewIndex(.labels)); 1017 try header.addTab(allocator, labels_tab_label, labels_link, View.viewIndex(.labels)); 1018 } 1019 1020 // new-patch tab; an edit or resolve url shows its tab in this place 1021 { 1022 const route = switch (data.view) { 1023 .edit => ui.RoutablePage.repoThreadEditRoute(.patch, data.identity, data.selected_id) orelse return error.RouteTooLong, 1024 .publish => ui.RoutablePage.repoPatchPublishRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 1025 .merge => ui.RoutablePage.repoPatchMergeRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 1026 .new_comment => ui.RoutablePage.repoThreadCommentNewRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1027 .edit_comment => ui.RoutablePage.repoThreadCommentEditRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1028 .remove => ui.RoutablePage.repoThreadRemoveRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1029 .resolve => ui.RoutablePage.repoPatchesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 1030 else => ui.RoutablePage.repoThreadNewRoute(.patch, data.identity) orelse return error.RouteTooLong, 1031 }; 1032 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.new)); 1033 const label: []const u8 = switch (data.view) { 1034 .edit => edit_tab_label, 1035 .publish => publish_tab_label, 1036 .merge => merge_tab_label, 1037 .new_comment => reply_tab_label, 1038 .edit_comment => edit_tab_label, 1039 .remove => remove_tab_label, 1040 .resolve => resolve_tab_label, 1041 else => new_tab_label, 1042 }; 1043 try header.addTab(allocator, label, link, View.viewIndex(.new)); 1044 } 1045 1046 // drafts belong to the logged-in user and are not available locally 1047 if (session.data.host_kind != .local) { 1048 const route = ui.RoutablePage.repoPatchesDraftsRoute(data.identity) orelse return error.RouteTooLong; 1049 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.drafts)); 1050 var label_buf: [64]u8 = undefined; 1051 const label = try std.fmt.bufPrint(&label_buf, drafts_tab_label ++ " ({d})", .{data.drafts.count}); 1052 try header.addTab(allocator, label, link, View.viewIndex(.drafts)); 1053 } 1054 1055 // conflicts tab, labeled with the conflict count 1056 if (data.conflicts.count > 0) { 1057 const route = ui.RoutablePage.repoPatchesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 1058 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.conflicts)); 1059 var label_buf: [64]u8 = undefined; 1060 const label = try std.fmt.bufPrint(&label_buf, conflicts_tab_label ++ " ({d})", .{data.conflicts.count}); 1061 try header.addTab(allocator, label, link, View.viewIndex(.conflicts)); 1062 } 1063 1064 header.select(View.viewIndex(data.view)); 1065 return header; 1066 } 1067