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

Function run_from_view

atomic-cli/src/commands/insert.rs:240–305  ·  view source on GitHub ↗

Insert changes from one view to another.

(repo: &Repository, args: &FromViewArgs)

Source from the content-addressed store, hash-verified

238
239/// Insert changes from one view to another.
240fn run_from_view(repo: &Repository, args: &FromViewArgs) -> CliResult<()> {
241 let to_view = args
242 .to_view
243 .clone()
244 .unwrap_or_else(|| repo.current_view().to_string());
245 let is_current_view = to_view == repo.current_view();
246
247 output::print_info(&format!(
248 "Inserting changes from '{}' to '{}'...",
249 args.from_view, to_view
250 ));
251
252 let options = CrossViewInsertOptions::new(&args.from_view, &to_view)
253 .with_dependencies(args.deps)
254 .allow_conflicts(args.allow_conflicts)
255 .dry_run(args.dry_run);
256
257 let outcome = repo
258 .insert_from_view(options)
259 .map_err(|e| CliError::Conflict {
260 description: e.to_string(),
261 })?;
262
263 print_cross_view_outcome(&outcome, args.dry_run);
264
265 // Update working copy if we inserted into the current view.
266 // Collect affected file paths from the inserted changes and only
267 // materialize those, avoiding a full rematerialization of the
268 // entire working copy.
269 if is_current_view && !args.dry_run && outcome.changes_applied > 0 {
270 let spinner = output::create_spinner("Materializing files for view...");
271
272 let mut affected_paths = std::collections::HashSet::new();
273 for hash in &outcome.applied_hashes {
274 if let Ok(change) = repo.load_change(hash) {
275 for op in change.hunks() {
276 if let Some(p) = op.path() {
277 affected_paths.insert(p.to_string());
278 }
279 }
280 }
281 }
282
283 let output_result = if affected_paths.is_empty() {
284 // No path info available (e.g. AddRoot-only changes) —
285 // fall back to full materialize.
286 repo.materialize().map_err(|e| {
287 CliError::Internal(anyhow::anyhow!("Failed to update working copy: {}", e))
288 })?
289 } else {
290 repo.materialize_paths(affected_paths).map_err(|e| {
291 CliError::Internal(anyhow::anyhow!("Failed to update working copy: {}", e))
292 })?
293 };
294
295 output::finish_success(
296 &spinner,
297 &format!(

Callers 1

runMethod · 0.85

Calls 15

print_infoFunction · 0.85
print_cross_view_outcomeFunction · 0.85
create_spinnerFunction · 0.85
finish_successFunction · 0.85
current_viewMethod · 0.80
allow_conflictsMethod · 0.80
insert_from_viewMethod · 0.80
materializeMethod · 0.80
materialize_pathsMethod · 0.80
cloneMethod · 0.45
dry_runMethod · 0.45
with_dependenciesMethod · 0.45

Tested by

no test coverage detected