╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Events.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
81 else if (repo_kind == .git) 82 return result 83 else 84 evt.currentMoment(repo_opts, repo)) catch { 85 if (require_selected_event) return error.NotFound; 86 return result; 87 }; 88 89 const kind_map_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.event_index_key)) orelse { 90 if (require_selected_event) return error.NotFound; 91 return result; 92 }; 93 const kind_map = try DB.HashMap(.read_only).init(kind_map_cursor); 94 95 const active_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.active_event_id_set_key)); 96 const removed_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.removed_event_id_set_key)); 97 98 var root_key: ?[@sizeOf(u64) + evt.event_id_size]u8 = null; 99 if (selected.len != 0) { 100 var id: [evt.event_id_size]u8 = undefined; 101 _ = std.fmt.hexToBytes(&id, selected) catch return error.NotFound; 102 if (!std.mem.eql(u8, selected, &std.fmt.bytesToHex(id, .lower))) return error.NotFound; 103 const kind = selected_kind orelse return error.NotFound; 104 const stored_kind = (try evt.readEventKind(repo_opts.hash, kind_map, &id)) orelse return error.NotFound; 105 if (stored_kind != kind) return error.NotFound; 106 result.selected = .{ .id = try aa.dupe(u8, selected), .kind = kind }; 107 const meta = try readMeta(repo_opts.hash, arena, haxy_moment, kind, &id); 108 result.view = if (meta.removed) .removed else .active; 109 root_key = evt.orderKeyDesc(meta.updated_order, &id); 110 } 111 112 if (moment_index != null) { 113 try readMomentEvents(repo_kind, repo_opts, arena, &result, haxy_moment, kind_map, admin_moment, identity, selected); 114 return result; 115 } 116 117 for ([_]ui.RoutablePage.EventsView{ .active, .removed }) |view| { 118 const id_set_cursor = switch (view) { 119 .active => active_cursor, 120 .removed => removed_cursor, 121 }; 122 const event_window = switch (view) { 123 .active => &result.active, 124 .removed => &result.removed, 125 }; 126 const id_set = try DB.SortedSet(.read_only).init(id_set_cursor orelse { 127 if (require_selected_event and result.view == view) return error.NotFound; 128 continue; 129 }); 130 event_window.count = @intCast(try id_set.count()); 131 const selected_key = if (result.view == view) root_key else null; 132 if (selected_key) |*key| if (!try id_set.contains(key)) return error.NotFound; 133 134 var iter = if (selected_key) |*key| try id_set.iteratorFrom(key) else try id_set.iteratorFromIndex(0); 135 var events: std.ArrayList(Item) = .empty; 136 while (try iter.next()) |cursor_value| { 137 const id = try evt.readOrderKeyId(DB, cursor_value); 138 const kind = (try evt.readEventKind(repo_opts.hash, kind_map, &id)) orelse continue; 139 if (events.items.len == page_size) { 140 event_window.next = .{ .id = try formatId(aa, &id), .kind = kind }; 141 break; 142 } 143 const item = (try readItem(repo_opts.hash, arena, haxy_moment, kind_map, admin_moment, identity, view == .active, kind, &id)) orelse continue; 144 try events.append(aa, item); 145 } 146 event_window.events = events.items; 147 } 148 return result; 149 } 150 151 // the haxy state as of one transaction in the repo history. a moment page 152 // reads from it, so undoing or rebasing later transactions cannot change what 153 // it shows, and the events read as they were when the transaction ran 154 fn transactionMoment( 155 comptime repo_kind: rp.RepoKind, 156 comptime repo_opts: rp.RepoOpts(repo_kind), 157 repo: *rp.Repo(repo_kind, repo_opts), 158 index: u64, 159 ) !evt.EventDB(repo_opts.hash).HashMap(.read_only) { 160 if (repo_kind == .git) return error.NotFound; 161 return try evt.currentMomentFromRepoMoment(repo_opts.hash, try repo.core.momentAt(index)); 162 } 163 164 // the moment's set is keyed on the event order, not the update order the 165 // active and removed sets use, so it gets its own walk. one transaction's 166 // events are few, so the whole set is scanned to count both views. 167 fn readMomentEvents( 168 comptime repo_kind: rp.RepoKind, 169 comptime repo_opts: rp.RepoOpts(repo_kind), 170 arena: *std.heap.ArenaAllocator, 171 result: *Self, 172 haxy_moment: evt.EventDB(repo_opts.hash).HashMap(.read_only), 173 kind_map: evt.EventDB(repo_opts.hash).HashMap(.read_only), 174 admin_moment: ?evt.AdminDB.HashMap(.read_only), 175 identity: []const u8, 176 selected: []const u8, 177 ) !void { 178 const DB = evt.EventDB(repo_opts.hash); 179 const aa = arena.allocator(); 180 // the moment names its own position, so the page needs no index from the 181 // url. a transaction that consumed nothing has no set of its own, which 182 // leaves the list empty rather than failing the page: the terminal hosts 183 // build their pages inside the run loop, where an error ends the session 184 const index_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.moment_index_key)) orelse return; 185 const ids = try evt.momentEventIds(DB, repo_opts.hash, haxy_moment, try index_cursor.readUint()) orelse return; 186 187 var events: [2]std.ArrayList(Item) = .{ .empty, .empty }; 188 // the selected event's window starts at it, not at the top 189 var awaiting_selected = selected.len != 0; 190 191 var iter = try ids.iterator(); 192 while (try iter.next()) |cursor_value| { 193 const id = try evt.readOrderKeyId(DB, cursor_value); 194 const kind = (try evt.readEventKind(repo_opts.hash, kind_map, &id)) orelse continue; 195 const meta = try readMeta(repo_opts.hash, arena, haxy_moment, kind, &id); 196 const view: ui.RoutablePage.EventsView = if (meta.removed) .removed else .active; 197 const event_window = switch (view) { 198 .active => &result.active, 199 .removed => &result.removed, 200 }; 201 event_window.count += 1; 202 if (awaiting_selected and view == result.view) { 203 if (!std.mem.eql(u8, selected, &std.fmt.bytesToHex(id, .lower))) continue; 204 awaiting_selected = false; 205 } 206 const window_events = &events[@intFromEnum(view)]; 207 if (window_events.items.len == page_size) { 208 if (event_window.next == null) event_window.next = .{ .id = try formatId(aa, &id), .kind = kind }; 209 continue; 210 } 211 const item = (try readItem(repo_opts.hash, arena, haxy_moment, kind_map, admin_moment, identity, view == .active, kind, &id)) orelse continue; 212 try window_events.append(aa, item); 213 } 214 // the window start can name an event this batch no longer holds 215 if (awaiting_selected) return; 216 result.active.events = events[@intFromEnum(ui.RoutablePage.EventsView.active)].items; 217 result.removed.events = events[@intFromEnum(ui.RoutablePage.EventsView.removed)].items; 218 } 219 220 pub fn empty(aa: std.mem.Allocator, identity: []const u8, view: ui.RoutablePage.EventsView, local: bool, failure: ?[]const u8) !Self { 221 return .{ 222 .identity = try aa.dupe(u8, identity), 223 .view = view, 224 .selected = null, 225 .active = .{}, 226 .removed = .{}, 227 .header = if (local) try Header.empty(aa, failure) else Header.remote(), 228 }; 229 } 230 231 fn window(self: *const Self, view: ui.RoutablePage.EventsView) *const Window { 232 return switch (view) { 233 .active => &self.active, 234 .removed => &self.removed, 235 }; 236 } 237 238 fn formatId(aa: std.mem.Allocator, id: *const [evt.event_id_size]u8) ![]const u8 { 239 const hex = std.fmt.bytesToHex(id.*, .lower); 240 return try aa.dupe(u8, &hex); 241 } 242 243 const EventMeta = struct { 244 updated_order: u64, 245 removed: bool, 246 }; 247 248 fn readMeta( 249 comptime hash_kind: hash.HashKind, 250 arena: *std.heap.ArenaAllocator, 251 haxy_moment: evt.EventDB(hash_kind).HashMap(.read_only), 252 kind: evt.EventKind, 253 id: *const [evt.event_id_size]u8, 254 ) !EventMeta { 255 return switch (kind) { 256 inline else => |event_kind| blk: { 257 const T = switch (event_kind) { 258 .user => evt.User, 259 .repo => evt.Repo, 260 .fork => evt.Fork, 261 .issue => evt.Issue, 262 .discuss => evt.Discussion, 263 .comment => evt.Comment, 264 .attach => evt.Attachment, 265 .patchrev => evt.PatchRev, 266 .patch => evt.Patch, 267 }; 268 break :blk (try evt.readRecordSubset(T, EventMeta, evt.EventDB(hash_kind), hash_kind, haxy_moment, arena, id)) orelse return error.NotFound; 269 }, 270 }; 271 } 272 273 fn readItem( 274 comptime hash_kind: hash.HashKind, 275 arena: *std.heap.ArenaAllocator, 276 haxy_moment: evt.EventDB(hash_kind).HashMap(.read_only), 277 kind_map: evt.EventDB(hash_kind).HashMap(.read_only), 278 admin_moment: ?evt.AdminDB.HashMap(.read_only), 279 identity: []const u8, 280 include_view_url: bool, 281 kind: evt.EventKind, 282 id: *const [evt.event_id_size]u8, 283 ) !?Item { 284 const DB = evt.EventDB(hash_kind); 285 // the parts of a record a row shows 286 const Authored = struct { author_email: ?[]const u8 }; 287 const Owned = struct { event: struct { user_id: []const u8 } }; 288 var item: Item = .{ 289 .id = try formatId(arena.allocator(), id), 290 .kind = kind, 291 .author = .unknown, 292 }; 293 switch (kind) { 294 .user => { 295 const record = (try evt.readRecordSubset(evt.User, struct { event: struct { email: []const u8 } }, DB, hash_kind, haxy_moment, arena, id)) orelse return null; 296 item.author = try ui.Author.initFromEmail(admin_moment, arena, record.event.email); 297 }, 298 .repo => { 299 const record = (try evt.readRecordSubset(evt.Repo, Owned, DB, hash_kind, haxy_moment, arena, id)) orelse return null; 300 if (admin_moment) |moment| { 301 if (try evt.User.readById(evt.AdminDB, evt.admin_repo_opts.hash, moment, arena, record.event.user_id)) |user| 302 item.author = .{ .user_name = user.event.name }; 303 } 304 }, 305 .fork => { 306 const record = (try evt.readRecordSubset(evt.Fork, Owned, DB, hash_kind, haxy_moment, arena, id)) orelse return null; 307 if (admin_moment) |moment| { 308 if (try evt.User.readById(evt.AdminDB, evt.admin_repo_opts.hash, moment, arena, record.event.user_id)) |user| 309 item.author = .{ .user_name = user.event.name }; 310 } 311 }, 312 .issue => { 313 const record = (try evt.readRecordSubset(evt.Issue, Authored, DB, hash_kind, haxy_moment, arena, id)) orelse return null; 314 item.author = try ui.Author.initFromEmail(admin_moment, arena, record.author_email); 315 if (!include_view_url) return item; 316 const route = ui.RoutablePage.repoThreadCommentsRoute(.issue, identity, item.id, 0) orelse return error.RouteTooLong; 317 item.view_url = try route.toUrl(arena); 318 }, 319 .discuss => { 320 const record = (try evt.readRecordSubset(evt.Discussion, Authored, DB, hash_kind, haxy_moment, arena, id)) orelse return null; 321 item.author = try ui.Author.initFromEmail(admin_moment, arena, record.author_email); 322 if (!include_view_url) return item; 323 const route = ui.RoutablePage.repoThreadCommentsRoute(.discuss, identity, item.id, 0) orelse return error.RouteTooLong; 324 item.view_url = try route.toUrl(arena); 325 }, 326 .comment => { 327 const record = (try evt.readRecordSubset(evt.Comment, struct { author_email: ?[]const u8, event: struct { thread_id: [evt.event_id_size * 2]u8 } }, DB, hash_kind, haxy_moment, arena, id)) orelse return null; 328 item.author = try ui.Author.initFromEmail(admin_moment, arena, record.author_email); 329 if (!include_view_url) return item; 330 var thread_id: [evt.event_id_size]u8 = undefined; 331 _ = std.fmt.hexToBytes(&thread_id, &record.event.thread_id) catch return error.InvalidEventId; 332 const thread_kind = (try evt.readEventKind(hash_kind, kind_map, &thread_id)) orelse return item; 333 const route = ui.RoutablePage.repoThreadCommentRoute(thread_kind, identity, &record.event.thread_id, item.id, 0) orelse return item; 334 item.view_url = try route.toUrl(arena); 335 }, 336 .attach => { 337 const record = (try evt.readRecordSubset(evt.Attachment, struct { author_email: ?[]const u8, event: struct { parent_id: [evt.event_id_size * 2]u8 } }, DB, hash_kind, haxy_moment, arena, id)) orelse return null; 338 item.author = try ui.Author.initFromEmail(admin_moment, arena, record.author_email); 339 if (!include_view_url) return item; 340 var parent_id: [evt.event_id_size]u8 = undefined; 341 _ = std.fmt.hexToBytes(&parent_id, &record.event.parent_id) catch return error.InvalidEventId; 342 const parent_kind = (try evt.readEventKind(hash_kind, kind_map, &parent_id)) orelse return item; 343 const route = ui.RoutablePage.repoThreadCommentsRoute(parent_kind, identity, &record.event.parent_id, 0) orelse return item; 344 item.view_url = try route.toUrl(arena); 345 }, 346 .patch => { 347 const record = (try evt.readRecordSubset(evt.Patch, Authored, DB, hash_kind, haxy_moment, arena, id)) orelse return null; 348 item.author = try ui.Author.initFromEmail(admin_moment, arena, record.author_email); 349 if (!include_view_url) return item; 350 const route = ui.RoutablePage.repoThreadCommentsRoute(.patch, identity, item.id, 0) orelse return error.RouteTooLong; 351 item.view_url = try route.toUrl(arena); 352 }, 353 .patchrev => { 354 const record = (try evt.readRecordSubset(evt.PatchRev, Authored, DB, hash_kind, haxy_moment, arena, id)) orelse return null; 355 item.author = try ui.Author.initFromEmail(admin_moment, arena, record.author_email); 356 }, 357 } 358 return item; 359 } 360 361 pub const View = struct { 362 box: wgt.Box(ui.Widget), 363 data: *const Self, 364 session: *ui.Session, 365 detailed_index: [2]?usize, 366 367 const header_index = 0; 368 const content_index = 1; 369 const list_index = 0; 370 const detail_index = 1; 371 const list_max_width = 20; 372 const detail_min_width = 40; 373 374 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 375 var outer = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 376 errdefer outer.deinit(allocator); 377 378 var header_view = try Header.View.init(allocator, data, session); 379 errdefer header_view.deinit(allocator); 380 // a row taller than the header, leaving a blank line beneath it 381 try outer.children.put(allocator, header_view.getFocus().id, .{ .widget = .{ .repo_events_header = header_view }, .rect = null, .min_size = .{ .width = null, .height = 4 } }); 382 383 var content_stack = try wgt.Stack(ui.Widget).init(allocator); 384 errdefer content_stack.deinit(allocator); 385 inline for ([_]ui.RoutablePage.EventsView{ .active, .removed }) |view| { 386 var content_box = try initContent(allocator, data, session, view); 387 errdefer content_box.deinit(allocator); 388 try content_stack.children.put(allocator, content_box.getFocus().id, .{ .box = content_box }); 389 } 390 content_stack.getFocus().child_id = content_stack.children.keys()[@intFromEnum(data.view)]; 391 try outer.children.put(allocator, content_stack.getFocus().id, .{ .widget = .{ .stack = content_stack }, .rect = null, .min_size = null }); 392 outer.getFocus().child_id = outer.children.keys()[content_index]; 393 return .{ .box = outer, .data = data, .session = session, .detailed_index = .{ null, null } }; 394 } 395 396 fn initContent(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session, view: ui.RoutablePage.EventsView) !wgt.Box(ui.Widget) { 397 var content_box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 398 errdefer content_box.deinit(allocator); 399 400 var list_box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert, .stretch = true }); 401 errdefer list_box.deinit(allocator); 402 const event_window = data.window(view); 403 for (event_window.events) |event| { 404 const route = ui.RoutablePage.repoEventsRoute(data.identity, view, event.kind, event.id, data.moment) orelse return error.RouteTooLong; 405 const link = try std.fmt.allocPrint(session.page_arena.allocator(), "ai:{s}", .{try route.toUrl(session.page_arena)}); 406 try addRow(allocator, &list_box, @tagName(event.kind), link); 407 } 408 if (event_window.next) |next| { 409 const route = ui.RoutablePage.repoEventsRoute(data.identity, view, next.kind, next.id, data.moment) orelse return error.RouteTooLong; 410 const link = try std.fmt.allocPrint(session.page_arena.allocator(), "a:{s}", .{try route.toUrl(session.page_arena)}); 411 try addRow(allocator, &list_box, "next →", link); 412 } 413 if (list_box.children.count() > 0) list_box.getFocus().child_id = list_box.children.keys()[0]; 414 var list_scroll = try wgt.Scroll(ui.Widget).init(allocator, .{ .box = list_box }, .{ .direction = .vert, .web_native = !session.is_terminal, .fill = true }); 415 errdefer list_scroll.deinit(allocator); 416 try content_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 } }); 417 418 var detail_box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 419 errdefer detail_box.deinit(allocator); 420 var detail_scroll = try wgt.Scroll(ui.Widget).init(allocator, .{ .box = detail_box }, .{ .direction = .vert, .web_native = !session.is_terminal, .fill = true }); 421 errdefer detail_scroll.deinit(allocator); 422 detail_scroll.getFocus().mode = .mouse; 423 try content_box.children.put(allocator, detail_scroll.getFocus().id, .{ .widget = .{ .scroll = detail_scroll }, .rect = null, .min_size = .{ .width = detail_min_width, .height = null } }); 424 425 content_box.getFocus().child_id = content_box.children.keys()[list_index]; 426 return content_box; 427 } 428 429 fn addRow(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), text: []const u8, link: []const u8) !void { 430 var row = try wgt.TextBox.init(allocator, text, .{ .border_style = .hidden, .round_corners = true, .wrap_kind = .none }); 431 errdefer row.deinit(allocator); 432 row.getFocus().mode = .all; 433 row.getFocus().kind = .{ .custom = link }; 434 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .text_box = row }, .rect = null, .min_size = null }); 435 } 436 437 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 438 self.box.deinit(allocator); 439 } 440 441 fn header(self: *View) *Header.View { 442 return &self.box.children.values()[header_index].widget.repo_events_header; 443 } 444 445 fn contentStack(self: *View) *wgt.Stack(ui.Widget) { 446 return &self.box.children.values()[content_index].widget.stack; 447 } 448 449 fn selectedView(self: *View) ui.RoutablePage.EventsView { 450 const stack = self.contentStack(); 451 const id = stack.getFocus().child_id orelse return .active; 452 return @enumFromInt(stack.children.getIndex(id) orelse 0); 453 } 454 455 fn eventWindow(self: *View) *const Window { 456 return self.data.window(self.selectedView()); 457 } 458 459 fn content(self: *View) *wgt.Box(ui.Widget) { 460 const stack = self.contentStack(); 461 return &stack.children.values()[@intFromEnum(self.selectedView())].box; 462 } 463 464 fn listScroll(self: *View) *wgt.Scroll(ui.Widget) { 465 return &self.content().children.values()[list_index].widget.scroll; 466 } 467 468 fn listBox(self: *View) *wgt.Box(ui.Widget) { 469 return &self.listScroll().child.box; 470 } 471 472 fn detailScroll(self: *View) *wgt.Scroll(ui.Widget) { 473 return &self.content().children.values()[detail_index].widget.scroll; 474 } 475 476 fn detailBox(self: *View) *wgt.Box(ui.Widget) { 477 return &self.detailScroll().child.box; 478 } 479 480 fn detailActive(self: *View) bool { 481 return self.content().getFocus().child_id == self.detailScroll().getFocus().id; 482 } 483 484 fn headerActive(self: *View) bool { 485 return self.box.getFocus().child_id == self.header().getFocus().id; 486 } 487 488 fn selectedEventIndex(self: *View) ?usize { 489 const id = self.listBox().getFocus().child_id orelse return null; 490 const index = self.listBox().children.getIndex(id) orelse return null; 491 return if (index < self.eventWindow().events.len) index else null; 492 } 493 494 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 495 self.clearGrid(); 496 if (self.header().getSelectedIndex()) |index| 497 self.contentStack().getFocus().child_id = self.contentStack().children.keys()[index]; 498 try self.refreshDetail(allocator); 499 500 const list = self.listBox(); 501 for (list.children.keys(), list.children.values()) |id, *child| switch (child.widget) { 502 .text_box => |*text_box| ui.widget.markSelected(text_box, list.getFocus().child_id == id), 503 else => {}, 504 }; 505 506 const both_fit = if (constraint.max_size.width) |width| width >= list_max_width + detail_min_width else true; 507 self.content().children.values()[list_index].max_size = if (both_fit) .{ .width = list_max_width, .height = null } else null; 508 const detail_width = if (constraint.max_size.width) |width| if (both_fit) width - list_max_width else width else detail_min_width; 509 self.content().children.values()[detail_index].min_size = .{ .width = detail_width, .height = null }; 510 for (self.detailBox().children.values()) |*child| child.max_size = .{ .width = detail_width -| 2, .height = null }; 511 512 try self.box.build(allocator, constraint, root_focus); 513 } 514 515 fn refreshDetail(self: *View, allocator: std.mem.Allocator) !void { 516 const index = self.selectedEventIndex() orelse return; 517 const detailed_index = &self.detailed_index[@intFromEnum(self.selectedView())]; 518 if (detailed_index.*) |old| if (old == index) return; 519 const box = self.detailBox(); 520 for (box.children.values()) |*child| child.widget.deinit(allocator); 521 box.children.clearAndFree(allocator); 522 box.getFocus().child_id = null; 523 524 const item = self.eventWindow().events[index]; 525 if (item.view_url) |url| { 526 var link = try wgt.TextBox.init(allocator, "view event", .{ .border_style = .single, .round_corners = true, .wrap_kind = .none }); 527 errdefer link.deinit(allocator); 528 link.getFocus().mode = .all; 529 link.getFocus().kind = .{ .custom = try std.fmt.allocPrint(self.session.page_arena.allocator(), "a:{s}", .{url}) }; 530 try box.children.put(allocator, link.getFocus().id, .{ .widget = .{ .text_box = link }, .rect = null, .min_size = null }); 531 } 532 { 533 var kind = try wgt.TextBox.init(allocator, @tagName(item.kind), .{ .border_style = .single, .round_corners = true, .wrap_kind = .word, .label = " kind " }); 534 errdefer kind.deinit(allocator); 535 kind.getFocus().mode = .all; 536 try box.children.put(allocator, kind.getFocus().id, .{ .widget = .{ .text_box = kind }, .rect = null, .min_size = null }); 537 } 538 { 539 var author = try ui.authorBox(allocator, self.session.page_arena, item.author); 540 errdefer author.deinit(allocator); 541 try box.children.put(allocator, author.getFocus().id, .{ .widget = .{ .text_box = author }, .rect = null, .min_size = null }); 542 } 543 544 if (box.children.count() > 0) box.getFocus().child_id = box.children.keys()[0]; 545 self.detailScroll().x = 0; 546 self.detailScroll().y = 0; 547 self.detailScroll().getFocus().version +%= 1; 548 detailed_index.* = index; 549 } 550 551 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 552 // scrolling crosses the sub header boundary the same way arrows do 553 const direction = inp.vertDirection(key); 554 if (self.headerActive()) { 555 if (direction == .down) root_focus.setFocus(self.content().getFocus().id) else try self.header().input(allocator, key, root_focus); 556 return; 557 } 558 if (direction == .up and self.contentAtTop()) { 559 self.header().focusCurrent(root_focus); 560 return; 561 } 562 if (self.detailActive()) { 563 if (key == .arrow_left) { 564 root_focus.setFocus(self.listScroll().getFocus().id); 565 } else if (inp.rowDelta(key, @intCast(self.detailBox().children.count()))) |delta| { 566 ui.widget.moveRowFocus(self.detailBox(), self.detailScroll(), root_focus, delta); 567 } 568 } else if (inp.rowDelta(key, @intCast(self.listBox().children.count()))) |delta| { 569 ui.widget.moveRowFocus(self.listBox(), self.listScroll(), root_focus, delta); 570 } else switch (key) { 571 .arrow_right => if (self.detailBox().children.count() > 0) root_focus.setFocus(self.detailScroll().getFocus().id), 572 .enter => if (self.selectedEventIndex() != null) root_focus.setFocus(self.detailScroll().getFocus().id), 573 else => {}, 574 } 575 } 576 577 fn contentAtTop(self: *View) bool { 578 const box = if (self.detailActive()) self.detailBox() else self.listBox(); 579 const scroll = if (self.detailActive()) self.detailScroll() else self.listScroll(); 580 const id = box.getFocus().child_id orelse return true; 581 return box.children.getIndex(id) == 0 and scroll.y == 0; 582 } 583 584 pub fn atTop(self: *View) bool { 585 return self.headerActive(); 586 } 587 588 // arriving from the page's tabs lands on the sub header, not the content 589 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 590 self.header().focusCurrent(root_focus); 591 return true; 592 } 593 594 pub fn clearGrid(self: *View) void { 595 self.box.clearGrid(); 596 } 597 598 pub fn getGrid(self: View) ?Grid { 599 return self.box.getGrid(); 600 } 601 602 pub fn getFocus(self: *View) *Focus { 603 return self.box.getFocus(); 604 } 605 }; 606 607 pub const Header = struct { 608 sync_status: ?[]const u8, 609 610 const nothing = "nothing to sync"; 611 const unsynced = "sync needed!"; 612 613 const Progress = struct { 614 message: *std.Io.Writer.Allocating, 615 616 pub fn run(self: @This(), _: std.Io, event: rp.ProgressEvent) !void { 617 switch (event) { 618 .text => |value| { 619 self.message.clearRetainingCapacity(); 620 try self.message.writer.writeAll(value); 621 }, 622 else => {}, 623 } 624 } 625 }; 626 627 pub fn local( 628 comptime repo_kind: rp.RepoKind, 629 comptime repo_opts: rp.RepoOpts(repo_kind), 630 aa: std.mem.Allocator, 631 repo: *rp.Repo(repo_kind, repo_opts), 632 io: std.Io, 633 failure: ?[]const u8, 634 ) !Header { 635 if (failure != null) return Header.empty(aa, failure); 636 const remote_name = (try remoteName(repo_kind, repo_opts, repo, io, aa)) orelse return .{ .sync_status = nothing }; 637 const remote_ref: rf.Ref = .{ .kind = .{ .remote = remote_name }, .name = evt.events_ref.name }; 638 const local_oid = (try repo.readRef(io, evt.events_ref)) orelse return .{ .sync_status = nothing }; 639 const remote_oid = (try repo.readRef(io, remote_ref)) orelse return .{ .sync_status = nothing }; 640 return .{ .sync_status = if (std.mem.eql(u8, &local_oid, &remote_oid)) nothing else unsynced }; 641 } 642 643 pub fn empty(aa: std.mem.Allocator, failure: ?[]const u8) !Header { 644 return .{ .sync_status = if (failure) |name| try std.fmt.allocPrint(aa, "error: {s}", .{name}) else nothing }; 645 } 646 647 pub fn remote() Header { 648 return .{ .sync_status = null }; 649 } 650 651 pub const View = struct { 652 box: wgt.Box(ui.Widget), 653 session: *ui.Session, 654 tab_ids: [2]usize, 655 button_id: ?usize, 656 657 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !Header.View { 658 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 659 errdefer box.deinit(allocator); 660 var tab_ids: [2]usize = undefined; 661 const view_labels = [_][]const u8{ active_tab_label, removed_tab_label }; 662 inline for ([_]ui.RoutablePage.EventsView{ .active, .removed }, view_labels, 0..) |view, view_label, i| { 663 const route = ui.RoutablePage.repoEventsRoute(data.identity, view, null, "", data.moment) orelse return error.RouteTooLong; 664 const count = data.window(view).count; 665 var label_buf: [64]u8 = undefined; 666 const label = try std.fmt.bufPrint(&label_buf, "{s} ({d})", .{ view_label, count }); 667 var tab = try wgt.TextBox.init(allocator, label, .{ .border_style = .hidden, .round_corners = true, .wrap_kind = .none }); 668 errdefer tab.deinit(allocator); 669 tab.getFocus().mode = .all; 670 const selected = std.meta.activeTag(session.data.current_page) == .repo_events and data.view == view; 671 tab.getFocus().kind = .{ .custom = try ui.inPageTabLink(session, route, selected) }; 672 tab_ids[i] = tab.getFocus().id; 673 try box.children.put(allocator, tab.getFocus().id, .{ .widget = .{ .text_box = tab }, .rect = null, .min_size = .{ .width = label.len + 2, .height = null } }); 674 } 675 676 var button_id: ?usize = null; 677 if (data.header.sync_status != null) { 678 box.getFocus().kind = .{ .custom = "form:/sync" }; 679 var button = try wgt.TextBox.init(allocator, "sync", .{ .border_style = .single, .round_corners = true, .wrap_kind = .none }); 680 errdefer button.deinit(allocator); 681 button.getFocus().mode = .all; 682 button.getFocus().kind = .{ .custom = "submit" }; 683 button_id = button.getFocus().id; 684 try box.children.put(allocator, button.getFocus().id, .{ .widget = .{ .text_box = button }, .rect = null, .min_size = null }); 685 } 686 687 if (data.header.sync_status) |status_text| { 688 var status = try wgt.TextBox.init(allocator, status_text, .{ .border_style = .hidden, .wrap_kind = .none }); 689 errdefer status.deinit(allocator); 690 try box.children.put(allocator, status.getFocus().id, .{ .widget = .{ .text_box = status }, .rect = null, .min_size = null, .flex = .shrink }); 691 } 692 box.getFocus().child_id = tab_ids[@intFromEnum(data.view)]; 693 return .{ .box = box, .session = session, .tab_ids = tab_ids, .button_id = button_id }; 694 } 695 696 pub fn deinit(self: *Header.View, allocator: std.mem.Allocator) void { 697 self.box.deinit(allocator); 698 } 699 700 pub fn build(self: *Header.View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 701 self.clearGrid(); 702 for (self.tab_ids) |id| { 703 const child = self.box.children.getPtr(id) orelse continue; 704 const tab = switch (child.widget) { 705 .text_box => |*text_box| text_box, 706 else => continue, 707 }; 708 ui.widget.markSelected(tab, self.box.getFocus().child_id == id); 709 } 710 try self.box.build(allocator, constraint, root_focus); 711 } 712 713 pub fn input(self: *Header.View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 714 const selected = self.box.getFocus().child_id orelse return; 715 const current = self.box.children.getIndex(selected) orelse return; 716 const count = 2 + @as(usize, @intFromBool(self.button_id != null)); 717 if (inp.moveTab(key, current, count)) |next| { 718 root_focus.setFocus(self.box.children.keys()[next]); 719 return; 720 } 721 switch (key) { 722 .enter => if (self.syncFocused()) try self.requestSync(allocator), 723 .mouse => |mouse| if (self.button_id) |id| if (inp.leftClickOn(root_focus, id, mouse)) try self.requestSync(allocator), 724 else => {}, 725 } 726 } 727 728 fn requestSync(self: *Header.View, allocator: std.mem.Allocator) !void { 729 if (!self.session.is_terminal) return; 730 if (self.session.host_request != null) return; 731 const button_id = self.button_id orelse return; 732 const child = self.box.children.getPtr(button_id) orelse return; 733 const button = switch (child.widget) { 734 .text_box => |*button| button, 735 else => return, 736 }; 737 try button.setContent(allocator, "syncing..."); 738 self.session.host_request = .sync_events; 739 } 740 741 fn syncFocused(self: *Header.View) bool { 742 const button_id = self.button_id orelse return false; 743 return self.box.getFocus().child_id == button_id; 744 } 745 746 pub fn getSelectedIndex(self: *Header.View) ?usize { 747 const id = self.box.getFocus().child_id orelse return null; 748 return std.mem.indexOfScalar(usize, &self.tab_ids, id); 749 } 750 751 pub fn focusCurrent(self: *Header.View, root_focus: *Focus) void { 752 root_focus.setFocus(self.box.getFocus().child_id orelse self.tab_ids[0]); 753 } 754 755 pub fn clearGrid(self: *Header.View) void { 756 self.box.clearGrid(); 757 } 758 759 pub fn getGrid(self: Header.View) ?Grid { 760 return self.box.getGrid(); 761 } 762 763 pub fn getFocus(self: *Header.View) *Focus { 764 return self.box.getFocus(); 765 } 766 }; 767 }; 768 769 pub fn performSync(allocator: std.mem.Allocator, session: *ui.Session) !void { 770 if (comptime builtin.target.cpu.arch == .wasm32) return; 771 const io = session.io orelse return; 772 const source = session.local orelse return; 773 defer session.refresh_requested = true; 774 const failure = sync(io, allocator, source) catch |err| { 775 session.data.sync_failure = @errorName(err); 776 return; 777 }; 778 if (failure) |message| { 779 defer allocator.free(message); 780 session.data.sync_failure = try session.arena.allocator().dupe(u8, message); 781 return; 782 } 783 session.data.sync_failure = null; 784 switch (session.data.current_page) { 785 .repo_events => |route| { 786 if (ui.RoutablePage.repoEventsRoute(route.name.slice(), route.view, null, "", route.moment)) |first| 787 session.data.current_page = first; 788 }, 789 else => {}, 790 } 791 } 792 793 fn remoteName( 794 comptime repo_kind: rp.RepoKind, 795 comptime repo_opts: rp.RepoOpts(repo_kind), 796 repo: *rp.Repo(repo_kind, repo_opts), 797 io: std.Io, 798 allocator: std.mem.Allocator, 799 ) !?[]u8 { 800 var remotes = try repo.listRemotes(io, allocator); 801 defer remotes.deinit(); 802 const names = remotes.sections.keys(); 803 if (names.len == 0) return null; 804 for (names) |name| { 805 const remote_ref: rf.Ref = .{ .kind = .{ .remote = name }, .name = evt.events_ref.name }; 806 if (try repo.readRef(io, remote_ref) != null) return try allocator.dupe(u8, name); 807 } 808 return try allocator.dupe(u8, names[0]); 809 } 810 811 fn isLoopbackSshUrl(url: []const u8) bool { 812 const uri = std.Uri.parse(url) catch return false; 813 const host = switch (uri.host orelse return false) { 814 .raw => |value| value, 815 .percent_encoded => |value| value, 816 }; 817 return std.mem.eql(u8, host, "localhost") or 818 std.mem.eql(u8, host, "127.0.0.1") or 819 std.mem.eql(u8, host, "::1") or 820 std.mem.eql(u8, host, "[::1]"); 821 } 822 823 pub fn sync(io: std.Io, allocator: std.mem.Allocator, source: ui.RepoSource) !?[]u8 { 824 var message: std.Io.Writer.Allocating = .init(allocator); 825 defer message.deinit(); 826 827 switch (source.repo_kind) { 828 inline else => |repo_kind| { 829 var any_repo = try rp.AnyRepo(repo_kind, .{ .ProgressCtx = Header.Progress }).open(io, allocator, source.localInitOpts()); 830 defer any_repo.deinit(io, allocator); 831 switch (any_repo) { 832 inline else => |*repo| { 833 const repo_opts = repo.self_repo_opts; 834 const remote_name = (try remoteName(repo_kind, repo_opts, repo, io, allocator)) orelse return error.RemoteNotFound; 835 defer allocator.free(remote_name); 836 837 var config = try repo.listConfig(io, allocator); 838 defer config.deinit(); 839 const configured_ssh = if (config.sections.get("core")) |core| core.get("sshcommand") else null; 840 const ssh = if (configured_ssh) |command| if (command.len > 0) command else "ssh" else "ssh"; 841 const remote_section = try std.fmt.allocPrint(allocator, "remote.{s}", .{remote_name}); 842 defer allocator.free(remote_section); 843 const remote_config = config.sections.get(remote_section) orelse return error.RemoteNotFound; 844 const fetch_url = remote_config.get("url") orelse return error.UrlNotFound; 845 const push_url = remote_config.get("pushurl") orelse fetch_url; 846 const loopback_opts = " -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"; 847 const fetch_ssh_command = try std.fmt.allocPrint(allocator, "{s}{s} -o BatchMode=yes -o LogLevel=QUIET", .{ ssh, if (isLoopbackSshUrl(fetch_url)) loopback_opts else "" }); 848 defer allocator.free(fetch_ssh_command); 849 const push_ssh_command = try std.fmt.allocPrint(allocator, "{s}{s} -o BatchMode=yes -o LogLevel=QUIET", .{ ssh, if (isLoopbackSshUrl(push_url)) loopback_opts else "" }); 850 defer allocator.free(push_ssh_command); 851 const fetch_transport_opts: xit.net.Opts(repo_opts.ProgressCtx) = .{ .progress_ctx = .{ .message = &message }, .wire = .{ .ssh = .{ .command = fetch_ssh_command } } }; 852 const push_transport_opts: xit.net.Opts(repo_opts.ProgressCtx) = .{ .progress_ctx = .{ .message = &message }, .wire = .{ .ssh = .{ .command = push_ssh_command } } }; 853 854 const fetch_refspec = try std.fmt.allocPrint(allocator, "+refs/heads/{s}:refs/remotes/{s}/{s}", .{ evt.events_ref.name, remote_name, evt.events_ref.name }); 855 defer allocator.free(fetch_refspec); 856 var fetch_opts = fetch_transport_opts; 857 fetch_opts.refspecs = &.{fetch_refspec}; 858 message.clearRetainingCapacity(); 859 repo.fetch(io, allocator, remote_name, fetch_opts) catch |err| { 860 if (err == error.ServerReportedError and message.written().len != 0) return try allocator.dupe(u8, message.written()); 861 return err; 862 }; 863 864 const remote_ref: rf.Ref = .{ .kind = .{ .remote = remote_name }, .name = evt.events_ref.name }; 865 const local_oid = try repo.readRef(io, evt.events_ref); 866 const remote_oid = try repo.readRef(io, remote_ref); 867 if (local_oid == null and remote_oid == null) { 868 try evt.consume(.local, .repo, repo_kind, repo_opts, io, allocator, repo, evt.events_ref, &.{}); 869 return null; 870 } 871 if (remote_oid != null) try evt.mergeEvents(repo_kind, repo_opts, io, allocator, repo, remote_ref); 872 try evt.consume(.local, .repo, repo_kind, repo_opts, io, allocator, repo, evt.events_ref, &.{}); 873 874 const push_refspec = try std.fmt.allocPrint(allocator, "refs/heads/{s}:refs/heads/{s}", .{ evt.events_ref.name, evt.events_ref.name }); 875 defer allocator.free(push_refspec); 876 message.clearRetainingCapacity(); 877 repo.push(io, allocator, remote_name, push_refspec, false, push_transport_opts) catch |err| { 878 if (err == error.ServerReportedError and message.written().len != 0) return try allocator.dupe(u8, message.written()); 879 return err; 880 }; 881 message.clearRetainingCapacity(); 882 repo.fetch(io, allocator, remote_name, fetch_opts) catch |err| { 883 if (err == error.ServerReportedError and message.written().len != 0) return try allocator.dupe(u8, message.written()); 884 return err; 885 }; 886 }, 887 } 888 }, 889 } 890 return null; 891 } 892