@@ -479,9 +479,7 @@ static int prepare_submodule_summary(struct rev_info *rev, const char *path,
479479 return prepare_revision_walk (rev );
480480}
481481
482- static void print_submodule_summary (struct rev_info * rev , FILE * f ,
483- const char * line_prefix ,
484- const char * del , const char * add , const char * reset )
482+ static void print_submodule_summary (struct rev_info * rev , struct diff_options * o )
485483{
486484 static const char format [] = " %m %s" ;
487485 struct strbuf sb = STRBUF_INIT ;
@@ -492,18 +490,12 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
492490 ctx .date_mode = rev -> date_mode ;
493491 ctx .output_encoding = get_log_output_encoding ();
494492 strbuf_setlen (& sb , 0 );
495- strbuf_addstr (& sb , line_prefix );
496- if (commit -> object .flags & SYMMETRIC_LEFT ) {
497- if (del )
498- strbuf_addstr (& sb , del );
499- }
500- else if (add )
501- strbuf_addstr (& sb , add );
502493 format_commit_message (commit , format , & sb , & ctx );
503- if (reset )
504- strbuf_addstr (& sb , reset );
505494 strbuf_addch (& sb , '\n' );
506- fprintf (f , "%s" , sb .buf );
495+ if (commit -> object .flags & SYMMETRIC_LEFT )
496+ diff_emit_submodule_del (o , sb .buf );
497+ else
498+ diff_emit_submodule_add (o , sb .buf );
507499 }
508500 strbuf_release (& sb );
509501}
@@ -530,11 +522,9 @@ void prepare_submodule_repo_env(struct argv_array *out)
530522 * attempt to lookup both the left and right commits and put them into the
531523 * left and right pointers.
532524 */
533- static void show_submodule_header (FILE * f , const char * path ,
534- const char * line_prefix ,
525+ static void show_submodule_header (struct diff_options * o , const char * path ,
535526 struct object_id * one , struct object_id * two ,
536- unsigned dirty_submodule , const char * meta ,
537- const char * reset ,
527+ unsigned dirty_submodule ,
538528 struct commit * * left , struct commit * * right ,
539529 struct commit_list * * merge_bases )
540530{
@@ -543,11 +533,10 @@ static void show_submodule_header(FILE *f, const char *path,
543533 int fast_forward = 0 , fast_backward = 0 ;
544534
545535 if (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED )
546- fprintf ( f , "%sSubmodule %s contains untracked content\n" ,
547- line_prefix , path );
536+ diff_emit_submodule_untracked ( o , path );
537+
548538 if (dirty_submodule & DIRTY_SUBMODULE_MODIFIED )
549- fprintf (f , "%sSubmodule %s contains modified content\n" ,
550- line_prefix , path );
539+ diff_emit_submodule_modified (o , path );
551540
552541 if (is_null_oid (one ))
553542 message = "(new submodule)" ;
@@ -589,31 +578,29 @@ static void show_submodule_header(FILE *f, const char *path,
589578 }
590579
591580output_header :
592- strbuf_addf (& sb , "%s%sSubmodule %s " , line_prefix , meta , path );
581+ strbuf_addf (& sb , "Submodule %s " , path );
593582 strbuf_add_unique_abbrev (& sb , one -> hash , DEFAULT_ABBREV );
594583 strbuf_addstr (& sb , (fast_backward || fast_forward ) ? ".." : "..." );
595584 strbuf_add_unique_abbrev (& sb , two -> hash , DEFAULT_ABBREV );
596585 if (message )
597- strbuf_addf (& sb , " %s%s \n" , message , reset );
586+ strbuf_addf (& sb , " %s\n" , message );
598587 else
599- strbuf_addf (& sb , "%s:%s \n" , fast_backward ? " (rewind)" : "" , reset );
600- fwrite ( sb . buf , sb .len , 1 , f );
588+ strbuf_addf (& sb , "%s:\n" , fast_backward ? " (rewind)" : "" );
589+ diff_emit_submodule_header ( o , sb .buf );
601590
602591 strbuf_release (& sb );
603592}
604593
605- void show_submodule_summary (FILE * f , const char * path ,
606- const char * line_prefix ,
594+ void show_submodule_summary (struct diff_options * o , const char * path ,
607595 struct object_id * one , struct object_id * two ,
608- unsigned dirty_submodule , const char * meta ,
609- const char * del , const char * add , const char * reset )
596+ unsigned dirty_submodule )
610597{
611598 struct rev_info rev ;
612599 struct commit * left = NULL , * right = NULL ;
613600 struct commit_list * merge_bases = NULL ;
614601
615- show_submodule_header (f , path , line_prefix , one , two , dirty_submodule ,
616- meta , reset , & left , & right , & merge_bases );
602+ show_submodule_header (o , path , one , two , dirty_submodule ,
603+ & left , & right , & merge_bases );
617604
618605 /*
619606 * If we don't have both a left and a right pointer, there is no
@@ -625,11 +612,11 @@ void show_submodule_summary(FILE *f, const char *path,
625612
626613 /* Treat revision walker failure the same as missing commits */
627614 if (prepare_submodule_summary (& rev , path , left , right , merge_bases )) {
628- fprintf ( f , "%s (revision walker failed)\n" , line_prefix );
615+ diff_emit_submodule_error ( o , "(revision walker failed)\n" );
629616 goto out ;
630617 }
631618
632- print_submodule_summary (& rev , f , line_prefix , del , add , reset );
619+ print_submodule_summary (& rev , o );
633620
634621out :
635622 if (merge_bases )
@@ -638,21 +625,18 @@ void show_submodule_summary(FILE *f, const char *path,
638625 clear_commit_marks (right , ~0 );
639626}
640627
641- void show_submodule_inline_diff (FILE * f , const char * path ,
642- const char * line_prefix ,
628+ void show_submodule_inline_diff (struct diff_options * o , const char * path ,
643629 struct object_id * one , struct object_id * two ,
644- unsigned dirty_submodule , const char * meta ,
645- const char * del , const char * add , const char * reset ,
646- const struct diff_options * o )
630+ unsigned dirty_submodule )
647631{
648632 const struct object_id * old = & empty_tree_oid , * new = & empty_tree_oid ;
649633 struct commit * left = NULL , * right = NULL ;
650634 struct commit_list * merge_bases = NULL ;
651- struct strbuf submodule_dir = STRBUF_INIT ;
652635 struct child_process cp = CHILD_PROCESS_INIT ;
636+ struct strbuf sb = STRBUF_INIT ;
653637
654- show_submodule_header (f , path , line_prefix , one , two , dirty_submodule ,
655- meta , reset , & left , & right , & merge_bases );
638+ show_submodule_header (o , path , one , two , dirty_submodule ,
639+ & left , & right , & merge_bases );
656640
657641 /* We need a valid left and right commit to display a difference */
658642 if (!(left || is_null_oid (one )) ||
@@ -664,16 +648,16 @@ void show_submodule_inline_diff(FILE *f, const char *path,
664648 if (right )
665649 new = two ;
666650
667- fflush (f );
668651 cp .git_cmd = 1 ;
669652 cp .dir = path ;
670- cp .out = dup ( fileno ( f )) ;
653+ cp .out = -1 ;
671654 cp .no_stdin = 1 ;
672655
673656 /* TODO: other options may need to be passed here. */
674657 argv_array_pushl (& cp .args , "diff" , "--submodule=diff" , NULL );
658+ argv_array_pushf (& cp .args , "--color=%s" , want_color (o -> use_color ) ?
659+ "always" : "never" );
675660
676- argv_array_pushf (& cp .args , "--line-prefix=%s" , line_prefix );
677661 if (DIFF_OPT_TST (o , REVERSE_DIFF )) {
678662 argv_array_pushf (& cp .args , "--src-prefix=%s%s/" ,
679663 o -> b_prefix , path );
@@ -696,11 +680,17 @@ void show_submodule_inline_diff(FILE *f, const char *path,
696680 argv_array_push (& cp .args , oid_to_hex (new ));
697681
698682 prepare_submodule_repo_env (& cp .env_array );
699- if (run_command (& cp ))
700- fprintf (f , "(diff failed)\n" );
683+ if (start_command (& cp ))
684+ diff_emit_submodule_error (o , "(diff failed)\n" );
685+
686+ while (strbuf_getwholeline_fd (& sb , cp .out , '\n' ) != EOF )
687+ diff_emit_submodule_pipethrough (o , sb .buf , sb .len );
688+
689+ if (finish_command (& cp ))
690+ diff_emit_submodule_error (o , "(diff failed)\n" );
701691
702692done :
703- strbuf_release (& submodule_dir );
693+ strbuf_release (& sb );
704694 if (merge_bases )
705695 free_commit_list (merge_bases );
706696 if (left )
0 commit comments