surf: stats for a given revision

The `stats` method always provided the stats at the `head` of the
repository.

Introduce the `stats_from` method which takes a revision to start
from. `stats` can be defined using `stats_from` and `head`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny
2022-12-22 12:07:58 +00:00
parent c2cc44bcc4
commit 5d7b1e4c01
2 changed files with 13 additions and 3 deletions
+12 -2
View File
@@ -336,10 +336,20 @@ impl Repository {
rev.to_commit(self)
}
/// Gets the [`Stats`] of this repository.
/// Gets the [`Stats`] of this repository starting from the
/// `HEAD` (see [`Repository::head`]) of the repository.
pub fn stats(&self) -> Result<Stats, Error> {
self.stats_from(&self.head()?)
}
/// Gets the [`Stats`] of this repository starting from the given
/// `rev`.
pub fn stats_from<R>(&self, rev: &R) -> Result<Stats, Error>
where
R: Revision,
{
let branches = self.branches(Glob::all_heads())?.count();
let mut history = self.history(self.head()?)?;
let mut history = self.history(rev)?;
let (commits, contributors) = history.try_fold(
(0, BTreeSet::new()),
|(commits, mut contributors), commit| {
+1 -1
View File
@@ -174,7 +174,7 @@ pub fn commits<R>(repo: &Repository, revision: &R) -> Result<Commits, Error>
where
R: git::Revision,
{
let stats = repo.stats()?;
let stats = repo.stats_from(revision)?;
let commits = repo.history(revision)?.collect::<Result<Vec<_>, _>>()?;
let headers = commits.into_iter().map(Header::from).collect();
Ok(Commits { headers, stats })