╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Patches.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
942 const clone_command = if (clone_name.len == 0) 943 try std.fmt.allocPrint(aa, "git clone {s}", .{url}) 944 else 945 try std.fmt.allocPrint(aa, "git clone {s} {s}", .{ url, clone_name }); 946 const merge_command = try std.fmt.allocPrint(aa, "git fetch '{s}' refs/heads/patch && git merge FETCH_HEAD", .{url}); 947 const choices: [3]ui.widget.CopyableText.Choice = .{ 948 .{ 949 .selector = "push", 950 .text = push_command, 951 .copyable_text = try std.fmt.allocPrint(aa, "{s}{s}", .{ session.data.git_ssh_prefix, push_command }), 952 .label = " push to this patch from existing repo ", 953 }, 954 .{ 955 .selector = "clone", 956 .text = clone_command, 957 .copyable_text = try std.fmt.allocPrint(aa, "{s}{s}", .{ session.data.git_ssh_prefix, clone_command }), 958 .label = " clone this patch ", 959 }, 960 .{ 961 .selector = "merge", 962 .text = merge_command, 963 .copyable_text = try std.fmt.allocPrint(aa, "{s}{s}", .{ session.data.git_ssh_prefix, merge_command }), 964 .label = " merge this patch locally ", 965 }, 966 }; 967 var copyable_text = try ui.widget.CopyableText.init(allocator, session, &choices); 968 errdefer copyable_text.deinit(allocator); 969 try box.children.put(allocator, copyable_text.getFocus().id, .{ .widget = .{ .copyable_text = copyable_text }, .rect = null, .min_size = null }); 970 }; 971 if (entry.record.event.source_branch) |branch| { 972 var source = try wgt.TextBox.init(allocator, branch, .{ .label = " source branch ", .border_style = .single, .round_corners = true, .wrap_kind = .none }); 973 errdefer source.deinit(allocator); 974 source.getFocus().mode = .all; 975 try box.children.put(allocator, source.getFocus().id, .{ .widget = .{ .text_box = source }, .rect = null, .min_size = null }); 976 } 977 const fields = [_]ui.widget.CopyableText.Choice{ 978 .{ 979 .selector = "from", 980 .text = entry.revision_oid, 981 .label = if (entry.no_changes) " object id of this patch (no changes) " else " object id of this patch ", 982 }, 983 .{ 984 .selector = "to", 985 .text = target_branch, 986 .label = if (status_kind == .merged) " target branch this patch was merged into " else " target branch this patch will go to ", 987 }, 988 }; 989 var copyable_text = try ui.widget.CopyableText.init(allocator, session, fields[@intFromBool(entry.revision_oid.len == 0)..]); 990 errdefer copyable_text.deinit(allocator); 991 try box.children.put(allocator, copyable_text.getFocus().id, .{ .widget = .{ .copyable_text = copyable_text }, .rect = null, .min_size = null }); 992 } 993 994 fn cloneDirectoryName(allocator: std.mem.Allocator, title: []const u8) ![]const u8 { 995 var name: [64]u8 = undefined; 996 var len: usize = 0; 997 var pending: ?u8 = null; 998 999 for (title) |char| { 1000 if (std.ascii.isAlphanumeric(char)) { 1001 const needed: usize = if (pending == null) 1 else 2; 1002 if (len + needed > name.len) break; 1003 if (pending) |value| { 1004 name[len] = value; 1005 len += 1; 1006 } 1007 name[len] = std.ascii.toLower(char); 1008 len += 1; 1009 pending = null; 1010 } else if (char == ' ') { 1011 if (len != 0) pending = '-'; 1012 } else if (char == '.') { 1013 if (len != 0 and pending != '-') pending = '.'; 1014 } 1015 } 1016 if (len == 0) return ""; 1017 return allocator.dupe(u8, name[0..len]); 1018 } 1019 1020 // tabs switching between the patches page's views 1021 pub fn initHeader(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 1022 var header = try Header.init(allocator, session, data.search); 1023 errdefer header.deinit(allocator); 1024 const aa = session.page_arena.allocator(); 1025 const selected_index = View.viewIndex(data.view); 1026 const page_selected = std.meta.activeTag(session.data.current_page) == .repo_patches; 1027 1028 // a list tab per status, labeled with its listing's patch count 1029 const status_labels = [_][]const u8{ open_tab_label, closed_tab_label, merged_tab_label }; 1030 for ([_]Status{ .open, .closed, .merged }, status_labels, 0..) |status, status_label, index| { 1031 const route = try thread.searchRoute(ui.RoutablePage.repoPatchesRoute(data.identity, status, data.label, ""), data.search); 1032 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == index); 1033 var label_buf: [64]u8 = undefined; 1034 const label = try thread.countLabel(&label_buf, status_label, data.window(status).*); 1035 try header.addTab(allocator, label, link, index); 1036 } 1037 1038 // labels tab, showing the active label filter 1039 { 1040 const labels_route = try thread.searchRoute(ui.RoutablePage.repoThreadLabelsRoute(.patch, data.identity, data.label), data.search); 1041 const labels_link = try ui.inPageTabLink(session, labels_route, page_selected and selected_index == View.viewIndex(.labels)); 1042 const label = if (data.label.len == 0) labels_tab_label else blk: { 1043 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.label)); 1044 break :blk try std.fmt.allocPrint(aa, labels_tab_label ++ " ({s})", .{decoded}); 1045 }; 1046 try header.addTab(allocator, label, labels_link, View.viewIndex(.labels)); 1047 } 1048 1049 // new-patch tab; an edit or resolve url shows its tab in this place 1050 { 1051 const route = switch (data.view) { 1052 .edit => ui.RoutablePage.repoThreadEditRoute(.patch, data.identity, data.selected_id) orelse return error.RouteTooLong, 1053 .publish => ui.RoutablePage.repoPatchPublishRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 1054 .merge => ui.RoutablePage.repoPatchMergeRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 1055 .new_comment => ui.RoutablePage.repoThreadCommentNewRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1056 .edit_comment => ui.RoutablePage.repoThreadCommentEditRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1057 .remove => ui.RoutablePage.repoThreadRemoveRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1058 .resolve => ui.RoutablePage.repoPatchesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 1059 else => ui.RoutablePage.repoThreadNewRoute(.patch, data.identity) orelse return error.RouteTooLong, 1060 }; 1061 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.new)); 1062 const label: []const u8 = switch (data.view) { 1063 .edit => edit_tab_label, 1064 .publish => publish_tab_label, 1065 .merge => merge_tab_label, 1066 .new_comment => reply_tab_label, 1067 .edit_comment => edit_tab_label, 1068 .remove => remove_tab_label, 1069 .resolve => resolve_tab_label, 1070 else => new_tab_label, 1071 }; 1072 try header.addTab(allocator, label, link, View.viewIndex(.new)); 1073 } 1074 1075 // drafts belong to the logged-in user and are not available locally 1076 if (session.data.host_kind != .local) { 1077 const route = ui.RoutablePage.repoPatchesDraftsRoute(data.identity) orelse return error.RouteTooLong; 1078 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.drafts)); 1079 var label_buf: [64]u8 = undefined; 1080 const label = try std.fmt.bufPrint(&label_buf, drafts_tab_label ++ " ({d})", .{data.drafts.count}); 1081 try header.addTab(allocator, label, link, View.viewIndex(.drafts)); 1082 } 1083 1084 // conflicts tab, labeled with the conflict count 1085 if (data.conflicts.count > 0) { 1086 const route = ui.RoutablePage.repoPatchesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 1087 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.conflicts)); 1088 var label_buf: [64]u8 = undefined; 1089 const label = try std.fmt.bufPrint(&label_buf, conflicts_tab_label ++ " ({d})", .{data.conflicts.count}); 1090 try header.addTab(allocator, label, link, View.viewIndex(.conflicts)); 1091 } 1092 1093 header.select(View.viewIndex(data.view)); 1094 return header; 1095 } 1096