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