Skip to content

Commit 329479c

Browse files
committed
ein t hours now uses the commit-info structure to avoid parsing a commit once more.
1 parent 068603a commit 329479c

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

gitoxide-core/src/hours/mod.rs

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use std::{collections::BTreeSet, io, path::Path, time::Instant};
22

3-
use anyhow::{anyhow, bail};
3+
use anyhow::bail;
44
use gix::{
55
actor,
66
bstr::{BStr, ByteSlice},
7-
interrupt,
87
prelude::*,
98
progress, Progress,
109
};
@@ -144,24 +143,31 @@ where
144143
let mut skipped_merge_commits = 0;
145144
const CHUNK_SIZE: usize = 50;
146145
let mut chunk = Vec::with_capacity(CHUNK_SIZE);
147-
let commit_iter = interrupt::Iter::new(
148-
commit_id.ancestors(|oid, buf| {
149-
progress.inc();
150-
repo.objects.find(oid, buf).map(|obj| {
151-
tx.send((commit_idx, obj.data.to_owned())).ok();
152-
if let Some((tx_tree, first_parent, commit)) = tx_tree_id.as_ref().and_then(|tx| {
153-
let mut parents = gix::objs::CommitRefIter::from_bytes(obj.data).parent_ids();
154-
let res = parents
146+
let mut commit_iter = commit_id.ancestors(|oid, buf| repo.objects.find_commit_iter(oid, buf));
147+
let mut is_shallow = false;
148+
while let Some(c) = commit_iter.next() {
149+
progress.inc();
150+
if gix::interrupt::is_triggered() {
151+
bail!("Cancelled by user");
152+
}
153+
match c {
154+
Ok(c) => {
155+
tx.send((commit_idx, commit_iter.commit_data().to_owned())).ok();
156+
let tree_delta_info = tx_tree_id.as_ref().and_then(|tx| {
157+
let mut parents = c.parent_ids.into_iter();
158+
parents
155159
.next()
156-
.map(|first_parent| (tx, Some(first_parent), oid.to_owned()));
157-
match parents.next() {
158-
Some(_) => {
159-
skipped_merge_commits += 1;
160-
None
161-
}
162-
None => res,
163-
}
164-
}) {
160+
.map(|first_parent| (tx, Some(first_parent), c.id.to_owned()))
161+
.filter(|_| {
162+
if parents.next().is_some() {
163+
skipped_merge_commits += 1;
164+
false
165+
} else {
166+
true
167+
}
168+
})
169+
});
170+
if let Some((tx_tree, first_parent, commit)) = tree_delta_info {
165171
if chunk.len() == CHUNK_SIZE {
166172
tx_tree
167173
.send(std::mem::replace(&mut chunk, Vec::with_capacity(CHUNK_SIZE)))
@@ -170,16 +176,8 @@ where
170176
chunk.push((commit_idx, first_parent, commit))
171177
}
172178
}
173-
commit_idx = commit_idx.checked_add(1).expect("less then 4 billion commits");
174-
gix::objs::CommitRefIter::from_bytes(obj.data)
175-
})
176-
}),
177-
|| anyhow!("Cancelled by user"),
178-
);
179-
let mut is_shallow = false;
180-
for c in commit_iter {
181-
match c? {
182-
Ok(c) => c,
179+
commit_idx += 1;
180+
}
183181
Err(gix::traverse::commit::ancestors::Error::FindExisting { .. }) => {
184182
is_shallow = true;
185183
break;

0 commit comments

Comments
 (0)