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