MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / file_churn

Function file_churn

src/graph/git.rs:13–45  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
13pub 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}

Callers 3

handle_test_riskFunction · 0.85
test_file_churnFunction · 0.85

Calls 5

outputMethod · 0.80
successMethod · 0.80
entryMethod · 0.80
git_programFunction · 0.50
is_emptyMethod · 0.45

Tested by 2

test_file_churnFunction · 0.68