MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / compute_diff

Function compute_diff

crates/opencode-session/src/summary.rs:137–187  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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.
137pub 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)

Callers 2

summarizeFunction · 0.85
summarize_messageFunction · 0.85

Calls 3

newFunction · 0.85
is_emptyMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected