@@ -269,7 +269,8 @@ static int diff_print_modes(
269269}
270270
271271static int diff_print_oid_range (
272- git_buf * out , const git_diff_delta * delta , int id_strlen )
272+ git_buf * out , const git_diff_delta * delta , int id_strlen ,
273+ bool print_index )
273274{
274275 char start_oid [GIT_OID_HEXSZ + 1 ], end_oid [GIT_OID_HEXSZ + 1 ];
275276
@@ -293,8 +294,9 @@ static int diff_print_oid_range(
293294 git_oid_tostr (end_oid , id_strlen + 1 , & delta -> new_file .id );
294295
295296 if (delta -> old_file .mode == delta -> new_file .mode ) {
296- git_buf_printf (out , "index %s..%s %o\n" ,
297- start_oid , end_oid , delta -> old_file .mode );
297+ if (print_index )
298+ git_buf_printf (out , "index %s..%s %o\n" ,
299+ start_oid , end_oid , delta -> old_file .mode );
298300 } else {
299301 if (delta -> old_file .mode == 0 )
300302 git_buf_printf (out , "new file mode %o\n" , delta -> new_file .mode );
@@ -303,7 +305,8 @@ static int diff_print_oid_range(
303305 else
304306 diff_print_modes (out , delta );
305307
306- git_buf_printf (out , "index %s..%s\n" , start_oid , end_oid );
308+ if (print_index )
309+ git_buf_printf (out , "index %s..%s\n" , start_oid , end_oid );
307310 }
308311
309312 return git_buf_oom (out ) ? -1 : 0 ;
@@ -400,7 +403,8 @@ int git_diff_delta__format_file_header(
400403 const git_diff_delta * delta ,
401404 const char * oldpfx ,
402405 const char * newpfx ,
403- int id_strlen )
406+ int id_strlen ,
407+ bool print_index )
404408{
405409 git_buf old_path = GIT_BUF_INIT , new_path = GIT_BUF_INIT ;
406410 bool unchanged = delta_is_unchanged (delta );
@@ -431,7 +435,8 @@ int git_diff_delta__format_file_header(
431435 }
432436
433437 if (!unchanged ) {
434- if ((error = diff_print_oid_range (out , delta , id_strlen )) < 0 )
438+ if ((error = diff_print_oid_range (out , delta ,
439+ id_strlen , print_index )) < 0 )
435440 goto done ;
436441
437442 if ((delta -> flags & GIT_DIFF_FLAG_BINARY ) == 0 )
@@ -566,6 +571,7 @@ static int diff_print_patch_file(
566571 (pi -> flags & GIT_DIFF_FORCE_BINARY );
567572 bool show_binary = !!(pi -> flags & GIT_DIFF_SHOW_BINARY );
568573 int id_strlen = pi -> id_strlen ;
574+ bool print_index = (pi -> format != GIT_DIFF_FORMAT_PATCH_ID );
569575
570576 if (binary && show_binary )
571577 id_strlen = delta -> old_file .id_abbrev ? delta -> old_file .id_abbrev :
@@ -582,7 +588,8 @@ static int diff_print_patch_file(
582588 return 0 ;
583589
584590 if ((error = git_diff_delta__format_file_header (
585- pi -> buf , delta , oldpfx , newpfx , id_strlen )) < 0 )
591+ pi -> buf , delta , oldpfx , newpfx ,
592+ id_strlen , print_index )) < 0 )
586593 return error ;
587594
588595 pi -> line .origin = GIT_DIFF_LINE_FILE_HDR ;
@@ -670,6 +677,11 @@ int git_diff_print(
670677 print_hunk = diff_print_patch_hunk ;
671678 print_line = diff_print_patch_line ;
672679 break ;
680+ case GIT_DIFF_FORMAT_PATCH_ID :
681+ print_file = diff_print_patch_file ;
682+ print_binary = diff_print_patch_binary ;
683+ print_line = diff_print_patch_line ;
684+ break ;
673685 case GIT_DIFF_FORMAT_PATCH_HEADER :
674686 print_file = diff_print_patch_file ;
675687 break ;
0 commit comments