╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 const builtin = @import("builtin"); 3 const evt = @import("../../event.zig"); 4 const ui = @import("../../ui.zig"); 5 const xit = @import("xit"); 6 const rp = xit.repo; 7 const Diff = @import("Diff.zig"); 8 const obj = xit.object; 9 const cms = @import("../../search_commit.zig"); 10 const srch = @import("../../search.zig"); 11 const xitui = xit.xitui; 12 const wgt = xitui.widget; 13 const layout = xitui.layout; 14 const Key = xitui.input.Key; 15 const Grid = xitui.grid.Grid; 16 const Focus = xitui.focus.Focus; 17 const inp = @import("../input.zig"); 18 19 // how many commits a page shows before a "next" link appears. 20 const page_size = 20; 21 // the largest message read even when it has fewer than the preview's line 22 // limit. 23 const max_message_size = 100 * 1024; 24 25 // one commit on the current page, with its diff against its first parent 26 // pre-rendered up to the budget so the web client can show it without a repo. 27 pub const Commit = struct { 28 oid: []const u8, 29 date: []const u8, // "YYYY-MM-DD" 30 message: []const u8, // trimmed, may be multi-line 31 // whether `message` is a shortened preview. 32 message_truncated: bool = false, 33 author: ui.Author = .unknown, 34 stats: ?xit.patch.CommitStats = null, 35 window: Diff.Window = .{}, 36 }; 37 38 // where links and clone commands for this repository are rooted. 39 location: ui.RoutablePage.RepoLocation, 40 // the resolved ref/oid this log walks from (the default branch when the route 41 // didn't name one), so the page can canonicalize its url to it. 42 ref_or_oid: ui.RoutablePage.RefOrOid, 43 ref_or_oid_value: []const u8, 44 base_oid: []const u8 = "", 45 commit_count: ?u64 = null, 46 commits: []const Commit, 47 // the first oid of the next page, or null when this is the last page. 48 next_start: ?[]const u8, 49 // what the pane shows for the commit the log walks from. 50 content: Content = .{ .diff = .{} }, 51 // the decoded query this list holds the results of, or null for a plain log. 52 search: ?[]const u8 = null, 53 // whether the viewed ref has a commit index, so the search box shows and a 54 // search: route resolves. travels in the page json for the wasm view. 55 search_available: bool = false, 56 57 const Self = @This(); 58 59 // the diff and the message are alternatives, so a filtered diff can't also be 60 // a message. the message page reads up to the safety limit above. 61 pub const Content = union(enum) { 62 diff: struct { 63 // the file the top commit's diff is filtered to ("" = every file). 64 path: []const u8 = "", 65 }, 66 message, 67 }; 68 69 // walk the log for an opened repo. generic over the repo's backend and hash 70 // kind so the oid buffers and diff types it threads through match the repo's 71 // opts. `content` is what the walk root's pane shows, the only commit any of 72 // it applies to. walks with the arena's backing allocator (transient; the 73 // commits we keep are duped into the page arena so they outlive it). 74 pub fn init( 75 comptime repo_kind: rp.RepoKind, 76 comptime repo_opts: rp.RepoOpts(repo_kind), 77 arena: *std.heap.ArenaAllocator, 78 repo: *rp.Repo(repo_kind, repo_opts), 79 io: std.Io, 80 gpa: std.mem.Allocator, 81 // the admin db's moment, for resolving author emails to user names (null 82 // in local mode, which has no users) 83 admin_moment: ?evt.AdminDB.HashMap(.read_only), 84 location: ui.RoutablePage.RepoLocation, 85 requested_ref_or_oid: ?ui.RoutablePage.RefOrOid, 86 requested_value: []const u8, 87 content: ui.RoutablePage.RepoCommitsRoute.Content, 88 base_oid: []const u8, 89 search: []const u8, 90 from: []const u8, 91 ) !Self { 92 const aa = arena.allocator(); 93 const hex_len = ui.ResolvedRefOrOid(repo_kind, repo_opts).hex_len; 94 if (base_oid.len != 0) { 95 evt.PatchRev.validateOid(repo_opts.hash, base_oid) catch return error.NotFound; 96 } 97 if (from.len != 0) { 98 evt.PatchRev.validateOid(repo_opts.hash, from) catch return error.NotFound; 99 } 100 const query: ?[]const u8 = if (search.len == 0) null else std.Uri.percentDecodeInPlace(try aa.dupe(u8, search)); 101 102 // the walk root's message replaces its diff, so it's read whole and its 103 // hunks aren't rendered. the window and the filter are its diff's. 104 const root_message = std.meta.activeTag(content) == .message; 105 const root_start: usize = switch (content) { 106 .diff => |d| d.start, 107 .message => 0, 108 }; 109 const root_path: []const u8 = switch (content) { 110 .diff => |*d| d.path.slice(), 111 .message => "", 112 }; 113 114 // resolve the requested ref (or the default branch) to the commit oid to 115 // walk from. an explicitly named ref that doesn't resolve is a bad url 116 // (NotFound -> 404); the default-branch path falls through to empty. 117 var resolved = (try ui.ResolvedRefOrOid(repo_kind, repo_opts).init(repo, io, aa, requested_ref_or_oid, requested_value)) orelse { 118 if (requested_ref_or_oid != null) return error.NotFound; 119 return emptyResult(aa, location, .branch, requested_value, content, base_oid); 120 }; 121 122 var moment = repo.core.latestMoment() catch return emptyResult(aa, location, resolved.ref_or_oid, resolved.value, content, base_oid); 123 const state = rp.Repo(repo_kind, repo_opts).State(.read_only){ .core = &repo.core, .extra = .{ .moment = &moment } }; 124 125 // collect this page's commit metadata, plus a peek at the one after it (its 126 // oid is the next page's start). the diff for each is rendered afterward, so 127 // the log iterator is closed before opening per-commit diff iterators. 128 var buf: [page_size]Commit = undefined; 129 var oids: [page_size][hex_len]u8 = undefined; 130 var count: usize = 0; 131 var next_start: ?[]const u8 = null; 132 var search_available = false; 133 var searched = false; 134 135 // the index covers a repository's branch and tag tips, so a fork or an 136 // object view gets no search box and refuses a search: url. nor does a list 137 // bounded by a base, whose version also covers the commits before it. 138 if (comptime repo_kind == .xit) index: { 139 if (location != .repo or resolved.ref_or_oid == .object or base_oid.len != 0) break :index; 140 // versions are keyed by commit, so an annotated tag is peeled first 141 var tip = obj.Object(.xit, repo_opts).initCommit(state, io, gpa, &resolved.oid) catch break :index; 142 defer tip.deinit(); 143 resolved.oid = tip.oid; 144 const index = (try cms.lookup(repo_opts, moment, &resolved.oid)) orelse break :index; 145 search_available = true; 146 const text = query orelse break :index; 147 148 var results = try srch.Query(rp.Repo(.xit, repo_opts).DB).init(index, aa, text); 149 if (from.len != 0) { 150 var start = obj.Object(.xit, repo_opts).initCommit(state, io, gpa, from[0..hex_len]) catch return error.NotFound; 151 defer start.deinit(); 152 const key = try cms.docKey(repo_opts.hash, start.content.commit.metadata.timestamp, &start.oid); 153 results.seek(&key); 154 } 155 while (try results.next()) |key| { 156 const oid = try cms.keyOid(repo_opts.hash, key); 157 if (count == page_size) { 158 next_start = try aa.dupe(u8, &oid); 159 break; 160 } 161 // a result whose object is gone is skipped rather than shown 162 var commit_object = obj.Object(.xit, repo_opts).init(state, io, gpa, &oid) catch continue; 163 defer commit_object.deinit(); 164 if (commit_object.content != .commit) continue; 165 @memcpy(&oids[count], &oid); 166 buf[count] = try commitEntry(repo_kind, repo_opts, arena, repo, io, gpa, admin_moment, &commit_object, root_message and count == 0); 167 count += 1; 168 } 169 searched = true; 170 } 171 if (query != null and !searched) return error.NotFound; 172 173 if (!searched) { 174 // paging keeps the ref and starts the walk at the url's commit 175 var start_oid = resolved.oid; 176 if (from.len != 0) @memcpy(&start_oid, from); 177 178 var iter = repo.log(io, gpa, .{ .start_oids = &.{start_oid}, .first_parent = true }) catch return emptyResult(aa, location, resolved.ref_or_oid, resolved.value, content, base_oid); 179 defer iter.deinit(); 180 while (try iter.next(gpa)) |commit_object| { 181 defer commit_object.deinit(); 182 // count from the commit itself when the tip is an annotated tag 183 if (count == 0 and from.len == 0) resolved.oid = commit_object.oid; 184 // the base is a stopping point, not an ancestry exclusion 185 if (std.mem.eql(u8, &commit_object.oid, base_oid)) break; 186 if (count == page_size) { 187 next_start = try aa.dupe(u8, &commit_object.oid); 188 break; 189 } 190 @memcpy(&oids[count], &commit_object.oid); 191 buf[count] = try commitEntry(repo_kind, repo_opts, arena, repo, io, gpa, admin_moment, commit_object, root_message and count == 0); 192 count += 1; 193 } 194 } 195 196 // render each commit's diff (best effort: a failed diff leaves it empty). 197 // the diff machinery isn't wasm-clean and the wasm client never runs it (it 198 // renders from the snapshot), so gate it out of the wasm build. 199 if (!builtin.cpu.arch.isWasm()) { 200 for (buf[0..count], oids[0..count], 0..) |*commit, oid, i| { 201 if (root_message and i == 0) continue; 202 // the walk root shows the window the url asks for and its filter; 203 // the rest show their first window, unfiltered. 204 const window_start = if (i == 0) root_start else 0; 205 commit.window = renderCommitDiff(repo_kind, repo_opts, io, gpa, aa, repo, oid, window_start, if (i == 0) root_path else "") catch .{ .start = window_start }; 206 } 207 } 208 209 return .{ 210 .location = try location.dupe(aa), 211 .ref_or_oid = resolved.ref_or_oid, 212 .ref_or_oid_value = resolved.value, 213 .base_oid = try aa.dupe(u8, base_oid), 214 .commit_count = if (repo_kind == .xit and location == .repo) blk: { 215 if (base_oid.len == 0) break :blk repo.commitCount(io, gpa, .{ .oid = &resolved.oid }) catch null; 216 break :blk evt.PatchRev.commitCount(repo_kind, repo_opts, state, io, gpa, base_oid, &resolved.oid) catch null; 217 } else null, 218 .commits = try aa.dupe(Commit, buf[0..count]), 219 .next_start = next_start, 220 .content = try pageContent(aa, content), 221 .search = query, 222 .search_available = search_available, 223 }; 224 } 225 226 // one commit's row: its message, author and stats. the diff window is rendered 227 // afterward, once the log iterator is closed. 228 fn commitEntry( 229 comptime repo_kind: rp.RepoKind, 230 comptime repo_opts: rp.RepoOpts(repo_kind), 231 arena: *std.heap.ArenaAllocator, 232 repo: *rp.Repo(repo_kind, repo_opts), 233 io: std.Io, 234 gpa: std.mem.Allocator, 235 admin_moment: ?evt.AdminDB.HashMap(.read_only), 236 commit_object: *obj.Object(repo_kind, repo_opts), 237 full_message: bool, 238 ) !Commit { 239 const aa = arena.allocator(); 240 const md = commit_object.content.commit.metadata; 241 const text, const truncated = try readMessage(repo_kind, repo_opts, aa, commit_object, full_message); 242 return .{ 243 .oid = try aa.dupe(u8, &commit_object.oid), 244 .date = try formatDate(aa, md.timestamp), 245 .message = text, 246 .message_truncated = truncated, 247 .author = try ui.Author.init(admin_moment, arena, md.author orelse ""), 248 .stats = if (repo_kind == .xit) try repo.commitStats(io, gpa, .{ .oid = &commit_object.oid }) else null, 249 }; 250 } 251 252 // an empty listing pinned to a ref, for the wasm / no-repo / unresolved paths. 253 pub fn emptyResult(aa: std.mem.Allocator, location: ui.RoutablePage.RepoLocation, ref_or_oid: ui.RoutablePage.RefOrOid, value: []const u8, content: ui.RoutablePage.RepoCommitsRoute.Content, base_oid: []const u8) !Self { 254 return .{ 255 .location = try location.dupe(aa), 256 .ref_or_oid = ref_or_oid, 257 .ref_or_oid_value = try aa.dupe(u8, value), 258 .base_oid = try aa.dupe(u8, base_oid), 259 .commit_count = null, 260 .commits = &.{}, 261 .next_start = null, 262 .content = try pageContent(aa, content), 263 }; 264 } 265 266 // the page's content for a route's, duped into `aa`. the diff window doesn't 267 // carry over: each commit holds the one its pane shows as `window.start`. 268 fn pageContent(aa: std.mem.Allocator, content: ui.RoutablePage.RepoCommitsRoute.Content) !Content { 269 return switch (content) { 270 .diff => |d| .{ .diff = .{ .path = try aa.dupe(u8, d.path.slice()) } }, 271 .message => .message, 272 }; 273 } 274 275 // render the window [start, start+len) of a commit's diff against its first 276 // parent into `arena`-owned hunks. start/has_more identify adjacent windows. 277 // a non-empty `path` filters to that file, so the window indexes its hunks. 278 fn renderCommitDiff( 279 comptime repo_kind: rp.RepoKind, 280 comptime repo_opts: rp.RepoOpts(repo_kind), 281 io: std.Io, 282 gpa: std.mem.Allocator, 283 arena: std.mem.Allocator, 284 repo: *rp.Repo(repo_kind, repo_opts), 285 oid: [xit.hash.hexLen(repo_opts.hash)]u8, 286 start: usize, 287 path: []const u8, 288 ) !Diff.Window { 289 const empty = Diff.Window{ .start = start }; 290 291 // load the commit so we can diff it against its first parent. 292 var commit_iter = repo.log(io, gpa, .{ .start_oids = &.{oid} }) catch return empty; 293 defer commit_iter.deinit(); 294 const commit_object = (commit_iter.next(gpa) catch return empty) orelse return empty; 295 defer commit_object.deinit(); 296 297 const parent_maybe = commit_object.content.commit.metadata.firstParent(); 298 299 return Diff.render(repo_kind, repo_opts, io, gpa, arena, repo, parent_maybe, oid, start, path); 300 } 301 302 // "YYYY-MM-DD" for a unix timestamp. 303 fn formatDate(arena: std.mem.Allocator, timestamp: u64) ![]const u8 { 304 const epoch_secs = std.time.epoch.EpochSeconds{ .secs = timestamp }; 305 const year_day = epoch_secs.getEpochDay().calculateYearDay(); 306 const month_day = year_day.calculateMonthDay(); 307 return std.fmt.allocPrint(arena, "{d:0>4}-{d:0>2}-{d:0>2}", .{ 308 year_day.year, 309 month_day.month.numeric(), 310 month_day.day_index + 1, 311 }); 312 } 313 314 // the commit message, trimmed and read into `aa`, plus whether its preview was 315 // cut short. 316 fn readMessage( 317 comptime repo_kind: rp.RepoKind, 318 comptime repo_opts: rp.RepoOpts(repo_kind), 319 aa: std.mem.Allocator, 320 commit_object: *xit.object.Object(repo_kind, repo_opts), 321 full_message: bool, 322 ) !struct { []const u8, bool } { 323 var message: std.ArrayList(u8) = .empty; 324 const byte_truncated = if (commit_object.readMessage(aa, &message, .limited(max_message_size))) |_| 325 false 326 else |err| switch (err) { 327 error.StreamTooLong => true, 328 else => |e| return e, 329 }; 330 const preview_end = if (full_message) null else ui.detailPreviewEnd(message.items); 331 const text = if (preview_end) |end| 332 message.items[0..end] 333 else if (byte_truncated) 334 trimIncompleteCodepoint(message.items) 335 else 336 message.items; 337 return .{ std.mem.trim(u8, text, " \t\r\n"), byte_truncated or preview_end != null }; 338 } 339 340 /// drop any incomplete UTF data from the end of a byte array 341 fn trimIncompleteCodepoint(bytes: []const u8) []const u8 { 342 var i = bytes.len; 343 while (i > 0 and bytes.len - i < 4) { 344 i -= 1; 345 const byte = bytes[i]; 346 if (byte & 0b1100_0000 == 0b1000_0000) continue; // continuation byte 347 const seq_len = std.unicode.utf8ByteSequenceLength(byte) catch return bytes; 348 return if (i + seq_len > bytes.len) bytes[0..i] else bytes; 349 } 350 return bytes; 351 } 352 353 // a focusable, word-wrapping box holding a commit message. `bottom_label` 354 // marks a message the page only shows part of ("" when it's whole). 355 fn messageBox(allocator: std.mem.Allocator, message: []const u8, bottom_label: []const u8) !wgt.TextBox { 356 var tb = try wgt.TextBox.init(allocator, message, .{ 357 .border_style = .single, 358 .rounded_corners = true, 359 .wrap_kind = .word, 360 .label = " message ", 361 .bottom_label = bottom_label, 362 }); 363 tb.getFocus().mode = .all; 364 return tb; 365 } 366 367 // the first line of a commit message, for the one-row list entries. 368 fn firstLine(message: []const u8) []const u8 { 369 const nl = std.mem.indexOfScalar(u8, message, '\n'); 370 return if (nl) |i| std.mem.trimEnd(u8, message[0..i], " \t\r") else message; 371 } 372 373 pub const View = struct { 374 // a vertical stack: the clone url row on top, then a horizontal 375 // split with the commit list on the left and a diff pane on the right 376 // showing the selected commit's diff. 377 box: wgt.Box(ui.Widget), // vert: [header_index] = clone url row, [content_index] = split 378 data: *const Self, 379 session: *ui.Session, 380 // the commit whose diff the pane currently shows (index into data.commits). 381 diffed_index: ?usize, 382 383 const header_index: usize = 0; 384 const content_index: usize = 1; 385 // indices within the content box (the horizontal split). 386 const list_index: usize = 0; 387 const diff_index: usize = 1; 388 const list_max_width: usize = 35; 389 const diff_min_width: usize = 40; 390 391 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 392 var outer = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 393 errdefer outer.deinit(allocator); 394 395 // the search box and the clone url at the top. 396 { 397 var header_view = try ui.widget.SearchHeader.init(allocator, session, data.location, " search ", "search", data.search, data.search_available); 398 errdefer header_view.deinit(allocator); 399 try outer.children.put(allocator, header_view.getFocus().id, .{ .widget = .{ .search_header = header_view }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 400 } 401 402 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 403 errdefer box.deinit(allocator); 404 405 // the commit list (one focusable row each), plus a "next" link 406 { 407 var list_scroll = blk: { 408 var list_box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert, .stretch = true }); 409 errdefer list_box.deinit(allocator); 410 for (data.commits, 0..) |commit, index| { 411 // an in-page "ai:" anchor so a commit row is clickable with 412 // js off (the browser follows it, rooting the list there); 413 // with wasm the click just selects it and swaps the diff pane. 414 const content = if (index == 0) data.content else Content{ .diff = .{} }; 415 try addRow(allocator, &list_box, firstLine(commit.message), try commitRowLink(session.page_arena, data, commit, content)); 416 } 417 if (data.next_start) |next| { 418 try addRow(allocator, &list_box, "next →", try nextPageLink(session.page_arena, data, next)); 419 } 420 if (list_box.children.count() > 0) list_box.getFocus().child_id = list_box.children.keys()[0]; 421 break :blk try wgt.Scroll(ui.Widget).init(allocator, .{ .box = list_box }, .{ .direction = .vert, .web_native = !session.is_terminal, .fill = true }); 422 }; 423 errdefer list_scroll.deinit(allocator); 424 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 } }); 425 } 426 427 // the diff pane — a frame around a scroll of the hunks 428 { 429 var diff_outer = blk: { 430 var diff_scroll = try Diff.View.initEmpty(allocator, session); 431 errdefer diff_scroll.deinit(allocator); 432 var frame = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = .hidden, .direction = .vert }); 433 errdefer frame.deinit(allocator); 434 // the frame's selected child is its scroll, so the focus chain 435 // reaches a hunk (populateDiff points the scroll's inner box at 436 // one), letting focus recovery descend into the diff pane after 437 // it's laid out beside a too-narrow list. 438 frame.getFocus().child_id = diff_scroll.getFocus().id; 439 try frame.children.put(allocator, diff_scroll.getFocus().id, .{ .widget = .{ .diff_view = diff_scroll }, .rect = null, .min_size = null }); 440 break :blk frame; 441 }; 442 errdefer diff_outer.deinit(allocator); 443 diff_outer.getFocus().mode = .mouse; 444 try box.children.put(allocator, diff_outer.getFocus().id, .{ .widget = .{ .box = diff_outer }, .rect = null, .min_size = .{ .width = diff_min_width, .height = null } }); 445 } 446 447 box.getFocus().child_id = box.children.keys()[list_index]; 448 try outer.children.put(allocator, box.getFocus().id, .{ .widget = .{ .box = box }, .rect = null, .min_size = null }); 449 450 // focus lives in the split, except that search results start in the 451 // search box so the query can be refined right away. 452 outer.getFocus().child_id = outer.children.keys()[if (data.search != null) header_index else content_index]; 453 454 return .{ 455 .box = outer, 456 .data = data, 457 .session = session, 458 .diffed_index = null, 459 }; 460 } 461 462 fn addRow(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, link: []const u8) !void { 463 var row = try wgt.TextBox.init(allocator, label, .{ .border_style = .hidden, .rounded_corners = true, .wrap_kind = .word }); 464 errdefer row.deinit(allocator); 465 row.getFocus().mode = .all; 466 if (link.len != 0) row.getFocus().kind = .{ .custom = link }; 467 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .text_box = row }, .rect = null, .min_size = null, .max_size = .{ .width = null, .height = 5 } }); 468 } 469 470 // a focusable window-navigation row ("previous"/"next"). it's a link to this 471 // commit's route at `target_start`, so activating it (the host follows the 472 // "a:" link) reloads the page on the adjacent window — same on TUI and web. 473 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 { 474 const link = try commitsLink(self.session.page_arena, self.data, oid, target_start, path); 475 var tb = try wgt.TextBox.init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 476 errdefer tb.deinit(allocator); 477 tb.getFocus().mode = .all; 478 tb.getFocus().kind = .{ .custom = link }; 479 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 480 } 481 482 // a focusable row for the top of the diff pane linking to the files tab at 483 // this commit's tree, so its files are always viewable as of this object. 484 fn addViewFilesLink(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), oid: []const u8) !void { 485 const link = try filesObjectLink(self.session.page_arena, self.data.location, oid); 486 var tb = try wgt.TextBox.init(allocator, "view files at this commit", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 487 errdefer tb.deinit(allocator); 488 tb.getFocus().mode = .all; 489 tb.getFocus().kind = .{ .custom = link }; 490 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 491 } 492 493 // how much of the message a pane's box holds: a truncated preview links to 494 // the pane holding the whole thing, which is that link's destination. 495 const MessageBox = enum { preview, whole }; 496 497 // the selected commit's message. 498 fn addMessageBox(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), commit: Commit, kind: MessageBox) !void { 499 // a truncated message keeps its box even with no whole line to show, 500 // since the box is what links to the whole thing. 501 if (commit.message.len == 0 and !commit.message_truncated) return; 502 const cut_short = commit.message_truncated and kind == .preview; 503 var tb = try messageBox(allocator, commit.message, if (cut_short) " click or press enter to see more " else ""); 504 errdefer tb.deinit(allocator); 505 if (cut_short) tb.getFocus().kind = .{ .custom = try messageLink(self.session.page_arena, self.data, commit.oid) }; 506 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 507 } 508 509 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 510 self.box.deinit(allocator); 511 } 512 513 fn contentBox(self: *View) *wgt.Box(ui.Widget) { 514 return &self.box.children.values()[content_index].widget.box; 515 } 516 517 fn header(self: *View) *ui.widget.SearchHeader { 518 return &self.box.children.values()[header_index].widget.search_header; 519 } 520 521 fn headerActive(self: *View) bool { 522 return self.box.getFocus().child_id == self.header().getFocus().id; 523 } 524 525 fn listScroll(self: *View) *wgt.Scroll(ui.Widget) { 526 return &self.contentBox().children.values()[list_index].widget.scroll; 527 } 528 529 fn listBox(self: *View) *wgt.Box(ui.Widget) { 530 return &self.listScroll().child.box; 531 } 532 533 fn diffOuter(self: *View) *wgt.Box(ui.Widget) { 534 return &self.contentBox().children.values()[diff_index].widget.box; 535 } 536 537 fn diffScroll(self: *View) *wgt.Scroll(ui.Widget) { 538 return &self.diffOuter().children.values()[0].widget.diff_view.scroll; 539 } 540 541 fn diffInner(self: *View) *wgt.Box(ui.Widget) { 542 return &self.diffScroll().child.box; 543 } 544 545 fn diffActive(self: *View) bool { 546 const content = self.contentBox(); 547 const cid = content.getFocus().child_id orelse return false; 548 return content.children.getIndex(cid) == diff_index; 549 } 550 551 // what the pane shows for the commit at `sel`. the page's content only 552 // applies to the commit it walks from; the rest show their plain diff. 553 fn paneContent(self: *View, sel: usize) Self.Content { 554 return if (sel == 0) self.data.content else .{ .diff = .{} }; 555 } 556 557 // the selected commit's index, or null when the "next" row is selected. 558 fn selectedCommitIndex(self: *View) ?usize { 559 const lb = self.listBox(); 560 const cid = lb.getFocus().child_id orelse return null; 561 const idx = lb.children.getIndex(cid) orelse return null; 562 if (idx >= self.data.commits.len) return null; 563 return idx; 564 } 565 566 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 567 self.clearGrid(); 568 569 // swap the diff pane to the selected commit when it changes. 570 try self.refreshDiff(allocator); 571 572 // the selected list row shows a border (the focused TextBox upgrades it 573 // to a double border itself); the rest stay borderless. 574 const lb = self.listBox(); 575 for (lb.children.keys(), lb.children.values()) |id, *child| { 576 switch (child.widget) { 577 .text_box => |*tb| tb.options.border_style = if (lb.getFocus().child_id == id) .single else .hidden, 578 else => {}, 579 } 580 } 581 582 // cap the list at list_max_width only while the diff pane fits beside it. 583 // the box drops the diff when the width can't hold both minimums, so when 584 // it's that narrow we lift the cap and let the list fill the whole width. 585 const both_panes_fit = if (constraint.max_size.width) |w| w >= list_max_width + diff_min_width else true; 586 self.contentBox().children.values()[list_index].max_size = if (both_panes_fit) .{ .width = list_max_width, .height = null } else null; 587 588 // stretch the diff pane across the rest of the width so it fills the area 589 // rather than shrinking to its content; its scroll fills the pane. when 590 // too narrow for both, it fills the whole width. 591 const diff_width: usize = if (constraint.max_size.width) |w| 592 (if (both_panes_fit) w - list_max_width else w) 593 else 594 diff_min_width; 595 self.contentBox().children.values()[diff_index].min_size = .{ .width = diff_width, .height = null }; 596 597 // the message is the pane's only wrapping row, and wrapping needs a 598 // bounded width, which the pane's scroll doesn't grant (it scrolls 599 // horizontally too). cap it to the pane, leaving room for the border 600 // and the scrollbar column. re-capped each build so it tracks resizes. 601 for (self.diffInner().children.values()) |*child| switch (child.widget) { 602 .text_box => |text_box| if (text_box.options.wrap_kind == .word) { 603 child.max_size = .{ .width = diff_width -| 3, .height = null }; 604 }, 605 else => {}, 606 }; 607 608 // the web bounds the layout to the browser viewport like the terminal; 609 // each Scroll's web-native mode hands its full content to a real 610 // scrollable element, so we no longer build unbounded here. 611 // 612 // crossing panes only re-selects the content box's child (focusDiff / 613 // focusList); when the window is too narrow to show both, the pane that 614 // held focus is dropped here. the framework recovers focus after the 615 // top-level build by re-deriving it down the selected-child chain, so 616 // there's nothing to fix up afterward. 617 try self.box.build(allocator, constraint, root_focus); 618 } 619 620 fn refreshDiff(self: *View, allocator: std.mem.Allocator) !void { 621 const sel = self.selectedCommitIndex() orelse return; 622 if (self.diffed_index) |d| if (d == sel) return; 623 try self.populateDiff(allocator, sel); 624 self.diffed_index = sel; 625 } 626 627 fn populateDiff(self: *View, allocator: std.mem.Allocator, sel: usize) !void { 628 const commit = self.data.commits[sel]; 629 const inner = self.diffInner(); 630 631 for (inner.children.values()) |*child| child.widget.deinit(allocator); 632 inner.children.clearAndFree(allocator); 633 inner.getFocus().child_id = null; 634 635 switch (self.paneContent(sel)) { 636 .message => { 637 try self.addNavLink(allocator, inner, "← back to diff", commit.oid, 0, ""); 638 try self.addMessageBox(allocator, inner, commit, .whole); 639 }, 640 .diff => |d| { 641 if (d.path.len == 0) { 642 try self.addMessageBox(allocator, inner, commit, .preview); 643 if (commit.author != .unknown) { 644 var tb = try ui.authorBox(allocator, self.session.page_arena, commit.author); 645 errdefer tb.deinit(allocator); 646 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 647 } 648 if (commit.stats) |stats| { 649 var text: std.Io.Writer.Allocating = .init(allocator); 650 defer text.deinit(); 651 try text.writer.print("lines changed: {d}", .{stats.lines_added + stats.lines_changed}); 652 if (stats.lines_removed != 0) try text.writer.print("\nlines removed: {d}", .{stats.lines_removed}); 653 const bytes_added = stats.bytes_added >= stats.bytes_removed; 654 const bytes = if (bytes_added) stats.bytes_added - stats.bytes_removed else stats.bytes_removed - stats.bytes_added; 655 try text.writer.print("\nbytes {s}: {d}\nfiles changed: {d}", .{ 656 if (bytes_added) "added" else "removed", bytes, stats.files_added + stats.files_changed, 657 }); 658 if (stats.files_removed != 0) try text.writer.print("\nfiles removed: {d}", .{stats.files_removed}); 659 var tb = try wgt.TextBox.init(allocator, text.written(), .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none, .label = " stats " }); 660 errdefer tb.deinit(allocator); 661 tb.getFocus().mode = .all; 662 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 663 } 664 try self.addViewFilesLink(allocator, inner, commit.oid); 665 } 666 667 try (Diff{ 668 .route = .{ .commit = .{ .location = self.data.location, .oid = commit.oid, .base_oid = self.data.base_oid } }, 669 .path = d.path, 670 .window = commit.window, 671 }).appendWindow(allocator, self.session, inner); 672 }, 673 } 674 675 // point the pane at its first row so focus recovery can land here. 676 if (inner.children.count() > 0) inner.getFocus().child_id = inner.children.keys()[0]; 677 678 // reset the scroll to the top for the newly-shown commit: directly on the 679 // terminal (the wasm offset), and via a version bump on the web (so the 680 // renderer's scroll id changes and JS drops the preserved position). 681 const sc = self.diffScroll(); 682 sc.x = 0; 683 sc.y = 0; 684 sc.getFocus().version +%= 1; 685 } 686 687 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 688 if (self.headerActive()) { 689 if (key == .arrow_down) { 690 root_focus.setFocus(self.contentBox().getFocus().id); 691 return; 692 } 693 if (key == .enter) if (try self.header().submittedText(allocator)) |text| { 694 defer allocator.free(text); 695 return self.submit(text); 696 }; 697 return self.header().input(allocator, key, root_focus); 698 } 699 if (key == .arrow_up and self.contentAtTop() and self.header().focusHeader(root_focus)) return; 700 if (self.diffActive()) { 701 if (key == .arrow_left and self.diffScroll().x == 0) { 702 self.focusList(root_focus); 703 } else { 704 try self.diffOuter().children.values()[0].widget.diff_view.input(allocator, key, root_focus); 705 } 706 } else { 707 try self.listInput(key, root_focus); 708 } 709 } 710 711 // navigate to the typed query's results, pinned to the list's ref. an 712 // empty query leaves the results for the plain log. 713 fn submit(self: *View, text: []const u8) !void { 714 if (text.len == 0 and self.data.search == null) return; 715 const route = self.data.location.commitsRoute(self.data.ref_or_oid, self.data.ref_or_oid_value, 0, "", self.data.base_oid) orelse return; 716 try self.session.navigate(route.withSearch(text) orelse return); 717 } 718 719 fn listInput(self: *View, key: Key, root_focus: *Focus) !void { 720 // up/down (and the scroll wheel) move the selection a row; page up/down 721 // jump a fixed amount. right/Enter cross into the diff pane. Enter/clicks 722 // on the "next" row become navigation in the host before reaching here. 723 if (inp.rowDelta(key, @intCast(self.listBox().children.count()))) |delta| { 724 ui.widget.moveRowFocus(self.listBox(), self.listScroll(), root_focus, delta); 725 return; 726 } 727 switch (key) { 728 .enter => if (self.selectedCommitIndex() != null) 729 self.focusDiff(root_focus) 730 else if (self.data.next_start) |next| { 731 if (pageRoute(self.data, next)) |route| try self.session.navigate(route); 732 }, 733 .arrow_right => self.focusDiff(root_focus), 734 else => {}, 735 } 736 } 737 738 // enter the diff pane. the host arrives here on right-arrow or Enter from the 739 // list. a diff with no rows can't be entered. setFocus handles the too-narrow 740 // case where the pane isn't laid out yet (it gets selected, then focused after 741 // the next build, landing on its remembered hunk). 742 fn focusDiff(self: *View, root_focus: *Focus) void { 743 if (self.diffInner().children.count() == 0) return; 744 root_focus.setFocus(self.diffOuter().getFocus().id); 745 } 746 747 // return to the list. 748 fn focusList(self: *View, root_focus: *Focus) void { 749 root_focus.setFocus(self.listScroll().getFocus().id); 750 } 751 752 pub fn clearGrid(self: *View) void { 753 self.box.clearGrid(); 754 } 755 756 pub fn getGrid(self: View) ?Grid { 757 return self.box.getGrid(); 758 } 759 760 pub fn getFocus(self: *View) *Focus { 761 return self.box.getFocus(); 762 } 763 764 fn contentAtTop(self: *View) bool { 765 if (self.diffActive()) { 766 const inner = self.diffInner(); 767 const cid = inner.getFocus().child_id orelse return true; 768 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 769 return first_focused and self.diffScroll().y == 0; 770 } 771 const lb = self.listBox(); 772 const cid = lb.getFocus().child_id orelse return true; 773 return lb.children.getIndex(cid) == 0; 774 } 775 776 // only the header's own row sits directly below the repository header. 777 pub fn atTop(self: *View) bool { 778 return self.headerActive() or (!self.header().hasFocusable() and self.contentAtTop()); 779 } 780 781 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 782 return self.header().focusHeader(root_focus); 783 } 784 }; 785 786 // the "a:" navigation link for the commits page walking from commit `oid` within 787 // `data.location`, windowing the selected commit's diff from hunk `start`, filtered 788 // to `path` ("" = every file). 789 fn commitsLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8, start: usize, path: []const u8) ![]const u8 { 790 const route = data.location.commitsRoute(.object, oid, start, path, data.base_oid) orelse return error.RouteTooLong; 791 const url = try route.toUrl(page_arena); 792 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 793 } 794 795 // this list's page starting at `oid`: a repo's branch or tag keeps its ref (and 796 // its query) and moves `from` along, so the search box survives paging. a fork 797 // or an object view roots the page at the commit itself. 798 fn pageRoute(data: *const Self, oid: []const u8) ?ui.RoutablePage { 799 if (data.location != .repo or data.ref_or_oid == .object) { 800 return data.location.commitsRoute(.object, oid, 0, "", data.base_oid); 801 } 802 const route = data.location.commitsRoute(data.ref_or_oid, data.ref_or_oid_value, 0, "", data.base_oid) orelse return null; 803 const paged = route.withFrom(oid) orelse return null; 804 return paged.withSearch(data.search orelse return paged); 805 } 806 807 fn nextPageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 808 const route = pageRoute(data, oid) orelse return error.RouteTooLong; 809 const url = try route.toUrl(page_arena); 810 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 811 } 812 813 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 814 // directory, within `location`. 815 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 816 const route = location.filesRoute(.object, oid, "", 0) orelse return error.RouteTooLong; 817 const url = try route.toUrl(page_arena); 818 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 819 } 820 821 // the in-page "ai:" anchor for selecting a commit with its current pane content 822 // and window. the href is only followed with js off. 823 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, commit: Commit, content: Content) ![]const u8 { 824 // a result roots the same results page at its commit, so the query 825 // survives following the row 826 if (data.search != null) { 827 const route = pageRoute(data, commit.oid) orelse return error.RouteTooLong; 828 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{try route.toUrl(page_arena)}); 829 } 830 const route = (switch (content) { 831 .message => data.location.commitMessageRoute(.object, commit.oid, data.base_oid), 832 .diff => |diff| data.location.commitsRoute(.object, commit.oid, commit.window.start, diff.path, data.base_oid), 833 }) orelse return error.RouteTooLong; 834 const url = try route.toUrl(page_arena); 835 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 836 } 837 838 // the "a:" link to the page showing `oid`'s message on its own. 839 fn messageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 840 const route = data.location.commitMessageRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 841 const url = try route.toUrl(page_arena); 842 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 843 } 844