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