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

Method run_git_diff

atomic-cli/src/commands/diff/command.rs:275–445  ·  view source on GitHub ↗

Versioned Git-inspired staging diff (CB-11A). Read-only comparison of two adjacent layers: - `--cached`: Git baseline (HEAD tree) → index (staged), - default: index → worktree (unstaged).

(&self, repo_root: &std::path::Path)

Source from the content-addressed store, hash-verified

273 /// - `--cached`: Git baseline (HEAD tree) → index (staged),
274 /// - default: index → worktree (unstaged).
275 fn run_git_diff(&self, repo_root: &std::path::Path) -> CliResult<()> {
276 use std::collections::BTreeMap;
277
278 // The --git staging diff is a versioned, bounded subset (RFC §9.1):
279 // Human output carries the subset marker; JSON uses the shared
280 // versioned diff schema without a text preamble.
281 if !self.json {
282 println!("# atomic-diff-git v1 (bounded subset; layers: --cached baseline→index, default index→worktree)");
283 }
284
285 let mut repo =
286 Repository::open_readonly(repo_root).map_err(|e| CliError::InvalidRepository {
287 reason: e.to_string(),
288 })?;
289 let workspace = match observe_workspace(&mut repo)? {
290 Ok(workspace) => workspace,
291 Err(remediation) => return Err(remediation_error(remediation)),
292 };
293 let _ = workspace;
294
295 let git_repo = git2::Repository::open(repo_root).map_err(|error| CliError::GitError {
296 message: format!("cannot open Git repository: {error}"),
297 })?;
298 let policy = crate::commands::git::parallel::conversion_policy(&git_repo)?;
299 let filter = atomic_repository::GitAttributesFilter::for_repository(repo_root);
300
301 // Baseline: HEAD tree blobs (read-only).
302 let mut baseline: BTreeMap<String, (Vec<u8>, u32)> = BTreeMap::new();
303 if let Ok(head) = git_repo.head() {
304 if let Ok(commit) = head.peel_to_commit() {
305 if let Ok(tree) = commit.tree() {
306 collect_baseline_blobs(&git_repo, &tree, &mut Vec::new(), &mut baseline)?;
307 }
308 }
309 }
310
311 // Index: stage-0 entries with blob content (read-only ODB access).
312 let index_state =
313 atomic_repository::observe_git_index(repo_root, &policy).map_err(|error| {
314 CliError::GitError {
315 message: error.to_string(),
316 }
317 })?;
318 let mut index: BTreeMap<String, (Vec<u8>, u32)> = BTreeMap::new();
319 for entry in &index_state.entries {
320 if entry.stage != 0 || entry.sparse_directory {
321 continue;
322 }
323 let path = String::from_utf8_lossy(entry.path.as_bytes()).into_owned();
324 let Some(oid) = &entry.oid else { continue };
325 let gid =
326 git2::Oid::from_bytes(oid.as_bytes()).map_err(|error| CliError::GitError {
327 message: format!("cannot parse index object id: {error}"),
328 })?;
329 let content = git_repo
330 .find_blob(gid)
331 .map(|blob| blob.content().to_vec())
332 .unwrap_or_default();

Callers 1

runMethod · 0.80

Calls 15

observe_workspaceFunction · 0.85
remediation_errorFunction · 0.85
openFunction · 0.85
conversion_policyFunction · 0.85
collect_baseline_blobsFunction · 0.85
observe_git_indexFunction · 0.85
cleanFunction · 0.85
build_layer_file_diffFunction · 0.85
treeMethod · 0.80
contains_keyMethod · 0.80
print_no_changesMethod · 0.80
get_output_configMethod · 0.80

Tested by

no test coverage detected