MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / diff_snapshots

Function diff_snapshots

atomic-agent/src/watcher/fallback.rs:125–163  ·  view source on GitHub ↗

Diff two snapshots to produce a `TurnChanges`.

(before: &FileSnapshot, after: &FileSnapshot)

Source from the content-addressed store, hash-verified

123
124/// Diff two snapshots to produce a `TurnChanges`.
125fn diff_snapshots(before: &FileSnapshot, after: &FileSnapshot) -> TurnChanges {
126 let mut modified = Vec::new();
127 let mut added = Vec::new();
128 let mut deleted = Vec::new();
129
130 // Find modified and deleted files
131 for (path, before_entry) in before {
132 match after.get(path) {
133 Some(after_entry) => {
134 // File exists in both — check if changed
135 if before_entry.mtime != after_entry.mtime || before_entry.size != after_entry.size
136 {
137 modified.push(path.clone());
138 }
139 }
140 None => {
141 // File was in before but not after — deleted
142 deleted.push(path.clone());
143 }
144 }
145 }
146
147 // Find added files
148 for path in after.keys() {
149 if !before.contains_key(path) {
150 added.push(path.clone());
151 }
152 }
153
154 // Sort for deterministic output
155 modified.sort();
156 added.sort();
157 deleted.sort();
158
159 TurnChanges::new()
160 .with_modified(modified)
161 .with_added(added)
162 .with_deleted(deleted)
163}
164
165// FallbackWatcher
166

Callers 9

end_turnMethod · 0.85
test_diff_no_changesFunction · 0.85
test_diff_added_fileFunction · 0.85
test_diff_deleted_fileFunction · 0.85
test_diff_mixed_changesFunction · 0.85
test_diff_results_sortedFunction · 0.85
test_diff_both_emptyFunction · 0.85

Calls 8

contains_keyMethod · 0.80
sortMethod · 0.80
with_deletedMethod · 0.80
with_addedMethod · 0.80
with_modifiedMethod · 0.80
getMethod · 0.65
pushMethod · 0.45
cloneMethod · 0.45

Tested by 8

test_diff_no_changesFunction · 0.68
test_diff_added_fileFunction · 0.68
test_diff_deleted_fileFunction · 0.68
test_diff_mixed_changesFunction · 0.68
test_diff_results_sortedFunction · 0.68
test_diff_both_emptyFunction · 0.68