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