╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ progress.zig ─────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
88 }, 89 // each phase names itself before reporting its count 90 .text => |text| { 91 self.label = text; 92 return; 93 }, 94 else => return, 95 } 96 // a phase that knows no total counts instead, and stays quiet until it 97 // has something to count 98 if (self.total == 0 and self.count == 0) return; 99 100 // every report flushes, so one is sent per percent, or per block of 101 // items when there is no total to turn into one 102 const step: usize = if (self.total > 0) @intCast(@as(u128, self.count) * 100 / self.total) else self.count / report_every; 103 if (event == .complete_one and step == self.step) return; 104 self.step = step; 105 106 // reporting is the only moment a transaction looks up from its work 107 if (self.sess) |sess| if (sess.peerGone()) { 108 self.gone = true; 109 return error.ClientGone; 110 }; 111 112 var buffer: [128]u8 = undefined; 113 const suffix = if (event == .end) "\n" else "\r"; 114 const text = if (self.total > 0) 115 try std.fmt.bufPrint(&buffer, "{s}: {d}% ({d}/{d}){s}", .{ self.label, step, self.count, self.total, suffix }) 116 else 117 try std.fmt.bufPrint(&buffer, "{s}: {d}{s}", .{ self.label, self.count, suffix }); 118 if (self.response) |response| { 119 try response.progress(self.writer, text); 120 } else { 121 try xit.net_server_pkt.sendSideband(self.writer, 2, text); 122 try self.writer.flush(); 123 } 124 } 125 }; 126 127 // whether the client the work is reporting to has hung up, or its push has 128 // outgrown the repo size limit. only a sideband reporter probes, so any other 129 // context never cancels. 130 pub fn cancelled(comptime repo_opts: rp.RepoOpts(.xit), progress_ctx_maybe: ?repo_opts.ProgressCtx) bool { 131 if (repo_opts.ProgressCtx != *Sideband) return false; 132 const progress_ctx = progress_ctx_maybe orelse return false; 133 return progress_ctx.gone or progress_ctx.too_large; 134 } 135