From 5d7b1e4c01e300b049e8d5f393c297af38d7b3e3 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Wed, 21 Dec 2022 15:14:27 +0000 Subject: [PATCH] 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 X-Clacks-Overhead: GNU Terry Pratchett --- radicle-surf/src/git/repo.rs | 14 ++++++++++++-- radicle-surf/src/source/commit.rs | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/radicle-surf/src/git/repo.rs b/radicle-surf/src/git/repo.rs index 91efd95..4396d19 100644 --- a/radicle-surf/src/git/repo.rs +++ b/radicle-surf/src/git/repo.rs @@ -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 { + self.stats_from(&self.head()?) + } + + /// Gets the [`Stats`] of this repository starting from the given + /// `rev`. + pub fn stats_from(&self, rev: &R) -> Result + 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| { diff --git a/radicle-surf/src/source/commit.rs b/radicle-surf/src/source/commit.rs index 048a70b..91ec149 100644 --- a/radicle-surf/src/source/commit.rs +++ b/radicle-surf/src/source/commit.rs @@ -174,7 +174,7 @@ pub fn commits(repo: &Repository, revision: &R) -> Result where R: git::Revision, { - let stats = repo.stats()?; + let stats = repo.stats_from(revision)?; let commits = repo.history(revision)?.collect::, _>>()?; let headers = commits.into_iter().map(Header::from).collect(); Ok(Commits { headers, stats })