MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / diff

Method diff

crates/opencode-session/src/snapshot.rs:76–127  ·  view source on GitHub ↗
(directory: &Path, from_hash: &str)

Source from the content-addressed store, hash-verified

74 }
75
76 pub fn diff(directory: &Path, from_hash: &str) -> Result<Vec<super::FileDiff>> {
77 let git_dir = ensure_snapshot_repo(directory)?;
78 git_add_all(directory, &git_dir)?;
79 let output = git_output(
80 directory,
81 &git_dir,
82 &[
83 "-c",
84 "core.autocrlf=false",
85 "-c",
86 "core.quotepath=false",
87 "diff",
88 "--no-ext-diff",
89 "--numstat",
90 from_hash,
91 "--",
92 ".",
93 ],
94 );
95
96 let mut diffs = Vec::new();
97
98 if let Ok(output) = output {
99 for line in String::from_utf8_lossy(&output.stdout).lines() {
100 if line.is_empty() {
101 continue;
102 }
103 let parts: Vec<&str> = line.split('\t').collect();
104 if parts.len() >= 3 {
105 let is_binary = parts[0] == "-" && parts[1] == "-";
106 let additions = if is_binary {
107 0
108 } else {
109 parts[0].parse::<u64>().unwrap_or(0)
110 };
111 let deletions = if is_binary {
112 0
113 } else {
114 parts[1].parse::<u64>().unwrap_or(0)
115 };
116 let path = parts[2].to_string();
117 diffs.push(super::FileDiff {
118 path,
119 additions,
120 deletions,
121 });
122 }
123 }
124 }
125
126 Ok(diffs)
127 }
128
129 /// Compute diff between two git refs (matching TS `Snapshot.diffFull`).
130 ///

Callers

nothing calls this directly

Calls 5

ensure_snapshot_repoFunction · 0.85
git_add_allFunction · 0.85
newFunction · 0.85
is_emptyMethod · 0.80
git_outputFunction · 0.70

Tested by

no test coverage detected