Compute diffs from message step snapshots. Scans messages for step-start and step-finish parts to find the earliest "from" snapshot and the latest "to" snapshot, then computes a full git diff.
(
messages: &[MessageWithParts],
worktree: &std::path::Path,
)
| 135 | /// Scans messages for step-start and step-finish parts to find the earliest |
| 136 | /// "from" snapshot and the latest "to" snapshot, then computes a full git diff. |
| 137 | pub fn compute_diff( |
| 138 | messages: &[MessageWithParts], |
| 139 | worktree: &std::path::Path, |
| 140 | ) -> Vec<SummaryFileDiff> { |
| 141 | let mut from: Option<String> = None; |
| 142 | let mut to: Option<String> = None; |
| 143 | |
| 144 | for msg in messages { |
| 145 | for part in &msg.parts { |
| 146 | match part { |
| 147 | Part::StepStart(StepStartPart { snapshot, .. }) => { |
| 148 | if from.is_none() { |
| 149 | if let Some(ref s) = snapshot { |
| 150 | if !s.is_empty() { |
| 151 | from = Some(s.clone()); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | Part::StepFinish(StepFinishPart { snapshot, .. }) => { |
| 157 | if let Some(ref s) = snapshot { |
| 158 | if !s.is_empty() { |
| 159 | to = Some(s.clone()); |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | _ => {} |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | if let (Some(ref from_ref), Some(ref to_ref)) = (&from, &to) { |
| 169 | match Snapshot::diff_full(worktree, from_ref, to_ref) { |
| 170 | Ok(diffs) => { |
| 171 | return diffs |
| 172 | .into_iter() |
| 173 | .map(|d| SummaryFileDiff { |
| 174 | file: d.path, |
| 175 | additions: d.additions, |
| 176 | deletions: d.deletions, |
| 177 | }) |
| 178 | .collect(); |
| 179 | } |
| 180 | Err(e) => { |
| 181 | tracing::warn!("Failed to compute snapshot diff: {}", e); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | Vec::new() |
| 187 | } |
| 188 | |
| 189 | // ============================================================================ |
| 190 | // Summarize (matches TS SessionSummary.summarize) |
no test coverage detected