@@ -464,12 +464,35 @@ static void patch_diff(const char *a, const char *b,
464
464
diff_flush (diffopt );
465
465
}
466
466
467
+ static struct strbuf * output_prefix_cb (struct diff_options * opt , void * data )
468
+ {
469
+ return data ;
470
+ }
471
+
467
472
static void output (struct string_list * a , struct string_list * b ,
468
- struct diff_options * diffopt )
473
+ struct range_diff_options * range_diff_opts )
469
474
{
470
475
struct strbuf buf = STRBUF_INIT , dashes = STRBUF_INIT ;
471
476
int patch_no_width = decimal_width (1 + (a -> nr > b -> nr ? a -> nr : b -> nr ));
472
477
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 );
473
496
474
497
/*
475
498
* 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,
490
513
491
514
/* Show unmatched LHS commit whose predecessors were shown. */
492
515
if (i < a -> nr && a_util -> matching < 0 ) {
493
- output_pair_header (diffopt , patch_no_width ,
516
+ output_pair_header (& opts , patch_no_width ,
494
517
& buf , & dashes , a_util , NULL );
495
518
i ++ ;
496
519
continue ;
497
520
}
498
521
499
522
/* Show unmatched RHS commits. */
500
523
while (j < b -> nr && b_util -> matching < 0 ) {
501
- output_pair_header (diffopt , patch_no_width ,
524
+ output_pair_header (& opts , patch_no_width ,
502
525
& buf , & dashes , NULL , b_util );
503
526
b_util = ++ j < b -> nr ? b -> items [j ].util : NULL ;
504
527
}
505
528
506
529
/* Show matching LHS/RHS pair. */
507
530
if (j < b -> nr ) {
508
531
a_util = a -> items [b_util -> matching ].util ;
509
- output_pair_header (diffopt , patch_no_width ,
532
+ output_pair_header (& opts , patch_no_width ,
510
533
& buf , & dashes , a_util , b_util );
511
- if (!(diffopt -> output_format & DIFF_FORMAT_NO_OUTPUT ))
534
+ if (!(opts . output_format & DIFF_FORMAT_NO_OUTPUT ))
512
535
patch_diff (a -> items [b_util -> matching ].string ,
513
- b -> items [j ].string , diffopt );
536
+ b -> items [j ].string , & opts );
514
537
a_util -> shown = 1 ;
515
538
j ++ ;
516
539
}
517
540
}
518
541
strbuf_release (& buf );
519
542
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 );
525
544
}
526
545
527
546
int show_range_diff (const char * range1 , const char * range2 ,
@@ -538,31 +557,10 @@ int show_range_diff(const char *range1, const char *range2,
538
557
res = error (_ ("could not parse log for '%s'" ), range2 );
539
558
540
559
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
-
560
560
find_exact_matches (& branch1 , & branch2 );
561
561
get_correspondences (& branch1 , & branch2 ,
562
562
range_diff_opts -> creation_factor );
563
- output (& branch1 , & branch2 , & opts );
564
-
565
- strbuf_release (& indent );
563
+ output (& branch1 , & branch2 , range_diff_opts );
566
564
}
567
565
568
566
string_list_clear (& branch1 , 1 );
0 commit comments