pub struct FileHistory { /* private fields */ }Expand description
File version history tracker
Thread-safe storage for file snapshots. Each file maintains an ordered
list of versions. Old versions are evicted when max_snapshots is reached.
Implementations§
Source§impl FileHistory
impl FileHistory
Sourcepub fn new(max_snapshots: usize) -> Self
pub fn new(max_snapshots: usize) -> Self
Create a new file history tracker
max_snapshots limits the total number of snapshots stored.
When exceeded, the oldest snapshots (across all files) are evicted.
Sourcepub fn save_snapshot(&self, path: &str, content: &str, tool_name: &str) -> usize
pub fn save_snapshot(&self, path: &str, content: &str, tool_name: &str) -> usize
Save a snapshot of a file’s content before modification
Returns the version number assigned to this snapshot.
Sourcepub fn list_versions(&self, path: &str) -> Vec<VersionSummary>
pub fn list_versions(&self, path: &str) -> Vec<VersionSummary>
List all versions of a specific file
Sourcepub fn list_files(&self) -> Vec<(String, usize)>
pub fn list_files(&self) -> Vec<(String, usize)>
List all tracked files with their version counts
Sourcepub fn get_version(&self, path: &str, version: usize) -> Option<FileSnapshot>
pub fn get_version(&self, path: &str, version: usize) -> Option<FileSnapshot>
Get a specific version’s content
Sourcepub fn get_latest(&self, path: &str) -> Option<FileSnapshot>
pub fn get_latest(&self, path: &str) -> Option<FileSnapshot>
Get the latest version of a file
Sourcepub fn diff(
&self,
path: &str,
from_version: usize,
to_version: usize,
) -> Option<String>
pub fn diff( &self, path: &str, from_version: usize, to_version: usize, ) -> Option<String>
Generate a unified diff between two versions of a file
Returns None if either version doesn’t exist.
Sourcepub fn diff_with_current(
&self,
path: &str,
version: usize,
current_content: &str,
) -> Option<String>
pub fn diff_with_current( &self, path: &str, version: usize, current_content: &str, ) -> Option<String>
Generate a diff between a version and the current file content
Sourcepub fn total_snapshots(&self) -> usize
pub fn total_snapshots(&self) -> usize
Get the total number of snapshots across all files
Sourcepub fn clear_file(&self, path: &str)
pub fn clear_file(&self, path: &str)
Clear all history for a specific file