Resolve the set of change hashes to split, from either the explicit positional list or `--last N`.
(
&self,
repo: &Repository,
from_view: &str,
)
| 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<()> { |
no test coverage detected