Synthesize a commit message from Atomic change messages.
(&self, repo: &Repository, history: &[HistoryEntry])
| 220 | |
| 221 | /// Synthesize a commit message from Atomic change messages. |
| 222 | fn synthesize_message(&self, repo: &Repository, history: &[HistoryEntry]) -> String { |
| 223 | let mut messages: Vec<String> = Vec::new(); |
| 224 | for entry in history.iter().rev().take(20) { |
| 225 | if let Ok(change) = repo.load_change(&entry.hash) { |
| 226 | let msg = change.hashed.header.message.clone(); |
| 227 | if !msg.is_empty() { |
| 228 | messages.push(msg); |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | if messages.is_empty() { |
| 234 | return "Atomic changes".to_string(); |
| 235 | } |
| 236 | |
| 237 | if messages.len() == 1 { |
| 238 | return messages.into_iter().next().unwrap(); |
| 239 | } |
| 240 | |
| 241 | // Multiple messages: bullet list |
| 242 | let mut result = format!("{} Atomic changes", messages.len()); |
| 243 | for msg in &messages { |
| 244 | let first_line = msg.lines().next().unwrap_or(msg); |
| 245 | result.push_str(&format!("\n\n* {}", first_line)); |
| 246 | } |
| 247 | result |
| 248 | } |
| 249 | |
| 250 | /// Push the current branch to the remote. |
| 251 | fn push_to_remote(&self, git_repo: &GitRepository) -> CliResult<()> { |