╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
474 var row = try wgt.TextBox.init(allocator, label, .{ .border = .hidden, .round_corners = true, .wrap_kind = .word, .bottom_label = .{ .text = bottom_label } }); 475 errdefer row.deinit(allocator); 476 row.getFocus().mode = .all; 477 if (link.len != 0) row.getFocus().kind = .{ .custom = link }; 478 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .text_box = row }, .rect = null, .min_size = null, .max_size = .{ .width = null, .height = 5 } }); 479 } 480 481 // a focusable row following `link`, returning its focus id 482 fn addLink(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, link: []const u8) !usize { 483 var tb = try wgt.TextBox.init(allocator, label, .{ .border = .single, .round_corners = true, .wrap_kind = .none }); 484 errdefer tb.deinit(allocator); 485 tb.getFocus().mode = .all; 486 tb.getFocus().kind = .{ .custom = link }; 487 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 488 return tb.getFocus().id; 489 } 490 491 // how much of the message a pane's box holds: a truncated preview links to 492 // the pane holding the whole thing, which is that link's destination. 493 const MessageBox = enum { preview, whole }; 494 495 // the selected commit's message. 496 fn addMessageBox(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), commit: Commit, kind: MessageBox) !void { 497 // a truncated message keeps its box even with no whole line to show, 498 // since the box is what links to the whole thing. 499 if (commit.message.len == 0 and !commit.message_truncated) return; 500 const cut_short = commit.message_truncated and kind == .preview; 501 var tb = try messageBox(allocator, commit.message, if (cut_short) " click or press enter to see more " else ""); 502 errdefer tb.deinit(allocator); 503 if (cut_short) tb.getFocus().kind = .{ .custom = try messageLink(self.session.page_arena, self.data, commit.oid) }; 504 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 505 } 506 507 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 508 self.box.deinit(allocator); 509 } 510 511 // the split is last, after the sub-header where there is one 512 fn contentIndex(self: *View) usize { 513 return self.box.children.count() - 1; 514 } 515 516 fn contentBox(self: *View) *wgt.Box(ui.Widget) { 517 return &self.box.children.values()[self.contentIndex()].widget.box; 518 } 519 520 fn header(self: *View) ?*ui.widget.SearchHeader { 521 switch (self.box.children.values()[header_index].widget) { 522 .search_header => |*header_view| return header_view, 523 else => return null, 524 } 525 } 526 527 fn headerActive(self: *View) bool { 528 const header_view = self.header() orelse return false; 529 return self.box.getFocus().child_id == header_view.getFocus().id; 530 } 531 532 fn listScroll(self: *View) *wgt.Scroll(ui.Widget) { 533 return &self.contentBox().children.values()[list_index].widget.scroll; 534 } 535 536 fn listBox(self: *View) *wgt.Box(ui.Widget) { 537 return &self.listScroll().child.box; 538 } 539 540 fn detailOuter(self: *View) *wgt.Box(ui.Widget) { 541 return &self.contentBox().children.values()[detail_index].widget.box; 542 } 543 544 fn detailScroll(self: *View) *wgt.Scroll(ui.Widget) { 545 return &self.detailOuter().children.values()[0].widget.scroll; 546 } 547 548 fn detailInner(self: *View) *wgt.Box(ui.Widget) { 549 return &self.detailScroll().child.box; 550 } 551 552 fn detailActive(self: *View) bool { 553 const content = self.contentBox(); 554 const cid = content.getFocus().child_id orelse return false; 555 return content.children.getIndex(cid) == detail_index; 556 } 557 558 // the selected commit's index, or null when the "next" row is selected. 559 fn selectedCommitIndex(self: *View) ?usize { 560 const lb = self.listBox(); 561 const cid = lb.getFocus().child_id orelse return null; 562 const idx = lb.children.getIndex(cid) orelse return null; 563 if (idx >= self.data.commits.len) return null; 564 return idx; 565 } 566 567 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 568 self.clearGrid(); 569 if (self.data.no_commits or self.data.isEmpty()) return self.box.build(allocator, constraint, root_focus); 570 571 // whether the detail pane fits beside the list, which decides the list 572 // cap below and whether the detail carries a way back to the list 573 const both_panes_fit = if (constraint.max_size.width) |w| w >= list_max_width + detail_min_width else true; 574 575 // swap the detail pane to the selected commit when it changes. 576 try self.refreshDetail(allocator, !both_panes_fit); 577 578 // the selected list row shows a border (the focused TextBox upgrades it 579 // to a double border itself); the rest stay borderless. 580 const lb = self.listBox(); 581 for (lb.children.keys(), lb.children.values()) |id, *child| { 582 switch (child.widget) { 583 .text_box => |*tb| ui.widget.markSelected(tb, lb.getFocus().child_id == id), 584 else => {}, 585 } 586 } 587 588 // cap the list at list_max_width only while the detail pane fits beside it. 589 // the box drops the pane when the width can't hold both minimums, so when 590 // it's that narrow we lift the cap and let the list fill the whole width. 591 self.contentBox().children.values()[list_index].max_size = if (both_panes_fit) .{ .width = list_max_width, .height = null } else null; 592 593 // stretch the detail pane across the rest of the width so it fills the area 594 // rather than shrinking to its content; its scroll fills the pane. when 595 // too narrow for both, it fills the whole width. 596 const detail_width: usize = if (constraint.max_size.width) |w| 597 (if (both_panes_fit) w - list_max_width else w) 598 else 599 detail_min_width; 600 self.contentBox().children.values()[detail_index].min_size = .{ .width = detail_width, .height = null }; 601 602 // the web bounds the layout to the browser viewport like the terminal; 603 // each Scroll's web-native mode hands its full content to a real 604 // scrollable element, so we no longer build unbounded here. 605 // 606 // crossing panes only re-selects the content box's child (focusDetail / 607 // focusList); when the window is too narrow to show both, the pane that 608 // held focus is dropped here. the framework recovers focus after the 609 // top-level build by re-deriving it down the selected-child chain, so 610 // there's nothing to fix up afterward. 611 try self.box.build(allocator, constraint, root_focus); 612 } 613 614 fn refreshDetail(self: *View, allocator: std.mem.Allocator, narrow: bool) !void { 615 const next: Shown = .{ .index = self.selectedCommitIndex() orelse return, .narrow = narrow }; 616 if (self.shown) |shown| if (std.meta.eql(shown, next)) return; 617 try self.populateDetail(allocator, next); 618 self.shown = next; 619 } 620 621 fn populateDetail(self: *View, allocator: std.mem.Allocator, next: Shown) !void { 622 const sel = next.index; 623 const commit = self.data.commits[sel]; 624 const inner = self.detailInner(); 625 626 for (inner.children.values()) |*child| child.widget.deinit(allocator); 627 inner.children.clearAndFree(allocator); 628 inner.getFocus().child_id = null; 629 self.back_id = null; 630 631 // with the list hidden beside it, the detail leads with the way back. 632 // an in-page link to this very page, so both hosts hand its press and 633 // enter to input instead of navigating. 634 if (next.narrow) { 635 const pa = self.session.page_arena; 636 const link = try pa.allocator().print("ai:{s}", .{try self.session.data.current_page.toUrl(pa)}); 637 self.back_id = try addLink(allocator, inner, "← back to commit list", link); 638 } 639 640 if (sel == 0 and self.data.message) { 641 _ = try addLink(allocator, inner, "← back to commit", try commitsLink(self.session.page_arena, self.data, commit.oid)); 642 try self.addMessageBox(allocator, inner, commit, .whole); 643 } else { 644 const pa = self.session.page_arena; 645 { 646 var row = try wgt.Box(ui.Widget).init(allocator, .{ .border = null, .direction = .horiz }); 647 errdefer row.deinit(allocator); 648 const diff_route = self.data.handle.location.commitDiffRoute(commit.oid, commit.parent_oid) orelse return error.RouteTooLong; 649 _ = try addLink(allocator, &row, "view diff", try pa.allocator().print("a:{s}", .{try diff_route.toUrl(pa)})); 650 _ = try addLink(allocator, &row, "view files at this commit", try filesObjectLink(pa, self.data.handle.location, commit.oid)); 651 row.getFocus().child_id = row.children.keys()[0]; 652 try inner.children.put(allocator, row.getFocus().id, .{ .widget = .{ .box = row }, .rect = null, .min_size = null }); 653 } 654 if (commit.merge) if (self.data.handle.location.commitsMergeRoute(commit.oid)) |route| { 655 _ = try addLink(allocator, inner, "view commits from this merge", try pa.allocator().print("a:{s}", .{try route.toUrl(pa)})); 656 }; 657 { 658 var row = try wgt.Box(ui.Widget).init(allocator, .{ .border = null, .direction = .horiz }); 659 errdefer row.deinit(allocator); 660 if (commit.author != .unknown) { 661 var tb = try ui.authorBox(allocator, pa, commit.author); 662 errdefer tb.deinit(allocator); 663 try row.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 664 } 665 if (commit.committer != .unknown) { 666 var tb = try ui.authorBox(allocator, pa, commit.committer); 667 errdefer tb.deinit(allocator); 668 tb.options.top_label.text = " committer "; 669 try row.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 670 } 671 const timestamp = try ui.timestamp.format(pa.allocator(), commit.timestamp, try self.session.nowSeconds()); 672 var tb = try wgt.TextBox.init(allocator, timestamp.relative, .{ .border = .single, .round_corners = true, .wrap_kind = .none, .bottom_label = .{ .text = timestamp.exact } }); 673 errdefer tb.deinit(allocator); 674 tb.getFocus().mode = .all; 675 try row.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 676 row.getFocus().child_id = row.children.keys()[0]; 677 try inner.children.put(allocator, row.getFocus().id, .{ .widget = .{ .box = row }, .rect = null, .min_size = null }); 678 } 679 if (commit.stats) |stats| { 680 var text: std.Io.Writer.Allocating = .init(allocator); 681 defer text.deinit(); 682 try text.writer.print("lines changed: {d}", .{stats.lines_added + stats.lines_changed}); 683 if (stats.lines_removed != 0) try text.writer.print("\nlines removed: {d}", .{stats.lines_removed}); 684 const bytes_added = stats.bytes_added >= stats.bytes_removed; 685 const bytes = if (bytes_added) stats.bytes_added - stats.bytes_removed else stats.bytes_removed - stats.bytes_added; 686 try text.writer.print("\nbytes {s}: {d}\nfiles changed: {d}", .{ 687 if (bytes_added) "added" else "removed", bytes, stats.files_added + stats.files_changed, 688 }); 689 if (stats.files_removed != 0) try text.writer.print("\nfiles removed: {d}", .{stats.files_removed}); 690 var tb = try wgt.TextBox.init(allocator, text.written(), .{ .border = .single, .round_corners = true, .wrap_kind = .none, .top_label = .{ .text = " stats " } }); 691 errdefer tb.deinit(allocator); 692 tb.getFocus().mode = .all; 693 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 694 } 695 try self.addMessageBox(allocator, inner, commit, .preview); 696 } 697 698 // point the pane at its first row so focus recovery can land here. 699 if (inner.children.count() > 0) inner.getFocus().child_id = inner.children.keys()[0]; 700 701 // reset the scroll to the top for the newly-shown commit: directly on the 702 // terminal (the wasm offset), and via a version bump on the web (so the 703 // renderer's scroll id changes and JS drops the preserved position). 704 const sc = self.detailScroll(); 705 sc.x = 0; 706 sc.y = 0; 707 sc.getFocus().version +%= 1; 708 } 709 710 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 711 if (self.data.no_commits) return self.box.input(allocator, key, root_focus); 712 // scrolling crosses the sub header boundary the same way arrows do 713 const direction = inp.vertDirection(key); 714 if (self.headerActive()) { 715 // active means there is one 716 const header_view = self.header() orelse unreachable; 717 if (direction == .down) { 718 // the empty message has nothing to focus 719 if (!self.data.isEmpty()) root_focus.setFocus(self.contentBox().getFocus().id); 720 return; 721 } 722 if (key == .enter) if (try header_view.submittedText(allocator)) |text| { 723 defer allocator.free(text); 724 return self.submit(text); 725 }; 726 return header_view.input(allocator, key, root_focus); 727 } 728 if (direction == .up and self.contentAtTop() and self.focusHeader(root_focus)) return; 729 if (self.detailActive()) { 730 // the way back to the list, by enter or a click 731 if (self.back_id) |id| { 732 if (inp.activated(root_focus, id, key)) return self.focusList(root_focus); 733 } 734 const inner = self.detailInner(); 735 if (inp.rowDelta(key, @intCast(inner.children.count()))) |delta| { 736 ui.widget.moveRowFocus(inner, self.detailScroll(), root_focus, delta); 737 } else if (key == .arrow_left) { 738 if (!ui.widget.moveInSelectedRow(inner, root_focus, false)) self.focusList(root_focus); 739 } else if (key == .arrow_right) { 740 _ = ui.widget.moveInSelectedRow(inner, root_focus, true); 741 } 742 } else { 743 try self.listInput(allocator, key, root_focus); 744 } 745 } 746 747 // navigate to the typed query's results, pinned to the list's ref. an 748 // empty query leaves the results for the plain log. 749 fn submit(self: *View, text: []const u8) !void { 750 if (text.len == 0 and self.data.search == null) return; 751 // an object view or a base-bounded list searches the default branch, so the url says so 752 const route = if (self.data.default_branch.len != 0) 753 self.data.handle.location.commitsRoute(.branch, self.data.default_branch, "") 754 else 755 self.data.handle.location.commitsRoute(self.data.ref_or_oid, self.data.ref_or_oid_value, self.data.base_oid); 756 try self.session.navigate((route orelse return).withSearch(text) orelse return); 757 } 758 759 fn listInput(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 760 // up/down (and the scroll wheel) move the selection a row; page up/down 761 // jump a fixed amount. right/Enter cross into the detail pane. Enter/clicks 762 // on the "next" row become navigation in the host before reaching here. 763 if (inp.rowDelta(key, @intCast(self.listBox().children.count()))) |delta| { 764 ui.widget.moveRowFocus(self.listBox(), self.listScroll(), root_focus, delta); 765 return; 766 } 767 switch (key) { 768 .enter => if (self.selectedCommitIndex() != null) 769 self.focusDetail(root_focus) 770 else if (self.data.next_start) |next| { 771 if (pageRoute(self.data, next)) |route| try self.session.navigate(route); 772 }, 773 .arrow_right => self.focusDetail(root_focus), 774 // when the window is too narrow to lay out the detail pane beside 775 // the list, a click on a row opens it like enter. the row was just 776 // selected, so the detail is swapped to it ahead of the build. 777 .mouse => |mouse| if (self.contentBox().children.values()[detail_index].rect == null and ui.widget.clickOnSelectedRow(self.listBox(), root_focus, mouse)) { 778 try self.refreshDetail(allocator, true); 779 self.focusDetail(root_focus); 780 }, 781 else => {}, 782 } 783 } 784 785 // enter the detail pane. the host arrives here on right-arrow or Enter from the 786 // list. a pane with no rows can't be entered. setFocus handles the too-narrow 787 // case where the pane isn't laid out yet (it gets selected, then focused after 788 // the next build, landing on its remembered row). 789 fn focusDetail(self: *View, root_focus: *Focus) void { 790 if (self.detailInner().children.count() == 0) return; 791 root_focus.setFocus(self.detailOuter().getFocus().id); 792 } 793 794 // return to the list. 795 fn focusList(self: *View, root_focus: *Focus) void { 796 root_focus.setFocus(self.listScroll().getFocus().id); 797 } 798 799 pub fn clearGrid(self: *View) void { 800 self.box.clearGrid(); 801 } 802 803 pub fn getGrid(self: View) ?Grid { 804 return self.box.getGrid(); 805 } 806 807 pub fn getFocus(self: *View) *Focus { 808 return self.box.getFocus(); 809 } 810 811 fn contentAtTop(self: *View) bool { 812 if (self.detailActive()) { 813 const inner = self.detailInner(); 814 const cid = inner.getFocus().child_id orelse return true; 815 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 816 return first_focused and self.detailScroll().y == 0; 817 } 818 const lb = self.listBox(); 819 const cid = lb.getFocus().child_id orelse return true; 820 return lb.children.getIndex(cid) == 0; 821 } 822 823 // only the header's own row sits directly below the repository header. 824 pub fn atTop(self: *View) bool { 825 if (self.data.no_commits or self.data.isEmpty()) return true; 826 const focusable = if (self.header()) |header_view| header_view.hasFocusable() else false; 827 return self.headerActive() or (!focusable and self.contentAtTop()); 828 } 829 830 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 831 const header_view = self.header() orelse return false; 832 return header_view.focusHeader(root_focus); 833 } 834 }; 835 836 // the "a:" navigation link for the commits page walking from commit `oid` within 837 // `data.handle.location`. 838 fn commitsLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 839 const route = data.handle.location.commitsRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 840 const url = try route.toUrl(page_arena); 841 return page_arena.allocator().print("a:{s}", .{url}); 842 } 843 844 // this list's page starting at `oid`: a repo's branch or tag keeps its ref (and 845 // its query) and moves `from` along, so the search box survives paging. a fork 846 // or an object view roots the page at the commit itself. 847 fn pageRoute(data: *const Self, oid: []const u8) ?ui.RoutablePage { 848 if (data.handle.location != .repo or data.ref_or_oid == .object) { 849 return data.handle.location.commitsRoute(.object, oid, data.base_oid); 850 } 851 const route = data.handle.location.commitsRoute(data.ref_or_oid, data.ref_or_oid_value, data.base_oid) orelse return null; 852 const paged = route.withFrom(oid) orelse return null; 853 return paged.withSearch(data.search orelse return paged); 854 } 855 856 fn nextPageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 857 const route = pageRoute(data, oid) orelse return error.RouteTooLong; 858 const url = try route.toUrl(page_arena); 859 return page_arena.allocator().print("a:{s}", .{url}); 860 } 861 862 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 863 // directory, within `location`. 864 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 865 const route = location.filesRoute(.object, oid, "", 0) orelse return error.RouteTooLong; 866 const url = try route.toUrl(page_arena); 867 return page_arena.allocator().print("a:{s}", .{url}); 868 } 869 870 // the in-page "ai:" anchor for selecting a commit, showing its whole message 871 // when `message` is set. the href is only followed with js off. 872 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, commit: Commit, message: bool) ![]const u8 { 873 // a result roots the same results page at its commit, so the query 874 // survives following the row 875 if (data.search != null) { 876 const route = pageRoute(data, commit.oid) orelse return error.RouteTooLong; 877 return page_arena.allocator().print("ai:{s}", .{try route.toUrl(page_arena)}); 878 } 879 const route = (if (message) 880 data.handle.location.commitMessageRoute(.object, commit.oid, data.base_oid) 881 else 882 data.handle.location.commitsRoute(.object, commit.oid, data.base_oid)) orelse return error.RouteTooLong; 883 const url = try route.toUrl(page_arena); 884 return page_arena.allocator().print("ai:{s}", .{url}); 885 } 886 887 // the "a:" link to the page showing `oid`'s message on its own. 888 fn messageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 889 const route = data.handle.location.commitMessageRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 890 const url = try route.toUrl(page_arena); 891 return page_arena.allocator().print("a:{s}", .{url}); 892 } 893