@@ -464,12 +464,35 @@ static void patch_diff(const char *a, const char *b,
464464 diff_flush (diffopt );
465465}
466466
467+ static struct strbuf * output_prefix_cb (struct diff_options * opt , void * data )
468+ {
469+ return data ;
470+ }
471+
467472static void output (struct string_list * a , struct string_list * b ,
468- struct diff_options * diffopt )
473+ struct range_diff_options * range_diff_opts )
469474{
470475 struct strbuf buf = STRBUF_INIT , dashes = STRBUF_INIT ;
471476 int patch_no_width = decimal_width (1 + (a -> nr > b -> nr ? a -> nr : b -> nr ));
472477 int i = 0 , j = 0 ;
478+ struct diff_options opts ;
479+ struct strbuf indent = STRBUF_INIT ;
480+
481+ if (range_diff_opts -> diffopt )
482+ memcpy (& opts , range_diff_opts -> diffopt , sizeof (opts ));
483+ else
484+ diff_setup (& opts );
485+
486+ if (!opts .output_format )
487+ opts .output_format = DIFF_FORMAT_PATCH ;
488+ opts .flags .suppress_diff_headers = 1 ;
489+ opts .flags .dual_color_diffed_diffs =
490+ range_diff_opts -> dual_color ;
491+ opts .flags .suppress_hunk_header_line_count = 1 ;
492+ opts .output_prefix = output_prefix_cb ;
493+ strbuf_addstr (& indent , " " );
494+ opts .output_prefix_data = & indent ;
495+ diff_setup_done (& opts );
473496
474497 /*
475498 * We assume the user is really more interested in the second argument
@@ -490,38 +513,34 @@ static void output(struct string_list *a, struct string_list *b,
490513
491514 /* Show unmatched LHS commit whose predecessors were shown. */
492515 if (i < a -> nr && a_util -> matching < 0 ) {
493- output_pair_header (diffopt , patch_no_width ,
516+ output_pair_header (& opts , patch_no_width ,
494517 & buf , & dashes , a_util , NULL );
495518 i ++ ;
496519 continue ;
497520 }
498521
499522 /* Show unmatched RHS commits. */
500523 while (j < b -> nr && b_util -> matching < 0 ) {
501- output_pair_header (diffopt , patch_no_width ,
524+ output_pair_header (& opts , patch_no_width ,
502525 & buf , & dashes , NULL , b_util );
503526 b_util = ++ j < b -> nr ? b -> items [j ].util : NULL ;
504527 }
505528
506529 /* Show matching LHS/RHS pair. */
507530 if (j < b -> nr ) {
508531 a_util = a -> items [b_util -> matching ].util ;
509- output_pair_header (diffopt , patch_no_width ,
532+ output_pair_header (& opts , patch_no_width ,
510533 & buf , & dashes , a_util , b_util );
511- if (!(diffopt -> output_format & DIFF_FORMAT_NO_OUTPUT ))
534+ if (!(opts . output_format & DIFF_FORMAT_NO_OUTPUT ))
512535 patch_diff (a -> items [b_util -> matching ].string ,
513- b -> items [j ].string , diffopt );
536+ b -> items [j ].string , & opts );
514537 a_util -> shown = 1 ;
515538 j ++ ;
516539 }
517540 }
518541 strbuf_release (& buf );
519542 strbuf_release (& dashes );
520- }
521-
522- static struct strbuf * output_prefix_cb (struct diff_options * opt , void * data )
523- {
524- return data ;
543+ strbuf_release (& indent );
525544}
526545
527546int show_range_diff (const char * range1 , const char * range2 ,
@@ -538,31 +557,10 @@ int show_range_diff(const char *range1, const char *range2,
538557 res = error (_ ("could not parse log for '%s'" ), range2 );
539558
540559 if (!res ) {
541- struct diff_options opts ;
542- struct strbuf indent = STRBUF_INIT ;
543-
544- if (range_diff_opts -> diffopt )
545- memcpy (& opts , range_diff_opts -> diffopt , sizeof (opts ));
546- else
547- diff_setup (& opts );
548-
549- if (!opts .output_format )
550- opts .output_format = DIFF_FORMAT_PATCH ;
551- opts .flags .suppress_diff_headers = 1 ;
552- opts .flags .dual_color_diffed_diffs =
553- range_diff_opts -> dual_color ;
554- opts .flags .suppress_hunk_header_line_count = 1 ;
555- opts .output_prefix = output_prefix_cb ;
556- strbuf_addstr (& indent , " " );
557- opts .output_prefix_data = & indent ;
558- diff_setup_done (& opts );
559-
560560 find_exact_matches (& branch1 , & branch2 );
561561 get_correspondences (& branch1 , & branch2 ,
562562 range_diff_opts -> creation_factor );
563- output (& branch1 , & branch2 , & opts );
564-
565- strbuf_release (& indent );
563+ output (& branch1 , & branch2 , range_diff_opts );
566564 }
567565
568566 string_list_clear (& branch1 , 1 );
0 commit comments