╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
430 errdefer list_scroll.deinit(allocator); 431 try box.children.put(allocator, list_scroll.getFocus().id, .{ .widget = .{ .scroll = list_scroll }, .rect = null, .min_size = .{ .width = list_max_width, .height = null }, .max_size = .{ .width = list_max_width, .height = null } }); 432 } 433 434 // the diff pane — a frame around a scroll of the hunks 435 { 436 var diff_outer = blk: { 437 var diff_scroll = try Diff.View.initEmpty(allocator, session); 438 errdefer diff_scroll.deinit(allocator); 439 var frame = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = .hidden, .direction = .vert }); 440 errdefer frame.deinit(allocator); 441 // the frame's selected child is its scroll, so the focus chain 442 // reaches a hunk (populateDiff points the scroll's inner box at 443 // one), letting focus recovery descend into the diff pane after 444 // it's laid out beside a too-narrow list. 445 frame.getFocus().child_id = diff_scroll.getFocus().id; 446 try frame.children.put(allocator, diff_scroll.getFocus().id, .{ .widget = .{ .diff_view = diff_scroll }, .rect = null, .min_size = null }); 447 break :blk frame; 448 }; 449 errdefer diff_outer.deinit(allocator); 450 diff_outer.getFocus().mode = .mouse; 451 try box.children.put(allocator, diff_outer.getFocus().id, .{ .widget = .{ .box = diff_outer }, .rect = null, .min_size = .{ .width = diff_min_width, .height = null } }); 452 } 453 454 box.getFocus().child_id = box.children.keys()[list_index]; 455 try outer.children.put(allocator, box.getFocus().id, .{ .widget = .{ .box = box }, .rect = null, .min_size = null }); 456 457 // focus lives in the split, except that search results start in the 458 // search box so the query can be refined right away. 459 outer.getFocus().child_id = outer.children.keys()[if (data.search != null) header_index else content_index]; 460 461 return .{ 462 .box = outer, 463 .data = data, 464 .session = session, 465 .diffed_index = null, 466 }; 467 } 468 469 fn addRow(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, link: []const u8) !void { 470 var row = try wgt.TextBox.init(allocator, label, .{ .border_style = .hidden, .rounded_corners = true, .wrap_kind = .word }); 471 errdefer row.deinit(allocator); 472 row.getFocus().mode = .all; 473 if (link.len != 0) row.getFocus().kind = .{ .custom = link }; 474 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .text_box = row }, .rect = null, .min_size = null, .max_size = .{ .width = null, .height = 5 } }); 475 } 476 477 // a focusable window-navigation row ("previous"/"next"). it's a link to this 478 // commit's route at `target_start`, so activating it (the host follows the 479 // "a:" link) reloads the page on the adjacent window — same on TUI and web. 480 fn addNavLink(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, oid: []const u8, target_start: usize, path: []const u8) !void { 481 const link = try commitsLink(self.session.page_arena, self.data, oid, target_start, path); 482 var tb = try wgt.TextBox.init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 483 errdefer tb.deinit(allocator); 484 tb.getFocus().mode = .all; 485 tb.getFocus().kind = .{ .custom = link }; 486 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 487 } 488 489 // a focusable row for the top of the diff pane linking to the files tab at 490 // this commit's tree, so its files are always viewable as of this object. 491 fn addViewFilesLink(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), oid: []const u8) !void { 492 const link = try filesObjectLink(self.session.page_arena, self.data.location, oid); 493 var tb = try wgt.TextBox.init(allocator, "view files at this commit", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 494 errdefer tb.deinit(allocator); 495 tb.getFocus().mode = .all; 496 tb.getFocus().kind = .{ .custom = link }; 497 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 498 } 499 500 // how much of the message a pane's box holds: a truncated preview links to 501 // the pane holding the whole thing, which is that link's destination. 502 const MessageBox = enum { preview, whole }; 503 504 // the selected commit's message. 505 fn addMessageBox(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), commit: Commit, kind: MessageBox) !void { 506 // a truncated message keeps its box even with no whole line to show, 507 // since the box is what links to the whole thing. 508 if (commit.message.len == 0 and !commit.message_truncated) return; 509 const cut_short = commit.message_truncated and kind == .preview; 510 var tb = try messageBox(allocator, commit.message, if (cut_short) " click or press enter to see more " else ""); 511 errdefer tb.deinit(allocator); 512 if (cut_short) tb.getFocus().kind = .{ .custom = try messageLink(self.session.page_arena, self.data, commit.oid) }; 513 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 514 } 515 516 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 517 self.box.deinit(allocator); 518 } 519 520 fn contentBox(self: *View) *wgt.Box(ui.Widget) { 521 return &self.box.children.values()[content_index].widget.box; 522 } 523 524 fn header(self: *View) *ui.widget.SearchHeader { 525 return &self.box.children.values()[header_index].widget.search_header; 526 } 527 528 fn headerActive(self: *View) bool { 529 return self.box.getFocus().child_id == self.header().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 diffOuter(self: *View) *wgt.Box(ui.Widget) { 541 return &self.contentBox().children.values()[diff_index].widget.box; 542 } 543 544 fn diffScroll(self: *View) *wgt.Scroll(ui.Widget) { 545 return &self.diffOuter().children.values()[0].widget.diff_view.scroll; 546 } 547 548 fn diffInner(self: *View) *wgt.Box(ui.Widget) { 549 return &self.diffScroll().child.box; 550 } 551 552 fn diffActive(self: *View) bool { 553 const content = self.contentBox(); 554 const cid = content.getFocus().child_id orelse return false; 555 return content.children.getIndex(cid) == diff_index; 556 } 557 558 // what the pane shows for the commit at `sel`. the page's content only 559 // applies to the commit it walks from; the rest show their plain diff. 560 fn paneContent(self: *View, sel: usize) Self.Content { 561 return if (sel == 0) self.data.content else .{ .diff = .{} }; 562 } 563 564 // the selected commit's index, or null when the "next" row is selected. 565 fn selectedCommitIndex(self: *View) ?usize { 566 const lb = self.listBox(); 567 const cid = lb.getFocus().child_id orelse return null; 568 const idx = lb.children.getIndex(cid) orelse return null; 569 if (idx >= self.data.commits.len) return null; 570 return idx; 571 } 572 573 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 574 self.clearGrid(); 575 576 // swap the diff pane to the selected commit when it changes. 577 try self.refreshDiff(allocator); 578 579 // the selected list row shows a border (the focused TextBox upgrades it 580 // to a double border itself); the rest stay borderless. 581 const lb = self.listBox(); 582 for (lb.children.keys(), lb.children.values()) |id, *child| { 583 switch (child.widget) { 584 .text_box => |*tb| tb.options.border_style = if (lb.getFocus().child_id == id) .single else .hidden, 585 else => {}, 586 } 587 } 588 589 // cap the list at list_max_width only while the diff pane fits beside it. 590 // the box drops the diff when the width can't hold both minimums, so when 591 // it's that narrow we lift the cap and let the list fill the whole width. 592 const both_panes_fit = if (constraint.max_size.width) |w| w >= list_max_width + diff_min_width else true; 593 self.contentBox().children.values()[list_index].max_size = if (both_panes_fit) .{ .width = list_max_width, .height = null } else null; 594 595 // stretch the diff pane across the rest of the width so it fills the area 596 // rather than shrinking to its content; its scroll fills the pane. when 597 // too narrow for both, it fills the whole width. 598 const diff_width: usize = if (constraint.max_size.width) |w| 599 (if (both_panes_fit) w - list_max_width else w) 600 else 601 diff_min_width; 602 self.contentBox().children.values()[diff_index].min_size = .{ .width = diff_width, .height = null }; 603 604 // the message is the pane's only wrapping row, and wrapping needs a 605 // bounded width, which the pane's scroll doesn't grant (it scrolls 606 // horizontally too). cap it to the pane, leaving room for the border 607 // and the scrollbar column. re-capped each build so it tracks resizes. 608 for (self.diffInner().children.values()) |*child| switch (child.widget) { 609 .text_box => |text_box| if (text_box.options.wrap_kind == .word) { 610 child.max_size = .{ .width = diff_width -| 3, .height = null }; 611 }, 612 else => {}, 613 }; 614 615 // the web bounds the layout to the browser viewport like the terminal; 616 // each Scroll's web-native mode hands its full content to a real 617 // scrollable element, so we no longer build unbounded here. 618 // 619 // crossing panes only re-selects the content box's child (focusDiff / 620 // focusList); when the window is too narrow to show both, the pane that 621 // held focus is dropped here. the framework recovers focus after the 622 // top-level build by re-deriving it down the selected-child chain, so 623 // there's nothing to fix up afterward. 624 try self.box.build(allocator, constraint, root_focus); 625 } 626 627 fn refreshDiff(self: *View, allocator: std.mem.Allocator) !void { 628 const sel = self.selectedCommitIndex() orelse return; 629 if (self.diffed_index) |d| if (d == sel) return; 630 try self.populateDiff(allocator, sel); 631 self.diffed_index = sel; 632 } 633 634 fn populateDiff(self: *View, allocator: std.mem.Allocator, sel: usize) !void { 635 const commit = self.data.commits[sel]; 636 const inner = self.diffInner(); 637 638 for (inner.children.values()) |*child| child.widget.deinit(allocator); 639 inner.children.clearAndFree(allocator); 640 inner.getFocus().child_id = null; 641 642 switch (self.paneContent(sel)) { 643 .message => { 644 try self.addNavLink(allocator, inner, "← back to diff", commit.oid, 0, ""); 645 try self.addMessageBox(allocator, inner, commit, .whole); 646 }, 647 .diff => |d| { 648 if (d.path.len == 0) { 649 try self.addMessageBox(allocator, inner, commit, .preview); 650 if (commit.author != .unknown) { 651 var tb = try ui.authorBox(allocator, self.session.page_arena, commit.author); 652 errdefer tb.deinit(allocator); 653 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 654 } 655 if (commit.stats) |stats| { 656 var text: std.Io.Writer.Allocating = .init(allocator); 657 defer text.deinit(); 658 try text.writer.print("lines changed: {d}", .{stats.lines_added + stats.lines_changed}); 659 if (stats.lines_removed != 0) try text.writer.print("\nlines removed: {d}", .{stats.lines_removed}); 660 const bytes_added = stats.bytes_added >= stats.bytes_removed; 661 const bytes = if (bytes_added) stats.bytes_added - stats.bytes_removed else stats.bytes_removed - stats.bytes_added; 662 try text.writer.print("\nbytes {s}: {d}\nfiles changed: {d}", .{ 663 if (bytes_added) "added" else "removed", bytes, stats.files_added + stats.files_changed, 664 }); 665 if (stats.files_removed != 0) try text.writer.print("\nfiles removed: {d}", .{stats.files_removed}); 666 var tb = try wgt.TextBox.init(allocator, text.written(), .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none, .label = " stats " }); 667 errdefer tb.deinit(allocator); 668 tb.getFocus().mode = .all; 669 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 670 } 671 try self.addViewFilesLink(allocator, inner, commit.oid); 672 } 673 674 try (Diff{ 675 .route = .{ .commit = .{ .location = self.data.location, .oid = commit.oid, .base_oid = self.data.base_oid } }, 676 .path = d.path, 677 .window = commit.window, 678 }).appendWindow(allocator, self.session, inner); 679 }, 680 } 681 682 // point the pane at its first row so focus recovery can land here. 683 if (inner.children.count() > 0) inner.getFocus().child_id = inner.children.keys()[0]; 684 685 // reset the scroll to the top for the newly-shown commit: directly on the 686 // terminal (the wasm offset), and via a version bump on the web (so the 687 // renderer's scroll id changes and JS drops the preserved position). 688 const sc = self.diffScroll(); 689 sc.x = 0; 690 sc.y = 0; 691 sc.getFocus().version +%= 1; 692 } 693 694 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 695 if (self.headerActive()) { 696 if (key == .arrow_down) { 697 root_focus.setFocus(self.contentBox().getFocus().id); 698 return; 699 } 700 if (key == .enter) if (try self.header().submittedText(allocator)) |text| { 701 defer allocator.free(text); 702 return self.submit(text); 703 }; 704 return self.header().input(allocator, key, root_focus); 705 } 706 if (key == .arrow_up and self.contentAtTop() and self.header().focusHeader(root_focus)) return; 707 if (self.diffActive()) { 708 if (key == .arrow_left and self.diffScroll().x == 0) { 709 self.focusList(root_focus); 710 } else { 711 try self.diffOuter().children.values()[0].widget.diff_view.input(allocator, key, root_focus); 712 } 713 } else { 714 try self.listInput(key, root_focus); 715 } 716 } 717 718 // navigate to the typed query's results, pinned to the list's ref. an 719 // empty query leaves the results for the plain log. 720 fn submit(self: *View, text: []const u8) !void { 721 if (text.len == 0 and self.data.search == null) return; 722 const route = self.data.location.commitsRoute(self.data.ref_or_oid, self.data.ref_or_oid_value, 0, "", self.data.base_oid) orelse return; 723 try self.session.navigate(route.withSearch(text) orelse return); 724 } 725 726 fn listInput(self: *View, key: Key, root_focus: *Focus) !void { 727 // up/down (and the scroll wheel) move the selection a row; page up/down 728 // jump a fixed amount. right/Enter cross into the diff pane. Enter/clicks 729 // on the "next" row become navigation in the host before reaching here. 730 if (inp.rowDelta(key, @intCast(self.listBox().children.count()))) |delta| { 731 ui.widget.moveRowFocus(self.listBox(), self.listScroll(), root_focus, delta); 732 return; 733 } 734 switch (key) { 735 .enter => if (self.selectedCommitIndex() != null) 736 self.focusDiff(root_focus) 737 else if (self.data.next_start) |next| { 738 if (pageRoute(self.data, next)) |route| try self.session.navigate(route); 739 }, 740 .arrow_right => self.focusDiff(root_focus), 741 else => {}, 742 } 743 } 744 745 // enter the diff pane. the host arrives here on right-arrow or Enter from the 746 // list. a diff with no rows can't be entered. setFocus handles the too-narrow 747 // case where the pane isn't laid out yet (it gets selected, then focused after 748 // the next build, landing on its remembered hunk). 749 fn focusDiff(self: *View, root_focus: *Focus) void { 750 if (self.diffInner().children.count() == 0) return; 751 root_focus.setFocus(self.diffOuter().getFocus().id); 752 } 753 754 // return to the list. 755 fn focusList(self: *View, root_focus: *Focus) void { 756 root_focus.setFocus(self.listScroll().getFocus().id); 757 } 758 759 pub fn clearGrid(self: *View) void { 760 self.box.clearGrid(); 761 } 762 763 pub fn getGrid(self: View) ?Grid { 764 return self.box.getGrid(); 765 } 766 767 pub fn getFocus(self: *View) *Focus { 768 return self.box.getFocus(); 769 } 770 771 fn contentAtTop(self: *View) bool { 772 if (self.diffActive()) { 773 const inner = self.diffInner(); 774 const cid = inner.getFocus().child_id orelse return true; 775 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 776 return first_focused and self.diffScroll().y == 0; 777 } 778 const lb = self.listBox(); 779 const cid = lb.getFocus().child_id orelse return true; 780 return lb.children.getIndex(cid) == 0; 781 } 782 783 // only the header's own row sits directly below the repository header. 784 pub fn atTop(self: *View) bool { 785 return self.headerActive() or (!self.header().hasFocusable() and self.contentAtTop()); 786 } 787 788 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 789 return self.header().focusHeader(root_focus); 790 } 791 }; 792 793 // the "a:" navigation link for the commits page walking from commit `oid` within 794 // `data.location`, windowing the selected commit's diff from hunk `start`, filtered 795 // to `path` ("" = every file). 796 fn commitsLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8, start: usize, path: []const u8) ![]const u8 { 797 const route = data.location.commitsRoute(.object, oid, start, path, data.base_oid) orelse return error.RouteTooLong; 798 const url = try route.toUrl(page_arena); 799 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 800 } 801 802 // this list's page starting at `oid`: a repo's branch or tag keeps its ref (and 803 // its query) and moves `from` along, so the search box survives paging. a fork 804 // or an object view roots the page at the commit itself. 805 fn pageRoute(data: *const Self, oid: []const u8) ?ui.RoutablePage { 806 if (data.location != .repo or data.ref_or_oid == .object) { 807 return data.location.commitsRoute(.object, oid, 0, "", data.base_oid); 808 } 809 const route = data.location.commitsRoute(data.ref_or_oid, data.ref_or_oid_value, 0, "", data.base_oid) orelse return null; 810 const paged = route.withFrom(oid) orelse return null; 811 return paged.withSearch(data.search orelse return paged); 812 } 813 814 fn nextPageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 815 const route = pageRoute(data, oid) orelse return error.RouteTooLong; 816 const url = try route.toUrl(page_arena); 817 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 818 } 819 820 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 821 // directory, within `location`. 822 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 823 const route = location.filesRoute(.object, oid, "", 0) orelse return error.RouteTooLong; 824 const url = try route.toUrl(page_arena); 825 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 826 } 827 828 // the in-page "ai:" anchor for selecting a commit with its current pane content 829 // and window. the href is only followed with js off. 830 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, commit: Commit, content: Content) ![]const u8 { 831 // a result roots the same results page at its commit, so the query 832 // survives following the row 833 if (data.search != null) { 834 const route = pageRoute(data, commit.oid) orelse return error.RouteTooLong; 835 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{try route.toUrl(page_arena)}); 836 } 837 const route = (switch (content) { 838 .message => data.location.commitMessageRoute(.object, commit.oid, data.base_oid), 839 .diff => |diff| data.location.commitsRoute(.object, commit.oid, commit.window.start, diff.path, data.base_oid), 840 }) orelse return error.RouteTooLong; 841 const url = try route.toUrl(page_arena); 842 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 843 } 844 845 // the "a:" link to the page showing `oid`'s message on its own. 846 fn messageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 847 const route = data.location.commitMessageRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 848 const url = try route.toUrl(page_arena); 849 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 850 } 851