@@ -402,53 +402,59 @@ impl std::fmt::Debug for MergeFileInput<'_> {
402402
403403/// For git_merge_file_result
404404pub struct MergeFileResult {
405- /// True if the output was automerged, false if the output contains
406- /// conflict markers.
407- pub automergeable : bool ,
408-
409- /// The path that the resultant merge file should use, or NULL if a
410- /// filename conflict would occur.
411- pub path : Option < String > ,
412-
413- /// The mode that the resultant merge file should use.
414- pub mode : FileMode ,
415-
416- /// The contents of the merge.
417- pub content : Option < Vec < u8 > > ,
405+ raw : raw:: git_merge_file_result ,
418406}
419407
420408impl MergeFileResult {
421409 /// Create MergeFileResult from C
422410 pub unsafe fn from_raw ( raw : raw:: git_merge_file_result ) -> MergeFileResult {
423- let c_str: & CStr = CStr :: from_ptr ( raw. path ) ;
411+ MergeFileResult { raw }
412+ }
413+
414+ /// True if the output was automerged, false if the output contains
415+ /// conflict markers.
416+ pub fn automergeable ( & self ) -> bool {
417+ self . raw . automergeable > 0
418+ }
419+
420+ /// The path that the resultant merge file should use, or NULL if a
421+ /// filename conflict would occur.
422+ pub unsafe fn path ( & self ) -> Option < String > {
423+ let c_str: & CStr = CStr :: from_ptr ( self . raw . path ) ;
424424 let str_slice: & str = c_str. to_str ( ) . unwrap ( ) ;
425425 let path: String = str_slice. to_owned ( ) ;
426+ Some ( path)
427+ }
426428
427- let content = slice:: from_raw_parts ( raw. ptr as * const u8 , raw. len as usize ) . to_vec ( ) ;
429+ /// The mode that the resultant merge file should use.
430+ pub fn mode ( & self ) -> FileMode {
431+ FileMode :: from ( self . raw . mode . try_into ( ) . unwrap ( ) )
432+ }
428433
429- MergeFileResult {
430- automergeable : raw. automergeable > 0 ,
431- path : Some ( path) ,
432- mode : FileMode :: from ( raw. mode . try_into ( ) . unwrap ( ) ) ,
433- content : Some ( content) ,
434- }
434+ /// The contents of the merge.
435+ pub unsafe fn content ( & self ) -> Option < Vec < u8 > > {
436+ let content =
437+ slice:: from_raw_parts ( self . raw . ptr as * const u8 , self . raw . len as usize ) . to_vec ( ) ;
438+ Some ( content)
435439 }
436440}
437441
438442impl std:: fmt:: Debug for MergeFileResult {
439443 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> Result < ( ) , std:: fmt:: Error > {
440444 let mut ds = f. debug_struct ( "MergeFileResult" ) ;
441- if let Some ( path) = & self . path {
442- ds. field ( "path" , path) ;
445+ unsafe {
446+ if let Some ( path) = & self . path ( ) {
447+ ds. field ( "path" , path) ;
448+ }
443449 }
444- ds. field ( "mode" , & self . mode ) ;
450+ ds. field ( "mode" , & self . mode ( ) ) ;
445451
446- match self . mode {
452+ match self . mode ( ) {
447453 FileMode :: Unreadable => { }
448454 FileMode :: Tree => { }
449455 FileMode :: Blob => unsafe {
450456 let content = self
451- . content
457+ . content ( )
452458 . as_ref ( )
453459 . map ( |c| String :: from_utf8_unchecked ( c. clone ( ) ) )
454460 . unwrap_or ( "unknown content" . to_string ( ) ) ;
0 commit comments