@@ -170,7 +170,7 @@ static int estimate_similarity(struct diff_filespec *src,
170
170
* and the final score computation below would not have a
171
171
* divide-by-zero issue.
172
172
*/
173
- if (base_size * (MAX_SCORE - minimum_score ) < delta_size * MAX_SCORE )
173
+ if (max_size * (MAX_SCORE - minimum_score ) < delta_size * MAX_SCORE )
174
174
return 0 ;
175
175
176
176
if (!src -> cnt_data && diff_populate_filespec (src , 0 ))
@@ -247,7 +247,8 @@ struct file_similarity {
247
247
};
248
248
249
249
static int find_identical_files (struct file_similarity * src ,
250
- struct file_similarity * dst )
250
+ struct file_similarity * dst ,
251
+ struct diff_options * options )
251
252
{
252
253
int renames = 0 ;
253
254
@@ -277,6 +278,8 @@ static int find_identical_files(struct file_similarity *src,
277
278
}
278
279
/* Give higher scores to sources that haven't been used already */
279
280
score = !source -> rename_used ;
281
+ if (source -> rename_used && options -> detect_rename != DIFF_DETECT_COPY )
282
+ continue ;
280
283
score += basename_same (source , target );
281
284
if (score > best_score ) {
282
285
best = p ;
@@ -306,11 +309,12 @@ static void free_similarity_list(struct file_similarity *p)
306
309
}
307
310
}
308
311
309
- static int find_same_files (void * ptr )
312
+ static int find_same_files (void * ptr , void * data )
310
313
{
311
314
int ret ;
312
315
struct file_similarity * p = ptr ;
313
316
struct file_similarity * src = NULL , * dst = NULL ;
317
+ struct diff_options * options = data ;
314
318
315
319
/* Split the hash list up into sources and destinations */
316
320
do {
@@ -329,7 +333,7 @@ static int find_same_files(void *ptr)
329
333
* If we have both sources *and* destinations, see if
330
334
* we can match them up
331
335
*/
332
- ret = (src && dst ) ? find_identical_files (src , dst ) : 0 ;
336
+ ret = (src && dst ) ? find_identical_files (src , dst , options ) : 0 ;
333
337
334
338
/* Free the hashes and return the number of renames found */
335
339
free_similarity_list (src );
@@ -377,7 +381,7 @@ static void insert_file_table(struct hash_table *table, int src_dst, int index,
377
381
* and then during the second round we try to match
378
382
* cache-dirty entries as well.
379
383
*/
380
- static int find_exact_renames (void )
384
+ static int find_exact_renames (struct diff_options * options )
381
385
{
382
386
int i ;
383
387
struct hash_table file_table ;
@@ -390,7 +394,7 @@ static int find_exact_renames(void)
390
394
insert_file_table (& file_table , 1 , i , rename_dst [i ].two );
391
395
392
396
/* Find the renames */
393
- i = for_each_hash (& file_table , find_same_files );
397
+ i = for_each_hash (& file_table , find_same_files , options );
394
398
395
399
/* .. and free the hash data structure */
396
400
free_hash (& file_table );
@@ -414,6 +418,27 @@ static void record_if_better(struct diff_score m[], struct diff_score *o)
414
418
m [worst ] = * o ;
415
419
}
416
420
421
+ static int find_renames (struct diff_score * mx , int dst_cnt , int minimum_score , int copies )
422
+ {
423
+ int count = 0 , i ;
424
+
425
+ for (i = 0 ; i < dst_cnt * NUM_CANDIDATE_PER_DST ; i ++ ) {
426
+ struct diff_rename_dst * dst ;
427
+
428
+ if ((mx [i ].dst < 0 ) ||
429
+ (mx [i ].score < minimum_score ))
430
+ break ; /* there is no more usable pair. */
431
+ dst = & rename_dst [mx [i ].dst ];
432
+ if (dst -> pair )
433
+ continue ; /* already done, either exact or fuzzy. */
434
+ if (!copies && rename_src [mx [i ].src ].one -> rename_used )
435
+ continue ;
436
+ record_rename_pair (mx [i ].dst , mx [i ].src , mx [i ].score );
437
+ count ++ ;
438
+ }
439
+ return count ;
440
+ }
441
+
417
442
void diffcore_rename (struct diff_options * options )
418
443
{
419
444
int detect_rename = options -> detect_rename ;
@@ -467,7 +492,7 @@ void diffcore_rename(struct diff_options *options)
467
492
* We really want to cull the candidates list early
468
493
* with cheap tests in order to avoid doing deltas.
469
494
*/
470
- rename_count = find_exact_renames ();
495
+ rename_count = find_exact_renames (options );
471
496
472
497
/* Did we only want exact renames? */
473
498
if (minimum_score == MAX_SCORE )
@@ -536,33 +561,9 @@ void diffcore_rename(struct diff_options *options)
536
561
/* cost matrix sorted by most to least similar pair */
537
562
qsort (mx , dst_cnt * NUM_CANDIDATE_PER_DST , sizeof (* mx ), score_compare );
538
563
539
- for (i = 0 ; i < dst_cnt * NUM_CANDIDATE_PER_DST ; i ++ ) {
540
- struct diff_rename_dst * dst ;
541
-
542
- if ((mx [i ].dst < 0 ) ||
543
- (mx [i ].score < minimum_score ))
544
- break ; /* there is no more usable pair. */
545
- dst = & rename_dst [mx [i ].dst ];
546
- if (dst -> pair )
547
- continue ; /* already done, either exact or fuzzy. */
548
- if (rename_src [mx [i ].src ].one -> rename_used )
549
- continue ;
550
- record_rename_pair (mx [i ].dst , mx [i ].src , mx [i ].score );
551
- rename_count ++ ;
552
- }
553
-
554
- for (i = 0 ; i < dst_cnt * NUM_CANDIDATE_PER_DST ; i ++ ) {
555
- struct diff_rename_dst * dst ;
556
-
557
- if ((mx [i ].dst < 0 ) ||
558
- (mx [i ].score < minimum_score ))
559
- break ; /* there is no more usable pair. */
560
- dst = & rename_dst [mx [i ].dst ];
561
- if (dst -> pair )
562
- continue ; /* already done, either exact or fuzzy. */
563
- record_rename_pair (mx [i ].dst , mx [i ].src , mx [i ].score );
564
- rename_count ++ ;
565
- }
564
+ rename_count += find_renames (mx , dst_cnt , minimum_score , 0 );
565
+ if (detect_rename == DIFF_DETECT_COPY )
566
+ rename_count += find_renames (mx , dst_cnt , minimum_score , 1 );
566
567
free (mx );
567
568
568
569
cleanup :
0 commit comments