Skip to content

Commit 7734793

Browse files
committed
empty iterators
1 parent 9a7c044 commit 7734793

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/git/repository.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ pub struct CommitRange<'a> {
4646
}
4747

4848
impl<'a> CommitRange<'a> {
49+
/// Create an empty CommitRange with no commits in its iterator.
50+
pub fn empty(repo: &'a Repository) -> Self {
51+
Self {
52+
repo,
53+
start_oid: String::new(),
54+
end_oid: String::new(),
55+
refname: String::new(),
56+
}
57+
}
58+
4959
#[allow(dead_code)]
5060
pub fn new(
5161
repo: &'a Repository,
@@ -221,6 +231,15 @@ impl<'a> IntoIterator for CommitRange<'a> {
221231
type IntoIter = CommitRangeIterator<'a>;
222232

223233
fn into_iter(self) -> Self::IntoIter {
234+
// Empty range - return empty iterator
235+
if self.start_oid.is_empty() && self.end_oid.is_empty() {
236+
return CommitRangeIterator {
237+
repo: self.repo,
238+
commit_oids: Vec::new(),
239+
index: 0,
240+
};
241+
}
242+
224243
// ie for single commit branches
225244
if self.start_oid == self.end_oid {
226245
return CommitRangeIterator {

0 commit comments

Comments
 (0)