commit.rs

 1use crate::Oid;
 2use anyhow::{Result, anyhow};
 3use collections::HashMap;
 4use std::path::Path;
 5
 6pub async 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_smol_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        .await
21        .map_err(|e| anyhow!("Failed to start git blame process: {}", e))?;
22
23    anyhow::ensure!(
24        output.status.success(),
25        "'git show' failed with error {:?}",
26        output.status
27    );
28
29    Ok(shas
30        .iter()
31        .cloned()
32        .zip(
33            String::from_utf8_lossy(&output.stdout)
34                .trim()
35                .split_terminator(MARKER)
36                .map(|str| str.trim().replace("<", "&lt;").replace(">", "&gt;")),
37        )
38        .collect::<HashMap<Oid, String>>())
39}