Skip to content

Commit 7b34b0a

Browse files
committed
refactor: completely separate Commits and Repo structure
1 parent d00ab45 commit 7b34b0a

File tree

2 files changed

+34
-50
lines changed

2 files changed

+34
-50
lines changed

src/info/mod.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::cli::{self, Config};
2+
use crate::repo::Commits;
23
use crate::ui::get_ascii_colors;
34
use crate::ui::text_colors::TextColors;
45
use anyhow::{Context, Result};
@@ -183,23 +184,24 @@ impl Info {
183184
}
184185
});
185186

186-
let mut internal_repo = Repo::new(
187-
&repo,
187+
let repo = Repo::new(&repo)?;
188+
let mut commits = Commits::new(
189+
repo.gitoxide(),
188190
config.no_merges,
189191
&config.bot_regex_pattern,
190192
config.number_of_authors,
191193
)?;
192-
let (repo_name, repo_url) = internal_repo.get_name_and_url()?;
193-
let head_refs = internal_repo.get_head_refs()?;
194-
let version = internal_repo.get_version()?;
195-
let git_username = internal_repo.get_git_username()?;
196-
let number_of_tags = internal_repo.get_number_of_tags()?;
197-
let number_of_branches = internal_repo.get_number_of_branches()?;
198-
let creation_date = internal_repo.get_creation_date(config.iso_time);
199-
let number_of_commits = internal_repo.get_number_of_commits();
200-
let (authors, contributors) = internal_repo.take_authors(config.show_email);
201-
let last_change = internal_repo.get_date_of_last_commit(config.iso_time);
202-
let (repo_size, file_count) = internal_repo.get_repo_size();
194+
let (repo_name, repo_url) = repo.get_name_and_url()?;
195+
let head_refs = repo.get_head_refs()?;
196+
let version = repo.get_version()?;
197+
let git_username = repo.get_git_username()?;
198+
let number_of_tags = repo.get_number_of_tags()?;
199+
let number_of_branches = repo.get_number_of_branches()?;
200+
let creation_date = commits.get_creation_date(config.iso_time);
201+
let number_of_commits = commits.count();
202+
let (authors, contributors) = commits.take_authors(config.show_email);
203+
let last_change = commits.get_date_of_last_commit(config.iso_time);
204+
let (repo_size, file_count) = repo.get_repo_size();
203205
let license = Detector::new()?.get_license(&workdir)?;
204206
let dependencies = DependencyDetector::new().get_dependencies(&workdir)?;
205207

src/info/repo.rs

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub struct Commits {
2626
pub struct Repo<'a> {
2727
git2_repo: &'a Repository,
2828
repo: git::Repository,
29-
commits: Commits,
3029
}
3130

3231
#[derive(Hash, PartialOrd, Ord, Eq, PartialEq)]
@@ -127,59 +126,42 @@ impl Commits {
127126
time_of_most_recent_commit,
128127
})
129128
}
130-
}
131-
132-
impl<'a> Repo<'a> {
133-
pub fn new(
134-
git2_repo: &'a Repository,
135-
no_merges: bool,
136-
bot_regex_pattern: &Option<Regex>,
137-
number_of_authors_to_display: usize,
138-
) -> Result<Self> {
139-
let repo = git::open(git2_repo.path())?;
140-
let commits = Commits::new(
141-
repo.clone(),
142-
no_merges,
143-
bot_regex_pattern,
144-
number_of_authors_to_display,
145-
)?;
146-
147-
Ok(Self {
148-
repo,
149-
git2_repo,
150-
commits,
151-
})
152-
}
153129

154130
pub fn get_creation_date(&self, iso_time: bool) -> String {
155-
gitoxide_time_to_formatted_time(self.commits.time_of_first_commit, iso_time)
131+
gitoxide_time_to_formatted_time(self.time_of_first_commit, iso_time)
156132
}
157133

158-
pub fn get_number_of_commits(&self) -> String {
134+
pub fn count(&self) -> String {
159135
format!(
160136
"{}{}",
161-
self.commits.num_commits,
162-
self.commits
163-
.is_shallow
164-
.then(|| " (shallow)")
165-
.unwrap_or_default()
137+
self.num_commits,
138+
self.is_shallow.then(|| " (shallow)").unwrap_or_default()
166139
)
167140
}
168141

169142
pub fn take_authors(&mut self, show_email: bool) -> (Vec<Author>, usize) {
170143
if !show_email {
171-
for author in &mut self.commits.authors {
144+
for author in &mut self.authors {
172145
author.clear_email();
173146
}
174147
}
175-
(
176-
std::mem::take(&mut self.commits.authors),
177-
self.commits.total_num_authors,
178-
)
148+
(std::mem::take(&mut self.authors), self.total_num_authors)
179149
}
180150

181151
pub fn get_date_of_last_commit(&self, iso_time: bool) -> String {
182-
gitoxide_time_to_formatted_time(self.commits.time_of_most_recent_commit, iso_time)
152+
gitoxide_time_to_formatted_time(self.time_of_most_recent_commit, iso_time)
153+
}
154+
}
155+
156+
impl<'a> Repo<'a> {
157+
pub fn new(git2_repo: &'a Repository) -> Result<Self> {
158+
let repo = git::open(git2_repo.path())?;
159+
160+
Ok(Self { repo, git2_repo })
161+
}
162+
163+
pub fn gitoxide(&self) -> git::Repository {
164+
self.repo.clone()
183165
}
184166

185167
// This collects the repo size excluding .git

0 commit comments

Comments
 (0)