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

Function diff_view_pair

atomic-cli/src/commands/rpc.rs:2473–2515  ·  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

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

Callers 1

diffFunction · 0.85

Calls 11

openFunction · 0.85
print_diff_jsonFunction · 0.85
file_diff_from_chunkFunction · 0.85
get_output_configMethod · 0.80
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