Returns a map of `file_path` → `commit_count` for the last `days` days. Shells out to `git log --format= --name-only --since='{days} days ago'`. Returns an empty map if git is not available or not a repo.
(project_root: &Path, days: u32)
| 11 | /// Shells out to `git log --format= --name-only --since='{days} days ago'`. |
| 12 | /// Returns an empty map if git is not available or not a repo. |
| 13 | pub async fn file_churn(project_root: &Path, days: u32) -> Result<HashMap<String, usize>> { |
| 14 | let output = tokio::process::Command::new(crate::git::git_program()) |
| 15 | .args([ |
| 16 | "log", |
| 17 | "--format=", |
| 18 | "--name-only", |
| 19 | &format!("--since={days} days ago"), |
| 20 | ]) |
| 21 | .current_dir(project_root) |
| 22 | .output() |
| 23 | .await; |
| 24 | |
| 25 | // git not found or other OS error → return empty map gracefully |
| 26 | let Ok(output) = output else { |
| 27 | return Ok(HashMap::new()); |
| 28 | }; |
| 29 | |
| 30 | if !output.status.success() { |
| 31 | // Not a git repo, or another non-fatal git error |
| 32 | return Ok(HashMap::new()); |
| 33 | } |
| 34 | |
| 35 | let stdout = String::from_utf8_lossy(&output.stdout); |
| 36 | let mut churn: HashMap<String, usize> = HashMap::new(); |
| 37 | for line in stdout.lines() { |
| 38 | let trimmed = line.trim(); |
| 39 | if trimmed.is_empty() { |
| 40 | continue; |
| 41 | } |
| 42 | *churn.entry(trimmed.to_string()).or_insert(0) += 1; |
| 43 | } |
| 44 | Ok(churn) |
| 45 | } |