@@ -2600,6 +2600,7 @@ static void run_checkdiff(struct diff_filepair *p, struct diff_options *o)
26002600void diff_setup (struct diff_options * options )
26012601{
26022602 memset (options , 0 , sizeof (* options ));
2603+ memset (& diff_queued_diff , 0 , sizeof (diff_queued_diff ));
26032604
26042605 options -> file = stdout ;
26052606
@@ -3541,8 +3542,7 @@ int diff_flush_patch_id(struct diff_options *options, unsigned char *sha1)
35413542 diff_free_filepair (q -> queue [i ]);
35423543
35433544 free (q -> queue );
3544- q -> queue = NULL ;
3545- q -> nr = q -> alloc = 0 ;
3545+ DIFF_QUEUE_CLEAR (q );
35463546
35473547 return result ;
35483548}
@@ -3670,8 +3670,7 @@ void diff_flush(struct diff_options *options)
36703670 diff_free_filepair (q -> queue [i ]);
36713671free_queue :
36723672 free (q -> queue );
3673- q -> queue = NULL ;
3674- q -> nr = q -> alloc = 0 ;
3673+ DIFF_QUEUE_CLEAR (q );
36753674 if (options -> close_file )
36763675 fclose (options -> file );
36773676
@@ -3693,8 +3692,7 @@ static void diffcore_apply_filter(const char *filter)
36933692 int i ;
36943693 struct diff_queue_struct * q = & diff_queued_diff ;
36953694 struct diff_queue_struct outq ;
3696- outq .queue = NULL ;
3697- outq .nr = outq .alloc = 0 ;
3695+ DIFF_QUEUE_CLEAR (& outq );
36983696
36993697 if (!filter )
37003698 return ;
@@ -3762,8 +3760,7 @@ static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)
37623760 int i ;
37633761 struct diff_queue_struct * q = & diff_queued_diff ;
37643762 struct diff_queue_struct outq ;
3765- outq .queue = NULL ;
3766- outq .nr = outq .alloc = 0 ;
3763+ DIFF_QUEUE_CLEAR (& outq );
37673764
37683765 for (i = 0 ; i < q -> nr ; i ++ ) {
37693766 struct diff_filepair * p = q -> queue [i ];
@@ -3824,6 +3821,12 @@ void diffcore_fix_diff_index(struct diff_options *options)
38243821
38253822void diffcore_std (struct diff_options * options )
38263823{
3824+ /* We never run this function more than one time, because the
3825+ * rename/copy detection logic can only run once.
3826+ */
3827+ if (diff_queued_diff .run )
3828+ return ;
3829+
38273830 if (options -> skip_stat_unmatch )
38283831 diffcore_skip_stat_unmatch (options );
38293832 if (options -> break_opt != -1 )
@@ -3843,6 +3846,8 @@ void diffcore_std(struct diff_options *options)
38433846 DIFF_OPT_SET (options , HAS_CHANGES );
38443847 else
38453848 DIFF_OPT_CLR (options , HAS_CHANGES );
3849+
3850+ diff_queued_diff .run = 1 ;
38463851}
38473852
38483853int diff_result_code (struct diff_options * opt , int status )
0 commit comments