@@ -538,7 +538,7 @@ static int grep_submodule_launch(struct grep_opt *opt,
538538 int status , i ;
539539 const char * end_of_base ;
540540 const char * name ;
541- struct work_item * w = opt -> output_priv ;
541+ struct strbuf child_output = STRBUF_INIT ;
542542
543543 end_of_base = strchr (gs -> name , ':' );
544544 if (gs -> identifier && end_of_base )
@@ -593,14 +593,16 @@ static int grep_submodule_launch(struct grep_opt *opt,
593593 * child process. A '0' indicates a hit, a '1' indicates no hit and
594594 * anything else is an error.
595595 */
596- status = capture_command (& cp , & w -> out , 0 );
596+ status = capture_command (& cp , & child_output , 0 );
597597 if (status && (status != 1 )) {
598598 /* flush the buffer */
599- write_or_die (1 , w -> out .buf , w -> out .len );
599+ write_or_die (1 , child_output .buf , child_output .len );
600600 die ("process for submodule '%s' failed with exit code: %d" ,
601601 gs -> name , status );
602602 }
603603
604+ opt -> output (opt , child_output .buf , child_output .len );
605+ strbuf_release (& child_output );
604606 /* invert the return code to make a hit equal to 1 */
605607 return !status ;
606608}
@@ -641,19 +643,14 @@ static int grep_submodule(struct grep_opt *opt, const unsigned char *sha1,
641643 } else
642644#endif
643645 {
644- struct work_item w ;
646+ struct grep_source gs ;
645647 int hit ;
646648
647- grep_source_init (& w . source , GREP_SOURCE_SUBMODULE ,
649+ grep_source_init (& gs , GREP_SOURCE_SUBMODULE ,
648650 filename , path , sha1 );
649- strbuf_init (& w .out , 0 );
650- opt -> output_priv = & w ;
651- hit = grep_submodule_launch (opt , & w .source );
651+ hit = grep_submodule_launch (opt , & gs );
652652
653- write_or_die (1 , w .out .buf , w .out .len );
654-
655- grep_source_clear (& w .source );
656- strbuf_release (& w .out );
653+ grep_source_clear (& gs );
657654 return hit ;
658655 }
659656}
0 commit comments