@@ -11,7 +11,6 @@ use crate::build::{CheckoutBuilder, RepoBuilder};
11
11
use crate :: diff:: {
12
12
binary_cb_c, file_cb_c, hunk_cb_c, line_cb_c, BinaryCb , DiffCallbacks , FileCb , HunkCb , LineCb ,
13
13
} ;
14
- use crate :: mailmap:: Mailmap ;
15
14
use crate :: oid_array:: OidArray ;
16
15
use crate :: stash:: { stash_cb, StashApplyOptions , StashCbData } ;
17
16
use crate :: string_array:: StringArray ;
@@ -20,6 +19,7 @@ use crate::util::{self, path_to_repo_path, Binding};
20
19
use crate :: worktree:: { Worktree , WorktreeAddOptions } ;
21
20
use crate :: CherrypickOptions ;
22
21
use crate :: RevertOptions ;
22
+ use crate :: { mailmap:: Mailmap , panic} ;
23
23
use crate :: {
24
24
raw, AttrCheckFlags , Buf , Error , Object , Remote , RepositoryOpenFlags , RepositoryState , Revspec ,
25
25
StashFlags ,
@@ -35,6 +35,29 @@ use crate::{Describe, IntoCString, Reflog, RepositoryInitMode, RevparseMode};
35
35
use crate :: { DescribeOptions , Diff , DiffOptions , Odb , PackBuilder , TreeBuilder } ;
36
36
use crate :: { Note , Notes , ObjectType , Revwalk , Status , StatusOptions , Statuses , Tag , Transaction } ;
37
37
38
+ type MergeheadForeachCb < ' a > = dyn FnMut ( & Oid ) -> bool + ' a ;
39
+
40
+ struct MergeheadForeachCbData < ' a > {
41
+ callback : & ' a mut MergeheadForeachCb < ' a > ,
42
+ }
43
+
44
+ extern "C" fn mergehead_foreach_cb ( oid : * const raw:: git_oid , payload : * mut c_void ) -> c_int {
45
+ panic:: wrap ( || unsafe {
46
+ let data = & mut * ( payload as * mut MergeheadForeachCbData < ' _ > ) ;
47
+ let res = {
48
+ let callback = & mut data. callback ;
49
+ callback ( & Binding :: from_raw ( oid) )
50
+ } ;
51
+
52
+ if res {
53
+ 0
54
+ } else {
55
+ 1
56
+ }
57
+ } )
58
+ . unwrap_or ( 1 )
59
+ }
60
+
38
61
/// An owned git repository, representing all state associated with the
39
62
/// underlying filesystem.
40
63
///
@@ -2972,6 +2995,26 @@ impl Repository {
2972
2995
Ok ( Binding :: from_raw ( ret) )
2973
2996
}
2974
2997
}
2998
+
2999
+ /// If a merge is in progress, invoke 'callback' for each commit ID in the
3000
+ /// * MERGE_HEAD file.
3001
+ pub fn mergehead_foreach < C > ( & mut self , mut callback : C ) -> Result < ( ) , Error >
3002
+ where
3003
+ C : FnMut ( & Oid ) -> bool ,
3004
+ {
3005
+ unsafe {
3006
+ let mut data = MergeheadForeachCbData {
3007
+ callback : & mut callback,
3008
+ } ;
3009
+ let cb: raw:: git_repository_mergehead_foreach_cb = Some ( mergehead_foreach_cb) ;
3010
+ try_call ! ( raw:: git_repository_mergehead_foreach(
3011
+ self . raw( ) ,
3012
+ cb,
3013
+ & mut data as * mut _ as * mut _
3014
+ ) ) ;
3015
+ Ok ( ( ) )
3016
+ }
3017
+ }
2975
3018
}
2976
3019
2977
3020
impl Binding for Repository {
0 commit comments