Skip to content

Commit d416df8

Browse files
author
Junio C Hamano
committed
combine-diff: Record diff status a bit more faithfully
This shows "new file mode XXXX" and "deleted file mode XXXX" lines like two-way diff-patch output does, by checking the status from each parent. The diff-raw output for combined diff is made a bit uglier by showing diff status letters with each parent. While most of the case you would see "MM" in the output, an Evil Merge that touches a path that was added by inheriting from one parent is possible and it would be shown like these: $ git-diff-tree --abbrev -c HEAD 2d7ca89675eb8888b0b88a91102f096d4471f09f ::000000 000000 100644 0000000... 0000000... 31dd686... AA b ::000000 100644 100644 0000000... 6c884ae... c6d4fa8... AM d ::100644 100644 100644 4f7cbe7... f8c295c... 19d5d80... RR e Signed-off-by: Junio C Hamano <[email protected]>
1 parent 297a1aa commit d416df8

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

combine-diff.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
3939
p->mode = q->queue[i]->two->mode;
4040
memcpy(p->parent[n].sha1, q->queue[i]->one->sha1, 20);
4141
p->parent[n].mode = q->queue[i]->one->mode;
42+
p->parent[n].status = q->queue[i]->status;
4243
*tail = p;
4344
tail = &p->next;
4445
}
@@ -62,6 +63,7 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
6263
memcpy(p->parent[n].sha1,
6364
q->queue[i]->one->sha1, 20);
6465
p->parent[n].mode = q->queue[i]->one->mode;
66+
p->parent[n].status = q->queue[i]->status;
6567
break;
6668
}
6769
}
@@ -739,12 +741,25 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
739741
printf("..%s\n", abb);
740742

741743
if (mode_differs) {
742-
printf("mode ");
743-
for (i = 0; i < num_parent; i++) {
744-
printf("%s%06o", i ? "," : "",
745-
elem->parent[i].mode);
744+
int added = !!elem->mode;
745+
for (i = 0; added && i < num_parent; i++)
746+
if (elem->parent[i].status !=
747+
DIFF_STATUS_ADDED)
748+
added = 0;
749+
if (added)
750+
printf("new file mode %06o", elem->mode);
751+
else {
752+
if (!elem->mode)
753+
printf("deleted file ");
754+
printf("mode ");
755+
for (i = 0; i < num_parent; i++) {
756+
printf("%s%06o", i ? "," : "",
757+
elem->parent[i].mode);
758+
}
759+
if (elem->mode)
760+
printf("..%06o", elem->mode);
746761
}
747-
printf("..%06o\n", elem->mode);
762+
putchar('\n');
748763
}
749764
dump_sline(sline, cnt, num_parent);
750765
}
@@ -811,8 +826,11 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
811826
}
812827

813828
if (opt->output_format == DIFF_FORMAT_RAW ||
814-
opt->output_format == DIFF_FORMAT_NAME_STATUS)
815-
printf("%c%c", mod_type, inter_name_termination);
829+
opt->output_format == DIFF_FORMAT_NAME_STATUS) {
830+
for (i = 0; i < num_parent; i++)
831+
putchar(p->parent[i].status);
832+
putchar(inter_name_termination);
833+
}
816834

817835
if (line_termination) {
818836
if (quote_c_style(p->path, NULL, NULL, 0))

diff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct combine_diff_path {
6666
unsigned int mode;
6767
unsigned char sha1[20];
6868
struct combine_diff_parent {
69+
char status;
6970
unsigned int mode;
7071
unsigned char sha1[20];
7172
} parent[FLEX_ARRAY];

0 commit comments

Comments
 (0)