11use std:: { borrow:: BorrowMut , collections:: VecDeque } ;
22
3- use gix_hash:: { oid, ObjectId } ;
43use gix_object:: tree:: EntryRef ;
4+ use gix_object:: FindExt ;
55
66use crate :: {
77 tree,
@@ -12,24 +12,21 @@ use crate::{
1212#[ derive( Debug , thiserror:: Error ) ]
1313#[ allow( missing_docs) ]
1414pub enum Error {
15- #[ error( "The object {oid} referenced by the tree or the tree itself was not found in the database" ) ]
16- FindExisting {
17- oid : ObjectId ,
18- source : Box < dyn std:: error:: Error + Send + Sync + ' static > ,
19- } ,
15+ #[ error( transparent) ]
16+ Find ( #[ from] gix_object:: find:: existing_iter:: Error ) ,
2017 #[ error( "The delegate cancelled the operation" ) ]
2118 Cancelled ,
2219 #[ error( transparent) ]
2320 EntriesDecode ( #[ from] gix_object:: decode:: Error ) ,
2421}
2522
2623impl < ' a > tree:: Changes < ' a > {
27- /// Calculate the changes that would need to be applied to `self` to get `other`.
24+ /// Calculate the changes that would need to be applied to `self` to get `other` using `objects` to obtain objects as needed for traversal .
2825 ///
2926 /// * The `state` maybe owned or mutably borrowed to allow reuses allocated data structures through multiple runs.
3027 /// * `locate` is a function `f(object_id, &mut buffer) -> Option<TreeIter>` to return a `TreeIter` for the given object id backing
3128 /// its data in the given buffer. Returning `None` is unexpected as these trees are obtained during iteration, and in a typical
32- /// database errors are not expected either which is why the error case is omitted. To allow proper error reporting, [`Error::FindExisting `]
29+ /// database errors are not expected either which is why the error case is omitted. To allow proper error reporting, [`Error::Find `]
3330 /// should be converted into a more telling error.
3431 /// * `delegate` will receive the computed changes, see the [`Visit`][`tree::Visit`] trait for more information on what to expect.
3532 ///
@@ -47,16 +44,14 @@ impl<'a> tree::Changes<'a> {
4744 ///
4845 /// [git_cmp_c]: https://github.com/git/git/blob/311531c9de557d25ac087c1637818bd2aad6eb3a/tree-diff.c#L49:L65
4946 /// [git_cmp_rs]: https://github.com/Byron/gitoxide/blob/a4d5f99c8dc99bf814790928a3bf9649cd99486b/gix-object/src/mutable/tree.rs#L52-L55
50- pub fn needed_to_obtain < FindFn , R , StateMut , E > (
47+ pub fn needed_to_obtain < R , StateMut > (
5148 mut self ,
5249 other : gix_object:: TreeRefIter < ' _ > ,
5350 mut state : StateMut ,
54- mut find : FindFn ,
51+ objects : impl gix_object :: Find ,
5552 delegate : & mut R ,
5653 ) -> Result < ( ) , Error >
5754 where
58- FindFn : for < ' b > FnMut ( & oid , & ' b mut Vec < u8 > ) -> Result < gix_object:: TreeRefIter < ' b > , E > ,
59- E : std:: error:: Error + Send + Sync + ' static ,
6055 R : tree:: Visit ,
6156 StateMut : BorrowMut < tree:: State > ,
6257 {
@@ -77,28 +72,16 @@ impl<'a> tree::Changes<'a> {
7772 match state. trees . pop_front ( ) {
7873 Some ( ( None , Some ( rhs) ) ) => {
7974 delegate. pop_front_tracked_path_and_set_current ( ) ;
80- rhs_entries = peekable ( find ( & rhs, & mut state. buf2 ) . map_err ( |err| Error :: FindExisting {
81- oid : rhs,
82- source : err. into ( ) ,
83- } ) ?) ;
75+ rhs_entries = peekable ( objects. find_tree_iter ( & rhs, & mut state. buf2 ) ?) ;
8476 }
8577 Some ( ( Some ( lhs) , Some ( rhs) ) ) => {
8678 delegate. pop_front_tracked_path_and_set_current ( ) ;
87- lhs_entries = peekable ( find ( & lhs, & mut state. buf1 ) . map_err ( |err| Error :: FindExisting {
88- oid : lhs,
89- source : err. into ( ) ,
90- } ) ?) ;
91- rhs_entries = peekable ( find ( & rhs, & mut state. buf2 ) . map_err ( |err| Error :: FindExisting {
92- oid : rhs,
93- source : err. into ( ) ,
94- } ) ?) ;
79+ lhs_entries = peekable ( objects. find_tree_iter ( & lhs, & mut state. buf1 ) ?) ;
80+ rhs_entries = peekable ( objects. find_tree_iter ( & rhs, & mut state. buf2 ) ?) ;
9581 }
9682 Some ( ( Some ( lhs) , None ) ) => {
9783 delegate. pop_front_tracked_path_and_set_current ( ) ;
98- lhs_entries = peekable ( find ( & lhs, & mut state. buf1 ) . map_err ( |err| Error :: FindExisting {
99- oid : lhs,
100- source : err. into ( ) ,
101- } ) ?) ;
84+ lhs_entries = peekable ( objects. find_tree_iter ( & lhs, & mut state. buf1 ) ?) ;
10285 }
10386 Some ( ( None , None ) ) => unreachable ! ( "BUG: it makes no sense to fill the stack with empties" ) ,
10487 None => return Ok ( ( ) ) ,
0 commit comments