summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b779d5f)
raw | patch | inline | side by side (parent: b779d5f)
author | Junio C Hamano <junkio@cox.net> | |
Sat, 10 Sep 2005 19:42:32 +0000 (12:42 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sat, 10 Sep 2005 19:42:32 +0000 (12:42 -0700) |
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>
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>
diff.c | patch | blob | history | |
diffcore-rename.c | patch | blob | history |
index 71696c5eee45af40024a7761f5470f4b3e39b6b9..f8e3cbf1a652de273ee3a9b98c09eefc268f9977 100644 (file)
--- a/diff.c
+++ b/diff.c
}
/* See if there is some other filepair that
* copies from the same source as us. If so
- * we are a copy. Otherwise we are a rename.
+ * we are a copy. Otherwise we are either a
+ * copy if the path stays, or a rename if it
+ * does not, but we already handled "stays" case.
*/
for (j = i + 1; j < q->nr; j++) {
pp = q->queue[j];
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 6a52699f732c76540d71ce1500bd8d838ee8a265..dbc85221320ed06e332fab25325020da241bde78 100644 (file)
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
/* Table of rename/copy src files */
static struct diff_rename_src {
struct diff_filespec *one;
- unsigned src_stays : 1;
+ unsigned src_path_left : 1;
} *rename_src;
static int rename_src_nr, rename_src_alloc;
static struct diff_rename_src *register_rename_src(struct diff_filespec *one,
- int src_stays)
+ int src_path_left)
{
int first, last;
memmove(rename_src + first + 1, rename_src + first,
(rename_src_nr - first - 1) * sizeof(*rename_src));
rename_src[first].one = one;
- rename_src[first].src_stays = src_stays;
+ rename_src[first].src_path_left = src_path_left;
return &(rename_src[first]);
}
dp = diff_queue(renq, one, two);
dp->score = score;
- dp->source_stays = rename_src[src_index].src_stays;
+ dp->source_stays = rename_src[src_index].src_path_left;
rename_dst[dst_index].pair = dp;
}
return b->score - a->score;
}
+static int compute_stays(struct diff_queue_struct *q,
+ struct diff_filespec *one)
+{
+ int i;
+ for (i = 0; i < q->nr; i++) {
+ struct diff_filepair *p = q->queue[i];
+ if (strcmp(one->path, p->two->path))
+ continue;
+ if (DIFF_PAIR_RENAME(p)) {
+ return 0; /* something else is renamed into this */
+ }
+ }
+ return 1;
+}
+
void diffcore_rename(int detect_rename, int minimum_score)
{
struct diff_queue_struct *q = &diff_queued_diff;
*q = outq;
diff_debug_queue("done collapsing", q);
+ /* We need to see which rename source really stays here;
+ * earlier we only checked if the path is left in the result,
+ * but even if a path remains in the result, if that is coming
+ * from copying something else on top of it, then the original
+ * source is lost and does not stay.
+ */
+ for (i = 0; i < q->nr; i++) {
+ struct diff_filepair *p = q->queue[i];
+ if (DIFF_PAIR_RENAME(p) && p->source_stays) {
+ /* If one appears as the target of a rename-copy,
+ * then mark p->source_stays = 0; otherwise
+ * leave it as is.
+ */
+ p->source_stays = compute_stays(q, p->one);
+ }
+ }
+
free(rename_dst);
rename_dst = NULL;
rename_dst_nr = rename_dst_alloc = 0;