Resolve the set of change hashes to split, from either the explicit positional list or `--last N`.
(
&self,
repo: &Repository,
from_view: &str,
)
| 197 | /// Resolve the set of change hashes to split, from either the explicit |
| 198 | /// positional list or `--last N`. |
| 199 | fn resolve_changes( |
| 200 | &self, |
| 201 | repo: &Repository, |
| 202 | from_view: &str, |
| 203 | ) -> CliResult<Vec<atomic_core::types::Hash>> { |
| 204 | use atomic_core::types::Hash; |
| 205 | |
| 206 | if let Some(n) = self.last { |
| 207 | if n == 0 { |
| 208 | return Err(CliError::InvalidArgument { |
| 209 | message: "--last must be greater than zero".to_string(), |
| 210 | }); |
| 211 | } |
| 212 | let all = repo |
| 213 | .view_own_change_hashes(from_view) |
| 214 | .map_err(CliError::Repository)?; |
| 215 | if all.len() < n { |
| 216 | return Err(CliError::InvalidArgument { |
| 217 | message: format!( |
| 218 | "view '{}' has only {} change(s); cannot split the last {}", |
| 219 | from_view, |
| 220 | all.len(), |
| 221 | n |
| 222 | ), |
| 223 | }); |
| 224 | } |
| 225 | return Ok(all[all.len() - n..].to_vec()); |
| 226 | } |
| 227 | |
| 228 | if self.changes.is_empty() { |
| 229 | return Err(CliError::InvalidArgument { |
| 230 | message: "specify one or more changes to split, or use --last <N>".to_string(), |
| 231 | }); |
| 232 | } |
| 233 | |
| 234 | let mut hashes = Vec::with_capacity(self.changes.len()); |
| 235 | for spec in &self.changes { |
| 236 | let hash = if let Some(h) = Hash::from_base32(spec.as_bytes()) { |
| 237 | h |
| 238 | } else { |
| 239 | repo.find_change_by_prefix(spec) |
| 240 | .map_err(CliError::Repository)? |
| 241 | .ok_or_else(|| CliError::ChangeNotFound { hash: spec.clone() })? |
| 242 | }; |
| 243 | hashes.push(hash); |
| 244 | } |
| 245 | Ok(hashes) |
| 246 | } |
| 247 | |
| 248 | /// Optionally switch to the new draft view. |
| 249 | fn maybe_switch(&self, repo: &mut Repository) -> CliResult<()> { |
no test coverage detected