55
static struct diff_rename_src {
56
struct diff_filespec *one;
57
unsigned short score; /* to remember the break score */
58
- unsigned src_path_left : 1;
58
} *rename_src;
59
static int rename_src_nr, rename_src_alloc;
60
61
static struct diff_rename_src *register_rename_src(struct diff_filespec *one,
63
- int src_path_left,
62
unsigned short score)
63
{
64
int first, last;
90
(rename_src_nr - first - 1) * sizeof(*rename_src));
91
rename_src[first].one = one;
92
rename_src[first].score = score;
95
- rename_src[first].src_path_left = src_path_left;
93
return &(rename_src[first]);
94
}
95
213
die("internal error: dst already matched.");
214
215
src = rename_src[src_index].one;
216
+ src->rename_used++;
217
src->count++;
218
219
dst = rename_dst[dst_index].two;
225
dp->score = rename_src[src_index].score;
226
else
227
dp->score = score;
230
- dp->source_stays = rename_src[src_index].src_path_left;
228
rename_dst[dst_index].pair = dp;
229
}
230
242
return b->score - a->score;
243
}
244
248
-static int compute_stays(struct diff_queue_struct *q,
249
- struct diff_filespec *one)
250
-{
251
- int i;
252
- for (i = 0; i < q->nr; i++) {
253
- struct diff_filepair *p = q->queue[i];
254
- if (strcmp(one->path, p->two->path))
255
- continue;
256
- if (DIFF_PAIR_RENAME(p)) {
257
- return 0; /* something else is renamed into this */
258
- }
259
- }
260
- return 1;
261
-}
262
-
245
/*
246
* Find exact renames first.
247
*
320
locate_rename_dst(p->two, 1);
321
}
322
else if (!DIFF_FILE_VALID(p->two)) {
341
- /* If the source is a broken "delete", and
323
+ /*
324
+ * If the source is a broken "delete", and
325
* they did not really want to get broken,
326
* that means the source actually stays.
327
+ * So we increment the "rename_used" score
328
+ * by one, to indicate ourselves as a user
329
+ */
330
+ if (p->broken_pair && !p->score)
331
+ p->one->rename_used++;
332
+ register_rename_src(p->one, p->score);
333
+ }
334
+ else if (detect_rename == DIFF_DETECT_COPY) {
335
+ /*
336
+ * Increment the "rename_used" score by
337
+ * one, to indicate ourselves as a user.
338
*/
345
- int stays = (p->broken_pair && !p->score);
346
- register_rename_src(p->one, stays, p->score);
339
+ p->one->rename_used++;
340
+ register_rename_src(p->one, p->score);
341
}
348
- else if (detect_rename == DIFF_DETECT_COPY)
349
- register_rename_src(p->one, 1, p->score);
342
}
343
if (rename_dst_nr == 0 || rename_src_nr == 0)
344
goto cleanup; /* nothing to do */
464
pair_to_free = p;
465
}
466
else {
475
- for (j = 0; j < rename_dst_nr; j++) {
476
- if (!rename_dst[j].pair)
477
- continue;
478
- if (strcmp(rename_dst[j].pair->
479
- one->path,
480
- p->one->path))
481
- continue;
482
- break;
483
- }
484
- if (j < rename_dst_nr)
467
+ if (p->one->rename_used)
468
/* this path remains */
469
pair_to_free = p;
470
}
490
*q = outq;
491
diff_debug_queue("done collapsing", q);
492
510
- /* We need to see which rename source really stays here;
511
- * earlier we only checked if the path is left in the result,
512
- * but even if a path remains in the result, if that is coming
513
- * from copying something else on top of it, then the original
514
- * source is lost and does not stay.
515
- */
516
- for (i = 0; i < q->nr; i++) {
517
- struct diff_filepair *p = q->queue[i];
518
- if (DIFF_PAIR_RENAME(p) && p->source_stays) {
519
- /* If one appears as the target of a rename-copy,
520
- * then mark p->source_stays = 0; otherwise
521
- * leave it as is.
522
- */
523
- p->source_stays = compute_stays(q, p->one);
524
- }
525
- }
526
-
493
for (i = 0; i < rename_dst_nr; i++)
494
free_filespec(rename_dst[i].two);
495