From d2441f1b3a6c1921d05d62d49dcd76ad991d553a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Thu, 4 Jun 2026 13:31:41 +0200 Subject: [PATCH] Speed up commit count with a direct revwalk --- crates/radicle-types/src/traits/repo.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/radicle-types/src/traits/repo.rs b/crates/radicle-types/src/traits/repo.rs index 353607fc2..308dbb711 100644 --- a/crates/radicle-types/src/traits/repo.rs +++ b/crates/radicle-types/src/traits/repo.rs @@ -678,10 +678,17 @@ pub trait Repo: Profile { let profile = self.profile(); let repo = profile.storage.repository(rid)?; - let repo = surf::Repository::open(repo.path())?; - let count = repo.history(crate::oid::into_surf(head))?.count(); + // Walk the commit graph directly instead of through radicle-surf's + // History iterator, which materializes and parses a full Commit for + // every node just to discard it. Counting only needs the reachable + // OIDs, and no ordering, so the walk is unsorted. The walk itself is + // not a verification step: trust comes from the signed `head` tip, and + // git's content-addressed DAG keeps its ancestry tamper-evident. + let mut revwalk = repo.backend.revwalk()?; + revwalk.set_sorting(git2::Sort::NONE)?; + revwalk.push(head.into())?; - Ok(count) + Ok(revwalk.count()) } fn repo_commit(