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

Function diff

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

`atomic diff` over DiffWorkingCopy / Diff / GetChange. The working-copy and view-pair forms render the wire's DiffChunk patches client-side — including `--json` (the versioned document shape the local body emits) and `--word-diff` (the same pairing + token-level highlighting the local unified renderer applies, over the parsed patch lines). `-c ` loads the change bundle over GetChange and runs

(args: &super::diff::command::Diff)

Source from the content-addressed store, hash-verified

2150/// ("reserved for future use") with no local behavior and no wire shape,
2151/// so it keeps the local body.
2152pub fn diff(args: &super::diff::command::Diff) -> CliResult<bool> {
2153 if args.git || args.snapshot {
2154 return Ok(false);
2155 }
2156 // The view-pair form (--from/--to) is the Diff RPC's RefPairScope arm.
2157 if let (Some(from), Some(to)) = (&args.from, &args.to) {
2158 return diff_view_pair(args, from, to);
2159 }
2160 // The `-c <id>` form: a recorded change's content, over GetChange.
2161 if let Some(change_ref) = args.change.clone() {
2162 return diff_change(args, &change_ref);
2163 }
2164 if args.cached {
2165 return Ok(false); // reserved for future use: a no-op flag needs no wire
2166 }
2167 super::workspace_txn::prepare_service_query(false)?;
2168 let session = match Service::open()? {
2169 Some(session) => session,
2170 None => return Ok(false),
2171 };
2172 let (stat_only, name_only, include_untracked, files) = (
2173 args.stat,
2174 args.name_only,
2175 args.untracked,
2176 args.files.clone(),
2177 );
2178 let response = session.diff_working_copy(pb::DiffWorkingCopyRequest {
2179 repository: Some(session.reference.clone()),
2180 word_diff: args.word_diff,
2181 working_copy: Some(pb::WorkingCopyScope {
2182 include_untracked,
2183 paths: files,
2184 }),
2185 stat_only,
2186 })?;
2187
2188 // One render, two data sources: rebuild the FileDiffs the local path
2189 // would have built from the wire's status + contents, then hand them to
2190 // the SAME formatters (print_unified/print_stat/... — including the
2191 // versioned JSON document and word-diff pairing). The bridge grows no
2192 // rendering dialect of its own.
2193 if response.is_empty() {
2194 let repo_root = crate::commands::find_repository_root()?;
2195 let repo = atomic_repository::Repository::open(&repo_root).map_err(CliError::Repository)?;
2196 let view = current_view_name()?;
2197 args.print_no_pending_changes(&repo, &view);
2198 return Ok(true);
2199 }
2200
2201 let algorithm = args.parse_algorithm()?;
2202 let config = args.get_output_config();
2203 let view = current_view_name()?;
2204
2205 let mut file_diffs = Vec::new();
2206 let mut stats = super::diff::types::DiffStats::new();
2207 for chunk in &response {
2208 if let Some(file_diff) = file_diff_from_chunk(chunk, &algorithm, config.context_lines) {
2209 stats.add_file(file_diff.stats.clone());

Callers 1

runMethod · 0.50

Calls 15

diff_view_pairFunction · 0.85
diff_changeFunction · 0.85
prepare_service_queryFunction · 0.85
openFunction · 0.85
find_repository_rootFunction · 0.85
current_view_nameFunction · 0.85
file_diff_from_chunkFunction · 0.85
get_output_configMethod · 0.80
cloneMethod · 0.45
diff_working_copyMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected