Save a snapshot of a file's content before modification Returns the version number assigned to this snapshot.
(&self, path: &str, content: &str, tool_name: &str)
| 84 | /// |
| 85 | /// Returns the version number assigned to this snapshot. |
| 86 | pub fn save_snapshot(&self, path: &str, content: &str, tool_name: &str) -> usize { |
| 87 | let mut snapshots = write_or_recover(&self.snapshots); |
| 88 | |
| 89 | let file_versions = snapshots.entry(path.to_string()).or_default(); |
| 90 | let version = file_versions.len(); |
| 91 | |
| 92 | file_versions.push(FileSnapshot { |
| 93 | version, |
| 94 | path: path.to_string(), |
| 95 | content: content.to_string(), |
| 96 | timestamp: Utc::now(), |
| 97 | tool_name: tool_name.to_string(), |
| 98 | }); |
| 99 | |
| 100 | // Evict oldest snapshots if over limit |
| 101 | self.evict_if_needed(&mut snapshots); |
| 102 | |
| 103 | version |
| 104 | } |
| 105 | |
| 106 | /// List all versions of a specific file |
| 107 | pub fn list_versions(&self, path: &str) -> Vec<VersionSummary> { |