╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ progress.zig ─────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
65 .end => |kind| { 66 if (!reported(kind)) return; 67 }, 68 // each phase names itself before reporting its count 69 .text => |text| { 70 self.label = text; 71 return; 72 }, 73 else => return, 74 } 75 // a phase that knows no total counts instead, and stays quiet until it 76 // has something to count 77 if (self.total == 0 and self.count == 0) return; 78 79 // every report flushes, so one is sent per percent, or per block of 80 // items when there is no total to turn into one 81 const step: usize = if (self.total > 0) @intCast(@as(u128, self.count) * 100 / self.total) else self.count / report_every; 82 if (event == .complete_one and step == self.step) return; 83 self.step = step; 84 85 // reporting is the only moment a transaction looks up from its work 86 if (self.sess) |sess| if (sess.peerGone()) { 87 self.gone = true; 88 return error.ClientGone; 89 }; 90 91 var buffer: [128]u8 = undefined; 92 const suffix = if (event == .end) "\n" else "\r"; 93 const text = if (self.total > 0) 94 try std.fmt.bufPrint(&buffer, "{s}: {d}% ({d}/{d}){s}", .{ self.label, step, self.count, self.total, suffix }) 95 else 96 try std.fmt.bufPrint(&buffer, "{s}: {d}{s}", .{ self.label, self.count, suffix }); 97 if (self.response) |response| { 98 try response.progress(self.writer, text); 99 } else { 100 try xit.net_server_pkt.sendSideband(self.writer, 2, text); 101 try self.writer.flush(); 102 } 103 } 104 }; 105 106 // whether the client the work is reporting to has hung up. only a sideband 107 // reporter probes, so any other context never cancels. 108 pub fn cancelled(comptime repo_opts: rp.RepoOpts(.xit), progress_ctx_maybe: ?repo_opts.ProgressCtx) bool { 109 if (repo_opts.ProgressCtx != *Sideband) return false; 110 const progress_ctx = progress_ctx_maybe orelse return false; 111 return progress_ctx.gone; 112 } 113