╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Patches.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
598 errdefer copyable_text.deinit(allocator); 599 try box.children.put(allocator, copyable_text.getFocus().id, .{ .widget = .{ .copyable_text = copyable_text }, .rect = null, .min_size = null }); 600 }; 601 if (entry.fork_oid.len != 0) { 602 fields[field_count] = .{ 603 .selector = "from", 604 .text = entry.fork_oid, 605 .label = if (entry.no_changes) " object id of this patch (no changes) " else " object id of this patch ", 606 }; 607 field_count += 1; 608 } 609 if (entry.target_branch.len != 0) { 610 fields[field_count] = .{ 611 .selector = "to", 612 .text = entry.target_branch, 613 .label = " target branch this patch will go to ", 614 .bottom_label = " (set by the url you push to above) ", 615 }; 616 field_count += 1; 617 } 618 619 if (field_count > 0) { 620 var copyable_text = try ui.widget.CopyableText.init(allocator, session, fields[0..field_count]); 621 errdefer copyable_text.deinit(allocator); 622 try box.children.put(allocator, copyable_text.getFocus().id, .{ .widget = .{ .copyable_text = copyable_text }, .rect = null, .min_size = null }); 623 624 var spacer = try ui.widget.Spacer.init(allocator); 625 errdefer spacer.deinit(allocator); 626 try box.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = .{ .width = null, .height = 1 }, .max_size = .{ .width = null, .height = 1 } }); 627 } 628 } 629 630 fn cloneDirectoryName(allocator: std.mem.Allocator, title: []const u8) ![]const u8 { 631 var name: [64]u8 = undefined; 632 var len: usize = 0; 633 var pending: ?u8 = null; 634 635 for (title) |char| { 636 if (std.ascii.isAlphanumeric(char)) { 637 const needed: usize = if (pending == null) 1 else 2; 638 if (len + needed > name.len) break; 639 if (pending) |value| { 640 name[len] = value; 641 len += 1; 642 } 643 name[len] = std.ascii.toLower(char); 644 len += 1; 645 pending = null; 646 } else if (char == ' ') { 647 if (len != 0) pending = '-'; 648 } else if (char == '.') { 649 if (len != 0 and pending != '-') pending = '.'; 650 } 651 } 652 if (len == 0) return ""; 653 return allocator.dupe(u8, name[0..len]); 654 } 655 656 // tabs switching between the patches page's views 657 pub fn initHeader(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 658 var header = try Header.init(allocator); 659 errdefer header.deinit(allocator); 660 const aa = session.page_arena.allocator(); 661 const selected_index = View.viewIndex(data.view); 662 const page_selected = std.meta.activeTag(session.data.current_page) == .repo_patches; 663 664 // a list tab per status, labeled with its listing's patch count 665 for ([_]evt.Patch.Status{ .open, .closed, .merged }, 0..) |status, index| { 666 const route = ui.RoutablePage.repoPatchesRoute(data.identity, status, data.tag, "") orelse return error.RouteTooLong; 667 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == index); 668 var label_buf: [64]u8 = undefined; 669 const label = try std.fmt.bufPrint(&label_buf, "{s} ({d})", .{ @tagName(status), data.window(status).count }); 670 try header.addTab(allocator, label, link, index); 671 } 672 673 // tags tab, labeled with the active tag filter 674 { 675 const tags_route = ui.RoutablePage.repoThreadTagsRoute(.patch, data.identity, data.tag) orelse return error.RouteTooLong; 676 const tags_link = try ui.inPageTabLink(session, tags_route, page_selected and selected_index == View.viewIndex(.tags)); 677 const label = if (data.tag.len == 0) "tags" else blk: { 678 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 679 break :blk try std.fmt.allocPrint(aa, "tags ({s})", .{decoded}); 680 }; 681 try header.addTab(allocator, label, tags_link, View.viewIndex(.tags)); 682 } 683 684 // new-patch tab; an edit or resolve url shows its tab in this place 685 if (session.local == null) { 686 const route = switch (data.view) { 687 .edit => ui.RoutablePage.repoThreadEditRoute(.patch, data.identity, data.selected_id) orelse return error.RouteTooLong, 688 .new_comment => ui.RoutablePage.repoThreadCommentNewRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 689 .edit_comment => ui.RoutablePage.repoThreadCommentEditRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 690 .remove => ui.RoutablePage.repoThreadRemoveRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 691 .resolve => ui.RoutablePage.repoPatchesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 692 else => ui.RoutablePage.repoThreadNewRoute(.patch, data.identity) orelse return error.RouteTooLong, 693 }; 694 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.new)); 695 const label: []const u8 = switch (data.view) { 696 .edit => "edit", 697 .new_comment => "reply", 698 .edit_comment => "edit", 699 .remove => "remove", 700 .resolve => "resolve", 701 else => "new", 702 }; 703 try header.addTab(allocator, label, link, View.viewIndex(.new)); 704 } 705 706 // drafts belong to the logged-in user and are not available locally 707 if (session.local == null) { 708 const route = ui.RoutablePage.repoPatchesDraftsRoute(data.identity) orelse return error.RouteTooLong; 709 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.drafts)); 710 var label_buf: [64]u8 = undefined; 711 const label = try std.fmt.bufPrint(&label_buf, "drafts ({d})", .{data.drafts.count}); 712 try header.addTab(allocator, label, link, View.viewIndex(.drafts)); 713 } 714 715 // conflicts tab, labeled with the conflict count 716 if (data.conflicts.count > 0) { 717 const route = ui.RoutablePage.repoPatchesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 718 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.conflicts)); 719 var label_buf: [64]u8 = undefined; 720 const label = try std.fmt.bufPrint(&label_buf, "conflicts ({d})", .{data.conflicts.count}); 721 try header.addTab(allocator, label, link, View.viewIndex(.conflicts)); 722 } 723 724 header.select(View.viewIndex(data.view)); 725 return header; 726 } 727