@@ -18,6 +18,7 @@ use crate::string_array::StringArray;
18
18
use crate :: tagforeach:: { tag_foreach_cb, TagForeachCB , TagForeachData } ;
19
19
use crate :: util:: { self , path_to_repo_path, Binding } ;
20
20
use crate :: worktree:: { Worktree , WorktreeAddOptions } ;
21
+ use crate :: CherrypickOptions ;
21
22
use crate :: RevertOptions ;
22
23
use crate :: {
23
24
raw, AttrCheckFlags , Buf , Error , Object , Remote , RepositoryOpenFlags , RepositoryState , Revspec ,
@@ -29,7 +30,6 @@ use crate::{
29
30
use crate :: { ApplyLocation , ApplyOptions , Rebase , RebaseOptions } ;
30
31
use crate :: { Blame , BlameOptions , Reference , References , ResetType , Signature , Submodule } ;
31
32
use crate :: { Blob , BlobWriter , Branch , BranchType , Branches , Commit , Config , Index , Oid , Tree } ;
32
- use crate :: { CherrypickOptions , IndexEntry } ;
33
33
use crate :: { Describe , IntoCString , Reflog , RepositoryInitMode , RevparseMode } ;
34
34
use crate :: { DescribeOptions , Diff , DiffOptions , Odb , PackBuilder , TreeBuilder } ;
35
35
use crate :: { Note , Notes , ObjectType , Revwalk , Status , StatusOptions , Statuses , Tag } ;
@@ -1848,47 +1848,13 @@ impl Repository {
1848
1848
///
1849
1849
/// Note that this function does not reference a repository and any
1850
1850
/// configuration must be passed as `git_merge_file_options`.
1851
- ///
1852
- /// @param out The git_merge_file_result to be filled in
1853
- /// @param ancestor The contents of the ancestor file
1854
- /// @param ours The contents of the file in "our" side
1855
- /// @param theirs The contents of the file in "their" side
1856
- /// @param opts The merge file options or `NULL` for defaults
1857
- /// @return 0 on success or error code
1858
1851
pub fn merge_file (
1859
1852
& self ,
1860
- ancestor : Option < & IndexEntry > ,
1861
- ours : Option < & IndexEntry > ,
1862
- theirs : Option < & IndexEntry > ,
1853
+ ancestor : Option < & MergeFileInput < ' _ > > ,
1854
+ ours : Option < & MergeFileInput < ' _ > > ,
1855
+ theirs : Option < & MergeFileInput < ' _ > > ,
1863
1856
options : Option < & MergeFileOptions > ,
1864
1857
) -> Result < MergeFileResult , Error > {
1865
- let ancestor_input;
1866
- let ours_input;
1867
- let theirs_input;
1868
-
1869
- let ancestor_raw;
1870
- let ours_raw;
1871
- let theirs_raw;
1872
-
1873
- if let Some ( ancestor) = ancestor {
1874
- ancestor_input = MergeFileInput :: from ( & self , ancestor) ;
1875
- ancestor_raw = ancestor_input. raw ( ) ;
1876
- } else {
1877
- ancestor_raw = ptr:: null ( ) ;
1878
- }
1879
- if let Some ( ours) = ours {
1880
- ours_input = MergeFileInput :: from ( & self , ours) ;
1881
- ours_raw = ours_input. raw ( ) ;
1882
- } else {
1883
- ours_raw = ptr:: null ( ) ;
1884
- }
1885
- if let Some ( theirs) = theirs {
1886
- theirs_input = MergeFileInput :: from ( & self , theirs) ;
1887
- theirs_raw = theirs_input. raw ( ) ;
1888
- } else {
1889
- theirs_raw = ptr:: null ( ) ;
1890
- }
1891
-
1892
1858
let mut ret = raw:: git_merge_file_result {
1893
1859
automergeable : 0 ,
1894
1860
path : ptr:: null ( ) ,
@@ -1900,9 +1866,9 @@ impl Repository {
1900
1866
unsafe {
1901
1867
try_call ! ( raw:: git_merge_file(
1902
1868
& mut ret,
1903
- ancestor_raw ,
1904
- ours_raw ,
1905
- theirs_raw ,
1869
+ ancestor . map ( |a| a . raw ( ) ) . unwrap_or ( ptr :: null ( ) ) ,
1870
+ ours . map ( |a| a . raw ( ) ) . unwrap_or ( ptr :: null ( ) ) ,
1871
+ theirs . map ( |a| a . raw ( ) ) . unwrap_or ( ptr :: null ( ) ) ,
1906
1872
options. map( |o| o. raw( ) )
1907
1873
) ) ;
1908
1874
@@ -3104,7 +3070,7 @@ impl RepositoryInitOptions {
3104
3070
#[ cfg( test) ]
3105
3071
mod tests {
3106
3072
use crate :: build:: CheckoutBuilder ;
3107
- use crate :: { CherrypickOptions , FileMode } ;
3073
+ use crate :: { CherrypickOptions , FileMode , MergeFileInput } ;
3108
3074
use crate :: { ObjectType , Oid , Repository , ResetType } ;
3109
3075
use std:: ffi:: OsStr ;
3110
3076
use std:: fs;
@@ -3457,11 +3423,63 @@ mod tests {
3457
3423
for conflict in index_conflicts {
3458
3424
let conflict = conflict. unwrap ( ) ;
3459
3425
3426
+ let ancestor_input;
3427
+ let ours_input;
3428
+ let theirs_input;
3429
+
3430
+ let ancestor_blob;
3431
+ let ours_blob;
3432
+ let theirs_blob;
3433
+
3434
+ let ancestor_content;
3435
+ let ours_content;
3436
+ let theirs_content;
3437
+
3438
+ if let Some ( ancestor) = conflict. ancestor {
3439
+ ancestor_blob = repo
3440
+ . find_blob ( ancestor. id . clone ( ) )
3441
+ . expect ( "failed to find blob of index entry to make MergeFileInput" ) ;
3442
+ ancestor_content = ancestor_blob. content ( ) ;
3443
+ let mut input = MergeFileInput :: new ( ) ;
3444
+ input. path ( String :: from_utf8 ( ancestor. path ) . unwrap ( ) ) ;
3445
+ input. mode ( Some ( FileMode :: from ( ancestor. mode ) ) ) ;
3446
+ input. content ( Some ( & ancestor_content) ) ;
3447
+ ancestor_input = Some ( input) ;
3448
+ } else {
3449
+ ancestor_input = None ;
3450
+ }
3451
+ if let Some ( ours) = conflict. our {
3452
+ ours_blob = repo
3453
+ . find_blob ( ours. id . clone ( ) )
3454
+ . expect ( "failed to find blob of index entry to make MergeFileInput" ) ;
3455
+ ours_content = ours_blob. content ( ) ;
3456
+ let mut input = MergeFileInput :: new ( ) ;
3457
+ input. path ( String :: from_utf8 ( ours. path ) . unwrap ( ) ) ;
3458
+ input. mode ( Some ( FileMode :: from ( ours. mode ) ) ) ;
3459
+ input. content ( Some ( & ours_content) ) ;
3460
+ ours_input = Some ( input) ;
3461
+ } else {
3462
+ ours_input = None ;
3463
+ }
3464
+ if let Some ( theirs) = conflict. their {
3465
+ theirs_blob = repo
3466
+ . find_blob ( theirs. id . clone ( ) )
3467
+ . expect ( "failed to find blob of index entry to make MergeFileInput" ) ;
3468
+ theirs_content = theirs_blob. content ( ) ;
3469
+ let mut input = MergeFileInput :: new ( ) ;
3470
+ input. path ( String :: from_utf8 ( theirs. path ) . unwrap ( ) ) ;
3471
+ input. mode ( Some ( FileMode :: from ( theirs. mode ) ) ) ;
3472
+ input. content ( Some ( & theirs_content) ) ;
3473
+ theirs_input = Some ( input) ;
3474
+ } else {
3475
+ theirs_input = None ;
3476
+ }
3477
+
3460
3478
let merge_file_result = repo
3461
3479
. merge_file (
3462
- conflict . ancestor . as_ref ( ) ,
3463
- conflict . our . as_ref ( ) ,
3464
- conflict . their . as_ref ( ) ,
3480
+ ancestor_input . as_ref ( ) ,
3481
+ ours_input . as_ref ( ) ,
3482
+ theirs_input . as_ref ( ) ,
3465
3483
None ,
3466
3484
)
3467
3485
. unwrap ( ) ;
0 commit comments