Skip to main content

Crate gitmeta

Crate gitmeta 

Source
Expand description

Fast per-file git metadata for Rust — last-commit time / author / subject, first-seen, commit count (churn), and tracked / ignored status — resolved by scanning a working tree once and answering per-path lookups in constant time.

The batch design is the point: one Cache runs git ls-files plus a single git log pass up front, so a 10k-file / 5k-commit repo costs a handful of git invocations (~½ s) instead of 10k git log -1 -- <path> calls (~100 s). It shells out to the system git binary rather than reimplementing git.

§One-shot Cache

let Some(cache) = gitmeta::Cache::new("/path/to/repo")? else {
    // Not a git working tree (or no git binary) — treat as "no git data".
    return Ok(());
};

if let Some(info) = cache.lookup("/path/to/repo/src/main.rs") {
    println!("{} by {} — {} commits",
        info.last_commit_time, info.last_commit_author, info.commit_count);
}
assert!(cache.is_tracked("/path/to/repo/Cargo.toml") || true);

§Pool — reuse across calls

A Pool keeps one Cache per repo and re-validates on HEAD change, so repeated lookups over an unchanging tree don’t re-scan — ideal for a long-running process (server, watcher, language tooling).

let pool = gitmeta::Pool::new();
if let Some(cache) = pool.get("/path/to/repo")? {
    let _ = cache.is_tracked("/path/to/repo/README.md");
}

§Why git rather than filesystem mtimes?

A fresh clone sets every file’s mtime to checkout time — so “recently changed” / “hot file” questions need git history, not the filesystem.

§Async

Enable the tokio feature for Cache::new_async, Pool::get_async, and Pool::warm_async. The sync API pulls in no async runtime.

Structs§

Cache
A scanned working tree. Build one with Cache::new (or Cache::new_async under the tokio feature) and consult it with lookup, is_tracked, and is_ignored.
FileGitInfo
Per-file git metadata resolved for every tracked path in a working tree.
Pool
Caches one Cache per canonical repository root, re-validating on HEAD change. Safe for concurrent use.

Enums§

Error
Errors returned when git is present but a command fails.

Functions§

has_git_binary
Whether a usable git executable is on PATH.