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

Function diff_view_pair

atomic-cli/src/commands/rpc.rs:2474–2516  ·  view source on GitHub ↗

`atomic diff --from X --to Y` over the Diff RPC's RefPairScope arm — the same client-side renders as the working-copy form (`--json`, the word-diff highlight, the plain patch text).

(args: &super::diff::command::Diff, from: &str, to: &str)

Source from the content-addressed store, hash-verified

2472/// the same client-side renders as the working-copy form (`--json`, the
2473/// word-diff highlight, the plain patch text).
2474fn diff_view_pair(args: &super::diff::command::Diff, from: &str, to: &str) -> CliResult<bool> {
2475 let Some(session) = Service::open()? else {
2476 return Ok(false);
2477 };
2478 let stat_only = args.stat;
2479 let from = from.to_string();
2480 let to = to.to_string();
2481 let chunks = session.diff(pb::DiffRequest {
2482 repository: Some(session.reference.clone()),
2483 word_diff: args.word_diff,
2484 scope: Some(pb::diff_request::Scope::Refs(pb::RefPairScope {
2485 from_view: from,
2486 to_view: to,
2487 })),
2488 stat_only,
2489 })?;
2490
2491 if args.json {
2492 // A view-pair diff is not scoped against a single view — the
2493 // document's `view` field stays null (and `change` too: no `-c`).
2494 print_diff_json(&chunks, None)?;
2495 return Ok(true);
2496 }
2497 if chunks.is_empty() {
2498 println!("No differences between the views.");
2499 return Ok(true);
2500 }
2501
2502 // Same shared-formatter render as the working-copy form: the wire's
2503 // status + contents rebuild the FileDiffs the local path would build.
2504 let algorithm = args.parse_algorithm()?;
2505 let config = args.get_output_config();
2506 let mut file_diffs = Vec::new();
2507 let mut stats = super::diff::types::DiffStats::new();
2508 for chunk in &chunks {
2509 if let Some(file_diff) = file_diff_from_chunk(chunk, &algorithm, config.context_lines) {
2510 stats.add_file(file_diff.stats.clone());
2511 file_diffs.push(file_diff);
2512 }
2513 }
2514 args.render(&file_diffs, &stats, &config, None, None)?;
2515 Ok(true)
2516}
2517
2518/// `atomic diff -c <id>` over GetChange — every form: the change
2519/// resolves (full hash, `#N` sequence, or prefix — the same ChangeRef

Callers 1

diffFunction · 0.85

Calls 11

print_diff_jsonFunction · 0.85
file_diff_from_chunkFunction · 0.85
get_output_configMethod · 0.80
openFunction · 0.50
diffMethod · 0.45
cloneMethod · 0.45
is_emptyMethod · 0.45
parse_algorithmMethod · 0.45
add_fileMethod · 0.45
pushMethod · 0.45
renderMethod · 0.45

Tested by

no test coverage detected