Parent
[>]
1//! Git repository helpers used across route handlers. 2//! 3//! Provides convenience functions for common `gix` operations such as opening a 4//! repository, formatting commit dates, validating paths, and iterating 5//! references. The [`GitResultExt`] extension trait lets handlers convert gix 6//! errors into [`Error::GitCorrupt`] with a single `.corrupt()` call. 7 8use Path; 9 10use Timestamp; 11use ; 12 13use crate; 14 15/// Opens a repository at `root/{name}` or returns [`Error::RepoNotFound`]. 16 19 20/// Rejects paths containing non-normal [`Component`]s (e.g. `..`) to prevent 21/// directory traversal. 22 31 32/// Returns the commit's author timestamp as Unix seconds. 33 36 37/// Formats a commit's author date as a `YYYY-MM-DD` string in the commit's 38/// local timezone, returning `None` if the time cannot be parsed. 39 43 44/// Formats a commit's committer date as a `YYYY-MM-DD` string in the 45/// commit's local timezone, returning `None` if the time cannot be parsed. 46 51 52/// Converts a Unix timestamp + timezone offset into a `YYYY-MM-DD` string. 53 59 60/// Extension trait adding `.corrupt()` to `Result<T, E>` where `E: Display`. 61/// 62/// Converts an error into [`Error::GitCorrupt`] by calling `.to_string()` on 63/// the inner error value. This removes the need for repetitive 64/// `.map_err(|e| Error::GitCorrupt(e.to_string()))` chains. 65/// 66/// # Usage 67/// 68/// ```ignore 69/// use crate::git::GitResultExt as _; 70/// let repo = git_repo.references().corrupt()?; 71/// ``` 72 75 76 81 82/// Silently flattens a `Result<impl IntoIterator<Item = Result<T, E2>>, E1>` into 83/// an `Iterator<Item = T>`. 84/// 85/// Both the outer and inner `Result` layers are consumed via `.into_iter()` and 86/// `.flatten()`, so errors at either level are silently skipped. This matches 87/// the common git-ref iteration pattern where a single corrupt ref should not 88/// crash the page. 89