Skip to content

Commit d79b506

Browse files
committed
Adjust to breaking changes in git-traverse (#364)
1 parent 83746f6 commit d79b506

File tree

7 files changed

+15
-22
lines changed

7 files changed

+15
-22
lines changed

experiments/diffing/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn main() -> anyhow::Result<()> {
4141
let db = db
4242
.to_cache()
4343
.with_pack_cache(|| Box::new(odb::pack::cache::lru::StaticLinkedList::<64>::default()));
44-
move |oid, buf| db.find_commit_iter(oid, buf).ok()
44+
move |oid, buf| db.find_commit_iter(oid, buf)
4545
})
4646
.collect::<Result<Vec<_>, _>>()?;
4747
let num_diffs = all_commits.len();

experiments/traversal/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn main() -> anyhow::Result<()> {
3737

3838
let start = Instant::now();
3939
let all_commits = commit_id
40-
.ancestors(|oid, buf| db.find_commit_iter(oid, buf).ok())
40+
.ancestors(|oid, buf| db.find_commit_iter(oid, buf))
4141
.collect::<Result<Vec<_>, _>>()?;
4242
let elapsed = start.elapsed();
4343
println!(
@@ -146,7 +146,7 @@ fn do_gitoxide_commit_graph_traversal<C>(
146146
where
147147
C: odb::pack::cache::DecodeEntry,
148148
{
149-
let ancestors = tip.ancestors(|oid, buf| db.find_commit_iter(oid, buf).ok());
149+
let ancestors = tip.ancestors(|oid, buf| db.find_commit_iter(oid, buf));
150150
let mut commits = 0;
151151
for commit_id in ancestors {
152152
let _ = commit_id?;

git-diff/tests/visit/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,8 @@ mod changes {
135135

136136
let head = head_of(db);
137137
commit::Ancestors::new(Some(head), commit::ancestors::State::default(), |oid, buf| {
138-
db.try_find(oid, buf)
139-
.ok()
140-
.flatten()
141-
.and_then(|t| t.0.try_into_commit_iter())
138+
use git_odb::FindExt;
139+
db.find_commit_iter(oid, buf)
142140
})
143141
.collect::<Vec<_>>()
144142
.into_iter()

git-repository/src/ext/object_id.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ pub trait Sealed {}
66
/// An extension trait to add functionality to [`ObjectId`]s.
77
pub trait ObjectIdExt: Sealed {
88
/// Create an iterator over the ancestry of the commits reachable from this id, which must be a commit.
9-
fn ancestors<Find>(self, find: Find) -> Ancestors<Find, fn(&git_hash::oid) -> bool, ancestors::State>
9+
fn ancestors<Find, E>(self, find: Find) -> Ancestors<Find, fn(&git_hash::oid) -> bool, ancestors::State>
1010
where
11-
Find: for<'a> FnMut(&git_hash::oid, &'a mut Vec<u8>) -> Option<git_object::CommitRefIter<'a>>;
11+
Find: for<'a> FnMut(&git_hash::oid, &'a mut Vec<u8>) -> Result<git_object::CommitRefIter<'a>, E>,
12+
E: std::error::Error + Send + Sync + 'static;
1213

1314
/// Infuse this object id `repo` access.
1415
fn attach(self, repo: &crate::Repository) -> crate::Id<'_>;
@@ -17,9 +18,10 @@ pub trait ObjectIdExt: Sealed {
1718
impl Sealed for ObjectId {}
1819

1920
impl ObjectIdExt for ObjectId {
20-
fn ancestors<Find>(self, find: Find) -> Ancestors<Find, fn(&git_hash::oid) -> bool, ancestors::State>
21+
fn ancestors<Find, E>(self, find: Find) -> Ancestors<Find, fn(&git_hash::oid) -> bool, ancestors::State>
2122
where
22-
Find: for<'a> FnMut(&git_hash::oid, &'a mut Vec<u8>) -> Option<git_object::CommitRefIter<'a>>,
23+
Find: for<'a> FnMut(&git_hash::oid, &'a mut Vec<u8>) -> Result<git_object::CommitRefIter<'a>, E>,
24+
E: std::error::Error + Send + Sync + 'static,
2325
{
2426
Ancestors::new(Some(self), ancestors::State::default(), find)
2527
}

git-repository/src/id.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub struct Ancestors<'repo> {
9797

9898
///
9999
pub mod ancestors {
100-
use git_odb::Find;
100+
use git_odb::FindExt;
101101

102102
use crate::id::Ancestors;
103103
use crate::{ext::ObjectIdExt, Id};
@@ -138,14 +138,7 @@ pub mod ancestors {
138138
git_traverse::commit::Ancestors::new(
139139
tips,
140140
git_traverse::commit::ancestors::State::default(),
141-
move |oid, buf| {
142-
self.repo
143-
.objects
144-
.try_find(oid, buf)
145-
.ok()
146-
.flatten()
147-
.and_then(|obj| obj.try_into_commit_iter())
148-
},
141+
move |oid, buf| self.repo.objects.find_commit_iter(oid, buf),
149142
)
150143
.sorting(sorting)
151144
.parents(parents),

gitoxide-core/src/hours.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ where
6666
let commit_iter = interrupt::Iter::new(
6767
commit_id.ancestors(|oid, buf| {
6868
progress.inc();
69-
handle.objects.find(oid, buf).ok().map(|o| {
69+
handle.objects.find(oid, buf).map(|o| {
7070
commits.push(o.data.to_owned());
7171
objs::CommitRefIter::from_bytes(o.data)
7272
})

gitoxide-core/src/pack/create.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ where
143143
let iter = Box::new(
144144
traverse::commit::Ancestors::new(tips, traverse::commit::ancestors::State::default(), {
145145
let handle = handle.clone();
146-
move |oid, buf| handle.find_commit_iter(oid, buf).ok().map(|t| t.0)
146+
move |oid, buf| handle.find_commit_iter(oid, buf).map(|t| t.0)
147147
})
148148
.map(|res| res.map_err(Into::into))
149149
.inspect(move |_| progress.inc()),

0 commit comments

Comments
 (0)