@@ -402,53 +402,59 @@ impl std::fmt::Debug for MergeFileInput<'_> {
402
402
403
403
/// For git_merge_file_result
404
404
pub 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 ,
418
406
}
419
407
420
408
impl MergeFileResult {
421
409
/// Create MergeFileResult from C
422
410
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 ) ;
424
424
let str_slice: & str = c_str. to_str ( ) . unwrap ( ) ;
425
425
let path: String = str_slice. to_owned ( ) ;
426
+ Some ( path)
427
+ }
426
428
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
+ }
428
433
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)
435
439
}
436
440
}
437
441
438
442
impl std:: fmt:: Debug for MergeFileResult {
439
443
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> Result < ( ) , std:: fmt:: Error > {
440
444
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
+ }
443
449
}
444
- ds. field ( "mode" , & self . mode ) ;
450
+ ds. field ( "mode" , & self . mode ( ) ) ;
445
451
446
- match self . mode {
452
+ match self . mode ( ) {
447
453
FileMode :: Unreadable => { }
448
454
FileMode :: Tree => { }
449
455
FileMode :: Blob => unsafe {
450
456
let content = self
451
- . content
457
+ . content ( )
452
458
. as_ref ( )
453
459
. map ( |c| String :: from_utf8_unchecked ( c. clone ( ) ) )
454
460
. unwrap_or ( "unknown content" . to_string ( ) ) ;
0 commit comments