@@ -479,9 +479,7 @@ static int prepare_submodule_summary(struct rev_info *rev, const char *path,
479
479
return prepare_revision_walk (rev );
480
480
}
481
481
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 )
485
483
{
486
484
static const char format [] = " %m %s" ;
487
485
struct strbuf sb = STRBUF_INIT ;
@@ -492,18 +490,12 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
492
490
ctx .date_mode = rev -> date_mode ;
493
491
ctx .output_encoding = get_log_output_encoding ();
494
492
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 );
502
493
format_commit_message (commit , format , & sb , & ctx );
503
- if (reset )
504
- strbuf_addstr (& sb , reset );
505
494
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 );
507
499
}
508
500
strbuf_release (& sb );
509
501
}
@@ -530,11 +522,9 @@ void prepare_submodule_repo_env(struct argv_array *out)
530
522
* attempt to lookup both the left and right commits and put them into the
531
523
* left and right pointers.
532
524
*/
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 ,
535
526
struct object_id * one , struct object_id * two ,
536
- unsigned dirty_submodule , const char * meta ,
537
- const char * reset ,
527
+ unsigned dirty_submodule ,
538
528
struct commit * * left , struct commit * * right ,
539
529
struct commit_list * * merge_bases )
540
530
{
@@ -543,11 +533,10 @@ static void show_submodule_header(FILE *f, const char *path,
543
533
int fast_forward = 0 , fast_backward = 0 ;
544
534
545
535
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
+
548
538
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 );
551
540
552
541
if (is_null_oid (one ))
553
542
message = "(new submodule)" ;
@@ -589,31 +578,29 @@ static void show_submodule_header(FILE *f, const char *path,
589
578
}
590
579
591
580
output_header :
592
- strbuf_addf (& sb , "%s%sSubmodule %s " , line_prefix , meta , path );
581
+ strbuf_addf (& sb , "Submodule %s " , path );
593
582
strbuf_add_unique_abbrev (& sb , one -> hash , DEFAULT_ABBREV );
594
583
strbuf_addstr (& sb , (fast_backward || fast_forward ) ? ".." : "..." );
595
584
strbuf_add_unique_abbrev (& sb , two -> hash , DEFAULT_ABBREV );
596
585
if (message )
597
- strbuf_addf (& sb , " %s%s \n" , message , reset );
586
+ strbuf_addf (& sb , " %s\n" , message );
598
587
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 );
601
590
602
591
strbuf_release (& sb );
603
592
}
604
593
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 ,
607
595
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 )
610
597
{
611
598
struct rev_info rev ;
612
599
struct commit * left = NULL , * right = NULL ;
613
600
struct commit_list * merge_bases = NULL ;
614
601
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 );
617
604
618
605
/*
619
606
* 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,
625
612
626
613
/* Treat revision walker failure the same as missing commits */
627
614
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" );
629
616
goto out ;
630
617
}
631
618
632
- print_submodule_summary (& rev , f , line_prefix , del , add , reset );
619
+ print_submodule_summary (& rev , o );
633
620
634
621
out :
635
622
if (merge_bases )
@@ -638,21 +625,18 @@ void show_submodule_summary(FILE *f, const char *path,
638
625
clear_commit_marks (right , ~0 );
639
626
}
640
627
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 ,
643
629
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 )
647
631
{
648
632
const struct object_id * old = & empty_tree_oid , * new = & empty_tree_oid ;
649
633
struct commit * left = NULL , * right = NULL ;
650
634
struct commit_list * merge_bases = NULL ;
651
- struct strbuf submodule_dir = STRBUF_INIT ;
652
635
struct child_process cp = CHILD_PROCESS_INIT ;
636
+ struct strbuf sb = STRBUF_INIT ;
653
637
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 );
656
640
657
641
/* We need a valid left and right commit to display a difference */
658
642
if (!(left || is_null_oid (one )) ||
@@ -664,16 +648,16 @@ void show_submodule_inline_diff(FILE *f, const char *path,
664
648
if (right )
665
649
new = two ;
666
650
667
- fflush (f );
668
651
cp .git_cmd = 1 ;
669
652
cp .dir = path ;
670
- cp .out = dup ( fileno ( f )) ;
653
+ cp .out = -1 ;
671
654
cp .no_stdin = 1 ;
672
655
673
656
/* TODO: other options may need to be passed here. */
674
657
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" );
675
660
676
- argv_array_pushf (& cp .args , "--line-prefix=%s" , line_prefix );
677
661
if (DIFF_OPT_TST (o , REVERSE_DIFF )) {
678
662
argv_array_pushf (& cp .args , "--src-prefix=%s%s/" ,
679
663
o -> b_prefix , path );
@@ -696,11 +680,17 @@ void show_submodule_inline_diff(FILE *f, const char *path,
696
680
argv_array_push (& cp .args , oid_to_hex (new ));
697
681
698
682
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" );
701
691
702
692
done :
703
- strbuf_release (& submodule_dir );
693
+ strbuf_release (& sb );
704
694
if (merge_bases )
705
695
free_commit_list (merge_bases );
706
696
if (left )
0 commit comments