Skip to content

Commit 1da6175

Browse files
byanggitster
authored andcommitted
Make diffcore_std only can run once before a diff_flush
When file renames/copies detection is turned on, the second diffcore_std will degrade a 'C' pair to a 'R' pair. And this may happen when we run 'git log --follow' with hard copies finding. That is, the try_to_follow_renames() will run diffcore_std to find the copies, and then 'git log' will issue another diffcore_std, which will reduce 'src->rename_used' and recognize this copy as a rename. This is not what we want. So, I think we really don't need to run diffcore_std more than one time. Signed-off-by: Bo Yang <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9ca5df9 commit 1da6175

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

diff.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3737,6 +3737,12 @@ void diffcore_fix_diff_index(struct diff_options *options)
37373737

37383738
void diffcore_std(struct diff_options *options)
37393739
{
3740+
/* We never run this function more than one time, because the
3741+
* rename/copy detection logic can only run once.
3742+
*/
3743+
if (diff_queued_diff.run)
3744+
return;
3745+
37403746
if (options->skip_stat_unmatch)
37413747
diffcore_skip_stat_unmatch(options);
37423748
if (options->break_opt != -1)
@@ -3756,6 +3762,8 @@ void diffcore_std(struct diff_options *options)
37563762
DIFF_OPT_SET(options, HAS_CHANGES);
37573763
else
37583764
DIFF_OPT_CLR(options, HAS_CHANGES);
3765+
3766+
diff_queued_diff.run = 1;
37593767
}
37603768

37613769
int diff_result_code(struct diff_options *opt, int status)

diffcore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ struct diff_queue_struct {
9191
struct diff_filepair **queue;
9292
int alloc;
9393
int nr;
94+
int run;
9495
};
9596
#define DIFF_QUEUE_CLEAR(q) \
9697
do { \
9798
(q)->queue = NULL; \
9899
(q)->nr = (q)->alloc = 0; \
100+
(q)->run = 0; \
99101
} while(0);
100102

101103
extern struct diff_queue_struct diff_queued_diff;

0 commit comments

Comments
 (0)