use std::path::{Path, PathBuf};
use std::process::{Command, Output};
pub use fallow_types::churn::ChurnTrend;
use rustc_hash::FxHashMap;
use crate::core_backend;
pub type ChurnSpawnHook = fn(&mut Command) -> std::io::Result<Output>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SinceDuration {
pub git_after: String,
pub display: String,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct AuthorContribution {
pub commits: u32,
pub weighted_commits: f64,
pub first_commit_ts: u64,
pub last_commit_ts: u64,
}
#[derive(Debug, Clone)]
pub struct FileChurn {
pub path: PathBuf,
pub commits: u32,
pub weighted_commits: f64,
pub lines_added: u32,
pub lines_deleted: u32,
pub trend: ChurnTrend,
pub authors: FxHashMap<u32, AuthorContribution>,
}
#[derive(Debug, Clone)]
pub struct ChurnResult {
pub files: FxHashMap<PathBuf, FileChurn>,
pub shallow_clone: bool,
pub author_pool: Vec<String>,
}
pub fn set_spawn_hook(hook: ChurnSpawnHook) {
core_backend::set_churn_spawn_hook(hook);
}
pub fn parse_since(input: &str) -> Result<SinceDuration, String> {
core_backend::parse_since(input)
}
#[must_use]
pub fn analyze_churn(root: &Path, since: &SinceDuration) -> Option<ChurnResult> {
core_backend::analyze_churn(root, since)
}
pub fn analyze_churn_from_file(path: &Path, root: &Path) -> Result<ChurnResult, String> {
core_backend::analyze_churn_from_file(path, root)
}
#[must_use]
pub fn is_git_repo(root: &Path) -> bool {
core_backend::is_git_repo(root)
}
#[must_use]
pub fn analyze_churn_cached(
root: &Path,
since: &SinceDuration,
cache_dir: &Path,
no_cache: bool,
) -> Option<(ChurnResult, bool)> {
core_backend::analyze_churn_cached(root, since, cache_dir, no_cache)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parse_since_returns_engine_owned_duration() {
let duration = parse_since("6m").expect("duration should parse");
assert_eq!(duration.git_after, "6 months ago");
assert_eq!(duration.display, "6 months");
}
}