diff --git a/src/info/mod.rs b/src/info/mod.rs index 4412dfd5d..437498111 100644 --- a/src/info/mod.rs +++ b/src/info/mod.rs @@ -1,4 +1,5 @@ use crate::cli::{self, Config}; +use crate::repo::Commits; use crate::ui::get_ascii_colors; use crate::ui::text_colors::TextColors; use anyhow::{Context, Result}; @@ -183,23 +184,24 @@ impl Info { } }); - let mut internal_repo = Repo::new( - &repo, + let repo = Repo::new(&repo)?; + let mut commits = Commits::new( + repo.gitoxide(), config.no_merges, &config.bot_regex_pattern, config.number_of_authors, )?; - let (repo_name, repo_url) = internal_repo.get_name_and_url()?; - let head_refs = internal_repo.get_head_refs()?; - let version = internal_repo.get_version()?; - let git_username = internal_repo.get_git_username()?; - let number_of_tags = internal_repo.get_number_of_tags()?; - let number_of_branches = internal_repo.get_number_of_branches()?; - let creation_date = internal_repo.get_creation_date(config.iso_time); - let number_of_commits = internal_repo.get_number_of_commits(); - let (authors, contributors) = internal_repo.take_authors(config.show_email); - let last_change = internal_repo.get_date_of_last_commit(config.iso_time); - let (repo_size, file_count) = internal_repo.get_repo_size(); + let (repo_name, repo_url) = repo.get_name_and_url()?; + let head_refs = repo.get_head_refs()?; + let version = repo.get_version()?; + let git_username = repo.get_git_username()?; + let number_of_tags = repo.get_number_of_tags()?; + let number_of_branches = repo.get_number_of_branches()?; + let creation_date = commits.get_creation_date(config.iso_time); + let number_of_commits = commits.count(); + let (authors, contributors) = commits.take_authors(config.show_email); + let last_change = commits.get_date_of_last_commit(config.iso_time); + let (repo_size, file_count) = repo.get_repo_size(); let license = Detector::new()?.get_license(&workdir)?; let dependencies = DependencyDetector::new().get_dependencies(&workdir)?; diff --git a/src/info/repo.rs b/src/info/repo.rs index 28ecf2b78..648ea38ba 100644 --- a/src/info/repo.rs +++ b/src/info/repo.rs @@ -26,7 +26,6 @@ pub struct Commits { pub struct Repo<'a> { git2_repo: &'a Repository, repo: git::Repository, - commits: Commits, } #[derive(Hash, PartialOrd, Ord, Eq, PartialEq)] @@ -127,59 +126,42 @@ impl Commits { time_of_most_recent_commit, }) } -} - -impl<'a> Repo<'a> { - pub fn new( - git2_repo: &'a Repository, - no_merges: bool, - bot_regex_pattern: &Option, - number_of_authors_to_display: usize, - ) -> Result { - let repo = git::open(git2_repo.path())?; - let commits = Commits::new( - repo.clone(), - no_merges, - bot_regex_pattern, - number_of_authors_to_display, - )?; - - Ok(Self { - repo, - git2_repo, - commits, - }) - } pub fn get_creation_date(&self, iso_time: bool) -> String { - gitoxide_time_to_formatted_time(self.commits.time_of_first_commit, iso_time) + gitoxide_time_to_formatted_time(self.time_of_first_commit, iso_time) } - pub fn get_number_of_commits(&self) -> String { + pub fn count(&self) -> String { format!( "{}{}", - self.commits.num_commits, - self.commits - .is_shallow - .then(|| " (shallow)") - .unwrap_or_default() + self.num_commits, + self.is_shallow.then(|| " (shallow)").unwrap_or_default() ) } pub fn take_authors(&mut self, show_email: bool) -> (Vec, usize) { if !show_email { - for author in &mut self.commits.authors { + for author in &mut self.authors { author.clear_email(); } } - ( - std::mem::take(&mut self.commits.authors), - self.commits.total_num_authors, - ) + (std::mem::take(&mut self.authors), self.total_num_authors) } pub fn get_date_of_last_commit(&self, iso_time: bool) -> String { - gitoxide_time_to_formatted_time(self.commits.time_of_most_recent_commit, iso_time) + gitoxide_time_to_formatted_time(self.time_of_most_recent_commit, iso_time) + } +} + +impl<'a> Repo<'a> { + pub fn new(git2_repo: &'a Repository) -> Result { + let repo = git::open(git2_repo.path())?; + + Ok(Self { repo, git2_repo }) + } + + pub fn gitoxide(&self) -> git::Repository { + self.repo.clone() } // This collects the repo size excluding .git