@@ -36,6 +36,11 @@ use crate::{DescribeOptions, Diff, DiffOptions, Odb, PackBuilder, TreeBuilder};
36
36
use crate :: { Note , Notes , ObjectType , Revwalk , Status , StatusOptions , Statuses , Tag , Transaction } ;
37
37
38
38
type MergeheadForeachCb < ' a > = dyn FnMut ( & Oid ) -> bool + ' a ;
39
+ type FetchheadForeachCb < ' a > = dyn FnMut ( & str , & [ u8 ] , & Oid , bool ) -> bool + ' a ;
40
+
41
+ struct FetchheadForeachCbData < ' a > {
42
+ callback : & ' a mut FetchheadForeachCb < ' a > ,
43
+ }
39
44
40
45
struct MergeheadForeachCbData < ' a > {
41
46
callback : & ' a mut MergeheadForeachCb < ' a > ,
@@ -58,6 +63,39 @@ extern "C" fn mergehead_foreach_cb(oid: *const raw::git_oid, payload: *mut c_voi
58
63
. unwrap_or ( 1 )
59
64
}
60
65
66
+ extern "C" fn fetchhead_foreach_cb (
67
+ ref_name : * const c_char ,
68
+ remote_url : * const c_char ,
69
+ oid : * const raw:: git_oid ,
70
+ is_merge : c_uint ,
71
+ payload : * mut c_void ,
72
+ ) -> c_int {
73
+ panic:: wrap ( || unsafe {
74
+ let data = & mut * ( payload as * mut FetchheadForeachCbData < ' _ > ) ;
75
+ let res = {
76
+ let callback = & mut data. callback ;
77
+
78
+ assert ! ( !ref_name. is_null( ) ) ;
79
+ assert ! ( !remote_url. is_null( ) ) ;
80
+ assert ! ( !oid. is_null( ) ) ;
81
+
82
+ let ref_name = str:: from_utf8 ( CStr :: from_ptr ( ref_name) . to_bytes ( ) ) . unwrap ( ) ;
83
+ let remote_url = CStr :: from_ptr ( remote_url) . to_bytes ( ) ;
84
+ let oid = Binding :: from_raw ( oid) ;
85
+ let is_merge = is_merge == 1 ;
86
+
87
+ callback ( & ref_name, remote_url, & oid, is_merge)
88
+ } ;
89
+
90
+ if res {
91
+ 0
92
+ } else {
93
+ 1
94
+ }
95
+ } )
96
+ . unwrap_or ( 1 )
97
+ }
98
+
61
99
/// An owned git repository, representing all state associated with the
62
100
/// underlying filesystem.
63
101
///
@@ -3017,7 +3055,7 @@ impl Repository {
3017
3055
}
3018
3056
3019
3057
/// If a merge is in progress, invoke 'callback' for each commit ID in the
3020
- /// * MERGE_HEAD file.
3058
+ /// MERGE_HEAD file.
3021
3059
pub fn mergehead_foreach < C > ( & mut self , mut callback : C ) -> Result < ( ) , Error >
3022
3060
where
3023
3061
C : FnMut ( & Oid ) -> bool ,
@@ -3035,6 +3073,32 @@ impl Repository {
3035
3073
Ok ( ( ) )
3036
3074
}
3037
3075
}
3076
+
3077
+ /// Invoke 'callback' for each entry in the given FETCH_HEAD file.
3078
+ ///
3079
+ /// `callback` will be called with with following arguments:
3080
+ ///
3081
+ /// - `&str`: the reference name
3082
+ /// - `&[u8]`: the remote url
3083
+ /// - `&Oid`: the reference target OID
3084
+ /// - `bool`: was the reference the result of a merge
3085
+ pub fn fetchhead_foreach < C > ( & self , mut callback : C ) -> Result < ( ) , Error >
3086
+ where
3087
+ C : FnMut ( & str , & [ u8 ] , & Oid , bool ) -> bool ,
3088
+ {
3089
+ unsafe {
3090
+ let mut data = FetchheadForeachCbData {
3091
+ callback : & mut callback,
3092
+ } ;
3093
+ let cb: raw:: git_repository_fetchhead_foreach_cb = Some ( fetchhead_foreach_cb) ;
3094
+ try_call ! ( raw:: git_repository_fetchhead_foreach(
3095
+ self . raw( ) ,
3096
+ cb,
3097
+ & mut data as * mut _ as * mut _
3098
+ ) ) ;
3099
+ Ok ( ( ) )
3100
+ }
3101
+ }
3038
3102
}
3039
3103
3040
3104
impl Binding for Repository {
0 commit comments