Skip to content

Commit 927815a

Browse files
committed
Make clear that the commit count might be truncated due to shallow cloning
1 parent eb753f9 commit 927815a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Diff for: src/info/repo.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub struct Repo<'a> {
2020
authors: Vec<Author>,
2121
total_num_authors: usize,
2222
num_commits: usize,
23+
/// false if we have found the first commit that started it all, true if the repository is shallow.
24+
is_shallow: bool,
2325
time_of_most_recent_commit: git::actor::Time,
2426
time_of_first_commit: git::actor::Time,
2527
}
@@ -100,6 +102,7 @@ impl<'a> Repo<'a> {
100102
let mut time_of_most_recent_commit = None;
101103
let mut time_of_first_commit = None;
102104
let mut commit_iter = repo.head_commit()?.ancestors().all().peekable();
105+
let mut is_shallow = false;
103106

104107
let mailmap = repo.load_mailmap();
105108
let mut author_to_number_of_commits: HashMap<Sig, usize> = HashMap::new();
@@ -112,7 +115,10 @@ impl<'a> Repo<'a> {
112115
.object()
113116
.expect("commit is still present/comes from cache")
114117
.into_commit(),
115-
Err(git::traverse::commit::ancestors::Error::FindExisting { .. }) => break, // assume a shallow clone
118+
Err(git::traverse::commit::ancestors::Error::FindExisting { .. }) => {
119+
is_shallow = true;
120+
break;
121+
}
116122
Err(err) => return Err(err.into()),
117123
};
118124

@@ -174,6 +180,7 @@ impl<'a> Repo<'a> {
174180
authors,
175181
total_num_authors,
176182
num_commits,
183+
is_shallow,
177184
time_of_first_commit,
178185
time_of_most_recent_commit,
179186
})
@@ -184,7 +191,11 @@ impl<'a> Repo<'a> {
184191
}
185192

186193
pub fn get_number_of_commits(&self) -> String {
187-
self.num_commits.to_string()
194+
format!(
195+
"{}{}",
196+
self.num_commits,
197+
self.is_shallow.then(|| " (shallow)").unwrap_or_default()
198+
)
188199
}
189200

190201
pub fn take_authors(&mut self, show_email: bool) -> (Vec<Author>, usize) {

0 commit comments

Comments
 (0)