1
1
use std:: { borrow:: BorrowMut , collections:: VecDeque } ;
2
2
3
- use gix_hash:: { oid, ObjectId } ;
4
3
use gix_object:: tree:: EntryRef ;
4
+ use gix_object:: FindExt ;
5
5
6
6
use crate :: {
7
7
tree,
@@ -12,24 +12,21 @@ use crate::{
12
12
#[ derive( Debug , thiserror:: Error ) ]
13
13
#[ allow( missing_docs) ]
14
14
pub 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 ) ,
20
17
#[ error( "The delegate cancelled the operation" ) ]
21
18
Cancelled ,
22
19
#[ error( transparent) ]
23
20
EntriesDecode ( #[ from] gix_object:: decode:: Error ) ,
24
21
}
25
22
26
23
impl < ' 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 .
28
25
///
29
26
/// * The `state` maybe owned or mutably borrowed to allow reuses allocated data structures through multiple runs.
30
27
/// * `locate` is a function `f(object_id, &mut buffer) -> Option<TreeIter>` to return a `TreeIter` for the given object id backing
31
28
/// 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 `]
33
30
/// should be converted into a more telling error.
34
31
/// * `delegate` will receive the computed changes, see the [`Visit`][`tree::Visit`] trait for more information on what to expect.
35
32
///
@@ -47,16 +44,14 @@ impl<'a> tree::Changes<'a> {
47
44
///
48
45
/// [git_cmp_c]: https://github.com/git/git/blob/311531c9de557d25ac087c1637818bd2aad6eb3a/tree-diff.c#L49:L65
49
46
/// [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 > (
51
48
mut self ,
52
49
other : gix_object:: TreeRefIter < ' _ > ,
53
50
mut state : StateMut ,
54
- mut find : FindFn ,
51
+ objects : impl gix_object :: Find ,
55
52
delegate : & mut R ,
56
53
) -> Result < ( ) , Error >
57
54
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 ,
60
55
R : tree:: Visit ,
61
56
StateMut : BorrowMut < tree:: State > ,
62
57
{
@@ -77,28 +72,16 @@ impl<'a> tree::Changes<'a> {
77
72
match state. trees . pop_front ( ) {
78
73
Some ( ( None , Some ( rhs) ) ) => {
79
74
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 ) ?) ;
84
76
}
85
77
Some ( ( Some ( lhs) , Some ( rhs) ) ) => {
86
78
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 ) ?) ;
95
81
}
96
82
Some ( ( Some ( lhs) , None ) ) => {
97
83
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 ) ?) ;
102
85
}
103
86
Some ( ( None , None ) ) => unreachable ! ( "BUG: it makes no sense to fill the stack with empties" ) ,
104
87
None => return Ok ( ( ) ) ,
0 commit comments