- if (!diff_unmodified_pair(p) ||
- diff_used_as_source(q, i, p->one))
- diff_q(&outq, p);
- else
- free(p);
+ p->status = 0;
+ if (DIFF_PAIR_UNMERGED(p))
+ p->status = 'U';
+ else if (!DIFF_FILE_VALID((p)->one))
+ p->status = 'N';
+ else if (!DIFF_FILE_VALID((p)->two)) {
+ /* maybe earlier one said 'R', meaning
+ * it will take it, in which case we do
+ * not need to keep 'D'.
+ */
+ int j;
+ for (j = 0; j < i; j++) {
+ struct diff_filepair *pp = q->queue[j];
+ if (pp->status == 'R' &&
+ !strcmp(pp->one->path, p->one->path))
+ break;
+ }
+ if (j < i)
+ continue;
+ p->status = 'D';
+ }
+ else if (strcmp(p->one->path, p->two->path)) {
+ /* This is rename or copy. Which one is it? */
+ if (diff_needs_to_stay(q, i+1, p->one))
+ p->status = 'C';
+ else
+ p->status = 'R';
+ }
+ else if (memcmp(p->one->sha1, p->two->sha1, 20))
+ p->status = 'M';
+ else {
+ /* we do not need this one */
+ p->status = 0;
+ }