@@ -504,21 +504,17 @@ static int diff_print_patch_file_binary_noshow(
504504 git_buf old_path = GIT_BUF_INIT , new_path = GIT_BUF_INIT ;
505505 int error ;
506506
507- if ((error = diff_delta_format_path (
508- & old_path , old_pfx , delta -> old_file .path )) < 0 ||
509- (error = diff_delta_format_path (
510- & new_path , new_pfx , delta -> new_file . path )) < 0 )
507+ if ((error = diff_delta_format_path (& old_path , old_pfx , delta -> old_file . path )) < 0 ||
508+ ( error = diff_delta_format_path ( & new_path , new_pfx , delta -> new_file .path )) < 0 ||
509+ (error = diff_delta_format_with_paths ( pi -> buf , delta , "Binary files %s and %s differ\n" ,
510+ old_path . ptr , new_path . ptr )) < 0 )
511511 goto done ;
512512
513513 pi -> line .num_lines = 1 ;
514- error = diff_delta_format_with_paths (
515- pi -> buf , delta , "Binary files %s and %s differ\n" ,
516- old_path .ptr , new_path .ptr );
517514
518515done :
519516 git_buf_dispose (& old_path );
520517 git_buf_dispose (& new_path );
521-
522518 return error ;
523519}
524520
@@ -542,10 +538,9 @@ static int diff_print_patch_file_binary(
542538 pi -> line .num_lines ++ ;
543539
544540 if ((error = format_binary (pi , binary -> new_file .type , binary -> new_file .data ,
545- binary -> new_file .datalen , binary -> new_file .inflatedlen )) < 0 ||
546- (error = format_binary (pi , binary -> old_file .type , binary -> old_file .data ,
547- binary -> old_file .datalen , binary -> old_file .inflatedlen )) < 0 ) {
548-
541+ binary -> new_file .datalen , binary -> new_file .inflatedlen )) < 0 ||
542+ (error = format_binary (pi , binary -> old_file .type , binary -> old_file .data ,
543+ binary -> old_file .datalen , binary -> old_file .inflatedlen )) < 0 ) {
549544 if (error == GIT_EBUFS ) {
550545 git_error_clear ();
551546 git_buf_truncate (pi -> buf , pre_binary_size );
@@ -582,16 +577,15 @@ static int diff_print_patch_file(
582577 GIT_UNUSED (progress );
583578
584579 if (S_ISDIR (delta -> new_file .mode ) ||
585- delta -> status == GIT_DELTA_UNMODIFIED ||
586- delta -> status == GIT_DELTA_IGNORED ||
587- delta -> status == GIT_DELTA_UNREADABLE ||
588- (delta -> status == GIT_DELTA_UNTRACKED &&
580+ delta -> status == GIT_DELTA_UNMODIFIED ||
581+ delta -> status == GIT_DELTA_IGNORED ||
582+ delta -> status == GIT_DELTA_UNREADABLE ||
583+ (delta -> status == GIT_DELTA_UNTRACKED &&
589584 (pi -> flags & GIT_DIFF_SHOW_UNTRACKED_CONTENT ) == 0 ))
590585 return 0 ;
591586
592- if ((error = git_diff_delta__format_file_header (
593- pi -> buf , delta , oldpfx , newpfx ,
594- id_strlen , print_index )) < 0 )
587+ if ((error = git_diff_delta__format_file_header (pi -> buf , delta , oldpfx , newpfx ,
588+ id_strlen , print_index )) < 0 )
595589 return error ;
596590
597591 pi -> line .origin = GIT_DIFF_LINE_FILE_HDR ;
@@ -701,17 +695,16 @@ int git_diff_print(
701695 return -1 ;
702696 }
703697
704- if (!(error = diff_print_info_init_fromdiff (
705- & pi , & buf , diff , format , print_cb , payload ))) {
706- error = git_diff_foreach (
707- diff , print_file , print_binary , print_hunk , print_line , & pi );
698+ if ((error = diff_print_info_init_fromdiff (& pi , & buf , diff , format , print_cb , payload )) < 0 )
699+ goto out ;
708700
709- if (error ) /* make sure error message is set */
710- git_error_set_after_callback_function (error , "git_diff_print" );
701+ if ((error = git_diff_foreach (diff , print_file , print_binary , print_hunk , print_line , & pi )) != 0 ) {
702+ git_error_set_after_callback_function (error , "git_diff_print" );
703+ goto out ;
711704 }
712705
706+ out :
713707 git_buf_dispose (& buf );
714-
715708 return error ;
716709}
717710
@@ -730,8 +723,8 @@ int git_diff_print_callback__to_buf(
730723 }
731724
732725 if (line -> origin == GIT_DIFF_LINE_ADDITION ||
733- line -> origin == GIT_DIFF_LINE_DELETION ||
734- line -> origin == GIT_DIFF_LINE_CONTEXT )
726+ line -> origin == GIT_DIFF_LINE_DELETION ||
727+ line -> origin == GIT_DIFF_LINE_CONTEXT )
735728 git_buf_putc (output , line -> origin );
736729
737730 return git_buf_put (output , line -> content , line -> content_len );
@@ -773,8 +766,7 @@ int git_diff_to_buf(git_buf *out, git_diff *diff, git_diff_format_t format)
773766{
774767 assert (out && diff );
775768 git_buf_sanitize (out );
776- return git_diff_print (
777- diff , format , git_diff_print_callback__to_buf , out );
769+ return git_diff_print (diff , format , git_diff_print_callback__to_buf , out );
778770}
779771
780772/* print a git_patch to an output callback */
@@ -783,28 +775,24 @@ int git_patch_print(
783775 git_diff_line_cb print_cb ,
784776 void * payload )
785777{
786- int error ;
787778 git_buf temp = GIT_BUF_INIT ;
788779 diff_print_info pi ;
780+ int error ;
789781
790782 assert (patch && print_cb );
791783
792- if (!(error = diff_print_info_init_frompatch (
793- & pi , & temp , patch ,
794- GIT_DIFF_FORMAT_PATCH , print_cb , payload )))
795- {
796- error = git_patch__invoke_callbacks (
797- patch ,
798- diff_print_patch_file , diff_print_patch_binary ,
799- diff_print_patch_hunk , diff_print_patch_line ,
800- & pi );
801-
802- if (error ) /* make sure error message is set */
803- git_error_set_after_callback_function (error , "git_patch_print" );
784+ if ((error = diff_print_info_init_frompatch (& pi , & temp , patch ,
785+ GIT_DIFF_FORMAT_PATCH , print_cb , payload )) < 0 )
786+ goto out ;
787+
788+ if ((error = git_patch__invoke_callbacks (patch , diff_print_patch_file , diff_print_patch_binary ,
789+ diff_print_patch_hunk , diff_print_patch_line , & pi )) < 0 ) {
790+ git_error_set_after_callback_function (error , "git_patch_print" );
791+ goto out ;
804792 }
805793
794+ out :
806795 git_buf_dispose (& temp );
807-
808796 return error ;
809797}
810798
0 commit comments