Skip to content

Commit

Permalink
monad: Add commit count to repo-info
Browse files Browse the repository at this point in the history
Summary: You'd think that we, as the source control team, have an easy way of telling how many commits there are in a repo, right?... right?

Reviewed By: mzr

Differential Revision: D65826187

fbshipit-source-id: e2f6dbe0ef4a32e3420da03077fe6a0c33df49b0
  • Loading branch information
lmvasquezg authored and facebook-github-bot committed Nov 13, 2024
1 parent 02b5f5c commit 31f758f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use futures::Stream;
use futures::StreamExt;
use futures::TryStreamExt;
use mononoke_types::ChangesetId;
use mononoke_types::RepositoryId;

use crate::SqlCommitGraphStorage;

Expand Down Expand Up @@ -193,6 +194,10 @@ impl CommitGraphBulkFetcher {
)
.try_flatten()
}

pub async fn fetch_commit_count(&self, ctx: &CoreContext, id: RepositoryId) -> Result<u64> {
self.storage.fetch_commit_count(ctx, id).await
}
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,10 @@ mononoke_queries! {
LIMIT {limit}"
)
}

read GetCommitCount(id: RepositoryId) -> (u64) {
"SELECT COUNT(*) FROM commit_graph_edges WHERE repo_id={id}"
}
}

type FetchedEdgesRow = (
Expand Down Expand Up @@ -1368,6 +1372,14 @@ impl SqlCommitGraphStorage {
)
.await
}

// Returns the amount of commits in a repo. Only to be used for ad-hoc internal operations
pub async fn fetch_commit_count(&self, ctx: &CoreContext, id: RepositoryId) -> Result<u64> {
let conn = self.read_conn(true);
let result =
GetCommitCount::maybe_traced_query(conn, ctx.client_request_info(), &id).await?;
Ok(result.first().map_or(0, |(count,)| *count))
}
}

#[async_trait]
Expand Down
12 changes: 12 additions & 0 deletions eden/mononoke/tools/admin/src/commands/repo_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use mononoke_app::args::RepoArgs;
use mononoke_app::MononokeApp;
use repo_identity::RepoIdentity;
use repo_identity::RepoIdentityRef;
use sql_commit_graph_storage::CommitGraphBulkFetcher;
use sql_commit_graph_storage::CommitGraphBulkFetcherRef;

/// Show information about a repository
#[derive(Parser)]
Expand All @@ -31,6 +33,9 @@ pub struct Repo {

#[facet]
bookmarks: dyn Bookmarks,

#[facet]
commit_graph_bulk_fetcher: CommitGraphBulkFetcher,
}

pub async fn run(app: MononokeApp, args: CommandArgs) -> Result<()> {
Expand All @@ -56,5 +61,12 @@ pub async fn run(app: MononokeApp, args: CommandArgs) -> Result<()> {
main_bookmark,
main_bookmark_value.as_deref().unwrap_or("(not set)")
);

let commits = repo
.commit_graph_bulk_fetcher()
.fetch_commit_count(&ctx, repo.repo_identity().id())
.await?;

println!("Commits: {}", commits);
Ok(())
}

0 comments on commit 31f758f

Please sign in to comment.