1use crate::Oid;
2use anyhow::{anyhow, Result};
3use collections::HashMap;
4use std::path::Path;
5
6pub fn get_messages(working_directory: &Path, shas: &[Oid]) -> Result<HashMap<Oid, String>> {
7 if shas.is_empty() {
8 return Ok(HashMap::default());
9 }
10
11 const MARKER: &str = "<MARKER>";
12
13 let output = util::command::new_std_command("git")
14 .current_dir(working_directory)
15 .arg("show")
16 .arg("-s")
17 .arg(format!("--format=%B{}", MARKER))
18 .args(shas.iter().map(ToString::to_string))
19 .output()
20 .map_err(|e| anyhow!("Failed to start git blame process: {}", e))?;
21
22 anyhow::ensure!(
23 output.status.success(),
24 "'git show' failed with error {:?}",
25 output.status
26 );
27
28 Ok(shas
29 .iter()
30 .cloned()
31 .zip(
32 String::from_utf8_lossy(&output.stdout)
33 .trim()
34 .split_terminator(MARKER)
35 .map(|str| str.trim().replace("<", "<").replace(">", ">")),
36 )
37 .collect::<HashMap<Oid, String>>())
38}