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

Function diff_change

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

`atomic diff -c ` over GetChange — every form: the change resolves (full hash, `#N` sequence, or prefix — the same ChangeRef arms `atomic change` uses), the versioned change bundle deserializes into the domain Change, and the SAME render flow the local `-c` body runs prints it. The request's file-content reconstruction carries each touched file's pre/post-change bytes: the FileOps hunks pad th

(args: &super::diff::command::Diff, change_ref: &str)

Source from the content-addressed store, hash-verified

2525/// legacy no-file_ops changes build their diffs from the reconstructed
2526/// content — the exception is gone.
2527fn diff_change(args: &super::diff::command::Diff, change_ref: &str) -> CliResult<bool> {
2528 use super::change::types::ChangeIdentifier;
2529 let Some(session) = Service::open()? else {
2530 return Ok(false);
2531 };
2532 let parsed = ChangeIdentifier::parse(Some(change_ref))
2533 .map_err(|error| CliError::InvalidArgument { message: error })?;
2534 let reference = match parsed {
2535 ChangeIdentifier::FullHash(hash) => {
2536 let mut bytes = [0u8; 32];
2537 bytes.copy_from_slice(&hash.0);
2538 pb::ChangeRef {
2539 kind: Some(pb::change_ref::Kind::Hash(pb::Hash {
2540 value: bytes.to_vec(),
2541 algorithm: pb::HashAlgorithm::Blake3 as i32,
2542 })),
2543 }
2544 }
2545 ChangeIdentifier::Sequence(sequence) => pb::ChangeRef {
2546 kind: Some(pb::change_ref::Kind::Sequence(sequence)),
2547 },
2548 // "Latest" (`@`/empty) resolves through the daemon's Log like the
2549 // `change` hook does: the view's newest change.
2550 ChangeIdentifier::Latest => {
2551 let entries = session.log(pb::LogRequest {
2552 repository: Some(session.reference.clone()),
2553 all_views: false,
2554 view: args.view.clone(),
2555 cursor: None,
2556 budget: Some(pb::PageBudget {
2557 max_items: Some(1),
2558 max_bytes: None,
2559 }),
2560 path_filter: Vec::new(),
2561 tags_only: false,
2562 })?;
2563 let Some(entry) = entries.entries.first() else {
2564 return Err(CliError::ChangeNotFound {
2565 hash: "latest".to_string(),
2566 });
2567 };
2568 let hash = entry
2569 .hash
2570 .clone()
2571 .ok_or_else(|| CliError::Internal(anyhow::anyhow!("log entry carries no hash")))?;
2572 pb::ChangeRef {
2573 kind: Some(pb::change_ref::Kind::Hash(hash)),
2574 }
2575 }
2576 _ => pb::ChangeRef {
2577 kind: Some(pb::change_ref::Kind::Prefix(change_ref.to_string())),
2578 },
2579 };
2580
2581 let response = session.get_change(pb::GetChangeRequest {
2582 repository: Some(session.reference.clone()),
2583 r#ref: Some(reference),
2584 includes: Some(pb::ChangeIncludes {

Callers 1

diffFunction · 0.85

Calls 15

get_files_in_changeFunction · 0.85
as_refMethod · 0.80
get_output_configMethod · 0.80
file_matches_filterMethod · 0.80
filter_file_diffsMethod · 0.80
getMethod · 0.65
openFunction · 0.50
parseFunction · 0.50
deserializeFunction · 0.50

Tested by

no test coverage detected