╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Patches.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
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 try header.addTab(allocator, status_label, try thread.countLabel(session, data.window(status).*), link, index); 1009 } 1010 1011 // labels tab 1012 { 1013 const labels_route = try thread.searchRoute(ui.RoutablePage.repoThreadLabelsRoute(.patch, data.identity), data.search); 1014 const labels_link = try ui.inPageTabLink(session, labels_route, page_selected and selected_index == View.viewIndex(.labels)); 1015 try header.addTab(allocator, labels_tab_label, "", labels_link, View.viewIndex(.labels)); 1016 } 1017 1018 // new-patch tab; an edit or resolve url shows its tab in this place 1019 { 1020 const route = switch (data.view) { 1021 .edit => ui.RoutablePage.repoThreadEditRoute(.patch, data.identity, data.selected_id) orelse return error.RouteTooLong, 1022 .publish => ui.RoutablePage.repoPatchPublishRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 1023 .merge => ui.RoutablePage.repoPatchMergeRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 1024 .new_comment => ui.RoutablePage.repoThreadCommentNewRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1025 .edit_comment => ui.RoutablePage.repoThreadCommentEditRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1026 .remove => ui.RoutablePage.repoThreadRemoveRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1027 .resolve => ui.RoutablePage.repoPatchesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 1028 else => ui.RoutablePage.repoThreadNewRoute(.patch, data.identity) orelse return error.RouteTooLong, 1029 }; 1030 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.new)); 1031 const label: []const u8 = switch (data.view) { 1032 .edit => edit_tab_label, 1033 .publish => publish_tab_label, 1034 .merge => merge_tab_label, 1035 .new_comment => reply_tab_label, 1036 .edit_comment => edit_tab_label, 1037 .remove => remove_tab_label, 1038 .resolve => resolve_tab_label, 1039 else => new_tab_label, 1040 }; 1041 try header.addTab(allocator, label, "", link, View.viewIndex(.new)); 1042 } 1043 1044 // drafts belong to the logged-in user and are not available locally 1045 if (session.data.host_kind != .local) { 1046 const route = ui.RoutablePage.repoPatchesDraftsRoute(data.identity) orelse return error.RouteTooLong; 1047 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.drafts)); 1048 try header.addTab(allocator, drafts_tab_label, try session.page_arena.allocator().print("({d})", .{data.drafts.count}), link, View.viewIndex(.drafts)); 1049 } 1050 1051 // conflicts tab, labeled with the conflict count 1052 if (data.conflicts.count > 0) { 1053 const route = ui.RoutablePage.repoPatchesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 1054 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.conflicts)); 1055 try header.addTab(allocator, conflicts_tab_label, try session.page_arena.allocator().print("({d})", .{data.conflicts.count}), link, View.viewIndex(.conflicts)); 1056 } 1057 1058 header.select(View.viewIndex(data.view)); 1059 return header; 1060 } 1061