X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=diffcore-rename.c;fp=diffcore-rename.c;h=6ed8cf5aec7dc60d1eeeaed3a6a8781832aa3205;hb=2cd68882ee8629f9782be017007fff4c78e45e45;hp=cf3fe093230ede0dd1b9a61ddbe06f4892fbc1a5;hpb=9d429ff6ff2832d6e63933e6d33b8380be703017;p=git.git diff --git a/diffcore-rename.c b/diffcore-rename.c index cf3fe093..6ed8cf5a 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -328,26 +328,48 @@ void diffcore_rename(int detect_rename, int minimum_score) outq.nr = outq.alloc = 0; for (i = 0; i < q->nr; i++) { struct diff_filepair *p = q->queue[i]; - struct diff_rename_dst *dst = locate_rename_dst(p->two, 0); struct diff_filepair *pair_to_free = NULL; - if (dst) { - /* creation */ - if (dst->pair) { - /* renq has rename/copy to produce - * this file already, so we do not - * emit the creation record in the - * output. - */ + if (!DIFF_FILE_VALID(p->one) && DIFF_FILE_VALID(p->two)) { + /* + * Creation + * + * We would output this create record if it has + * not been turned into a rename/copy already. + */ + struct diff_rename_dst *dst = + locate_rename_dst(p->two, 0); + if (dst && dst->pair) { diff_q(&outq, dst->pair); pair_to_free = p; } else - /* no matching rename/copy source, so record - * this as a creation. + /* no matching rename/copy source, so + * record this as a creation. */ diff_q(&outq, p); } + else if (DIFF_FILE_VALID(p->one) && !DIFF_FILE_VALID(p->two)) { + /* + * Deletion + * + * We would output this delete record if renq + * does not have a rename/copy to move + * p->one->path out. + */ + for (j = 0; j < renq.nr; j++) + if (!strcmp(renq.queue[j]->one->path, + p->one->path)) + break; + if (j < renq.nr) + /* this path remains */ + pair_to_free = p; + + if (pair_to_free) + ; + else + diff_q(&outq, p); + } else if (!diff_unmodified_pair(p)) /* all the usual ones need to be kept */ diff_q(&outq, p);