Fix copy marking from diffcore-rename.
When (A,B) ==> (B,C) rename-copy was detected, we incorrectly said that C was created by copying B. This is because we only check if the path of rename/copy source still exists in the resulting tree to see if the file is renamed out of existence. In this case, the new B is created by copying or renaming A, so the original B is lost and we should say C is a rename of B not a copy of B. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Sep 10, 2005 at 12:42 UTC
6bac10d89d0889118a3e747c9c9210fd437c140d
2 files changed
+39
-5
diff.c
+3
-1
@@ -955,7 +955,9 @@ static void diff_resolve_rename_copy(void)
955
}
956
/* See if there is some other filepair that
957
* copies from the same source as us. If so
958
- * we are a copy. Otherwise we are a rename.
958
+ * we are a copy. Otherwise we are either a
959
+ * copy if the path stays, or a rename if it
960
+ * does not, but we already handled "stays" case.
961
*/
962
for (j = i + 1; j < q->nr; j++) {
963
pp = q->queue[j];
diffcore-rename.c
+36
-4
@@ -55,12 +55,12 @@ static struct diff_rename_dst *locate_rename_dst(struct diff_filespec *two,
55
/* Table of rename/copy src files */
56
static struct diff_rename_src {
57
struct diff_filespec *one;
58
- unsigned src_stays : 1;
58
+ unsigned src_path_left : 1;
59
} *rename_src;
60
static int rename_src_nr, rename_src_alloc;
61
62
static struct diff_rename_src *register_rename_src(struct diff_filespec *one,
63
- int src_stays)
63
+ int src_path_left)
64
{
65
int first, last;
66
@@ -90,7 +90,7 @@ static struct diff_rename_src *register_rename_src(struct diff_filespec *one,
90
memmove(rename_src + first + 1, rename_src + first,
91
(rename_src_nr - first - 1) * sizeof(*rename_src));
92
rename_src[first].one = one;
93
- rename_src[first].src_stays = src_stays;
93
+ rename_src[first].src_path_left = src_path_left;
94
return &(rename_src[first]);
95
}
96
@@ -220,7 +220,7 @@ static void record_rename_pair(struct diff_queue_struct *renq,
220
221
dp = diff_queue(renq, one, two);
222
dp->score = score;
223
- dp->source_stays = rename_src[src_index].src_stays;
223
+ dp->source_stays = rename_src[src_index].src_path_left;
224
rename_dst[dst_index].pair = dp;
225
}
226
@@ -234,6 +234,21 @@ static int score_compare(const void *a_, const void *b_)
234
return b->score - a->score;
235
}
236
237
+static int compute_stays(struct diff_queue_struct *q,
238
+ struct diff_filespec *one)
239
+{
240
+ int i;
241
+ for (i = 0; i < q->nr; i++) {
242
+ struct diff_filepair *p = q->queue[i];
243
+ if (strcmp(one->path, p->two->path))
244
+ continue;
245
+ if (DIFF_PAIR_RENAME(p)) {
246
+ return 0; /* something else is renamed into this */
247
+ }
248
+ }
249
+ return 1;
250
+}
251
+
252
void diffcore_rename(int detect_rename, int minimum_score)
253
{
254
struct diff_queue_struct *q = &diff_queued_diff;
@@ -406,6 +421,23 @@ void diffcore_rename(int detect_rename, int minimum_score)
421
*q = outq;
422
diff_debug_queue("done collapsing", q);
423
424
+ /* We need to see which rename source really stays here;
425
+ * earlier we only checked if the path is left in the result,
426
+ * but even if a path remains in the result, if that is coming
427
+ * from copying something else on top of it, then the original
428
+ * source is lost and does not stay.
429
+ */
430
+ for (i = 0; i < q->nr; i++) {
431
+ struct diff_filepair *p = q->queue[i];
432
+ if (DIFF_PAIR_RENAME(p) && p->source_stays) {
433
+ /* If one appears as the target of a rename-copy,
434
+ * then mark p->source_stays = 0; otherwise
435
+ * leave it as is.
436
+ */
437
+ p->source_stays = compute_stays(q, p->one);
438
+ }
439
+ }
440
+
441
free(rename_dst);
442
rename_dst = NULL;
443
rename_dst_nr = rename_dst_alloc = 0;