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

Method resolve_changes

atomic-cli/src/commands/view/split.rs:332–379  ·  view source on GitHub ↗

Resolve the set of change hashes to split, from either the explicit positional list or `--last N`.

(
        &self,
        repo: &Repository,
        from_view: &str,
    )

Source from the content-addressed store, hash-verified

330 /// Resolve the set of change hashes to split, from either the explicit
331 /// positional list or `--last N`.
332 fn resolve_changes(
333 &self,
334 repo: &Repository,
335 from_view: &str,
336 ) -> CliResult<Vec<atomic_core::types::Hash>> {
337 use atomic_core::types::Hash;
338
339 if let Some(n) = self.last {
340 if n == 0 {
341 return Err(CliError::InvalidArgument {
342 message: "--last must be greater than zero".to_string(),
343 });
344 }
345 let all = repo
346 .view_own_change_hashes(from_view)
347 .map_err(CliError::Repository)?;
348 if all.len() < n {
349 return Err(CliError::InvalidArgument {
350 message: format!(
351 "view '{}' has only {} change(s); cannot split the last {}",
352 from_view,
353 all.len(),
354 n
355 ),
356 });
357 }
358 return Ok(all[all.len() - n..].to_vec());
359 }
360
361 if self.changes.is_empty() {
362 return Err(CliError::InvalidArgument {
363 message: "specify one or more changes to split, or use --last <N>".to_string(),
364 });
365 }
366
367 let mut hashes = Vec::with_capacity(self.changes.len());
368 for spec in &self.changes {
369 let hash = if let Some(h) = Hash::from_base32(spec.as_bytes()) {
370 h
371 } else {
372 repo.find_change_by_prefix(spec)
373 .map_err(CliError::Repository)?
374 .ok_or_else(|| CliError::ChangeNotFound { hash: spec.clone() })?
375 };
376 hashes.push(hash);
377 }
378 Ok(hashes)
379 }
380
381 /// Optionally switch to the new draft view.
382 fn maybe_switch(&self, repo: &mut Repository, working_copy: WorkingCopyId) -> CliResult<()> {

Callers 1

planMethod · 0.80

Calls 7

find_change_by_prefixMethod · 0.80
lenMethod · 0.45
is_emptyMethod · 0.45
as_bytesMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected