@matheusbsbs / matheus-bagliano / commits / d416df8869
Fork 0

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 <junkio@cox.net>

Junio C Hamano committed Feb 10, 2006 at 02:30 UTC d416df8869d803282fb254a18505eccceee9ba3e
2 files changed +26 -7
combine-diff.c
+25 -7
@@ -39,6 +39,7 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
39 p->mode = q->queue[i]->two->mode;
40 memcpy(p->parent[n].sha1, q->queue[i]->one->sha1, 20);
41 p->parent[n].mode = q->queue[i]->one->mode;
42 + p->parent[n].status = q->queue[i]->status;
43 *tail = p;
44 tail = &p->next;
45 }
@@ -62,6 +63,7 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
63 memcpy(p->parent[n].sha1,
64 q->queue[i]->one->sha1, 20);
65 p->parent[n].mode = q->queue[i]->one->mode;
66 + p->parent[n].status = q->queue[i]->status;
67 break;
68 }
69 }
@@ -739,12 +741,25 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
741 printf("..%s\n", abb);
742
743 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);
761 }
747 - printf("..%06o\n", elem->mode);
762 + putchar('\n');
763 }
764 dump_sline(sline, cnt, num_parent);
765 }
@@ -811,8 +826,11 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
826 }
827
828 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 + }
834
835 if (line_termination) {
836 if (quote_c_style(p->path, NULL, NULL, 0))
diff.h
+1
@@ -66,6 +66,7 @@ struct combine_diff_path {
66 unsigned int mode;
67 unsigned char sha1[20];
68 struct combine_diff_parent {
69 + char status;
70 unsigned int mode;
71 unsigned char sha1[20];
72 } parent[FLEX_ARRAY];