combine-diff.c: teach combined diffs about line prefix

When running "git log --graph --cc -p" the diff output for merges is not indented by the graph structure, unlike the diffs of non-merge commits (added in commit 7be5761 - diff.c: Output the text graph padding before each diff line). Fix this by teaching the combined diff code to output diff_line_prefix() before each line. Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

John Keeping committed Feb 7, 2013 at 20:15 UTC 41ee2ad6cbebab0429248a14ec4e02afddd60dbe
1 file changed +30 -17
combine-diff.c
+30 -17
@@ -526,7 +526,8 @@ static void show_line_to_eol(const char *line, int len, const char *reset)
526 saw_cr_at_eol ? "\r" : "");
527 }
528
529 -static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
529 +static void dump_sline(struct sline *sline, const char *line_prefix,
530 + unsigned long cnt, int num_parent,
531 int use_color, int result_deleted)
532 {
533 unsigned long mark = (1UL<<num_parent);
@@ -582,7 +583,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
583 rlines -= null_context;
584 }
585
585 - fputs(c_frag, stdout);
586 + printf("%s%s", line_prefix, c_frag);
587 for (i = 0; i <= num_parent; i++) putchar(combine_marker);
588 for (i = 0; i < num_parent; i++)
589 show_parent_lno(sline, lno, hunk_end, i, null_context);
@@ -614,7 +615,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
615 struct sline *sl = &sline[lno++];
616 ll = (sl->flag & no_pre_delete) ? NULL : sl->lost_head;
617 while (ll) {
617 - fputs(c_old, stdout);
618 + printf("%s%s", line_prefix, c_old);
619 for (j = 0; j < num_parent; j++) {
620 if (ll->parent_map & (1UL<<j))
621 putchar('-');
@@ -627,6 +628,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
628 if (cnt < lno)
629 break;
630 p_mask = 1;
631 + fputs(line_prefix, stdout);
632 if (!(sl->flag & (mark-1))) {
633 /*
634 * This sline was here to hang the
@@ -680,11 +682,13 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
682 static void dump_quoted_path(const char *head,
683 const char *prefix,
684 const char *path,
685 + const char *line_prefix,
686 const char *c_meta, const char *c_reset)
687 {
688 static struct strbuf buf = STRBUF_INIT;
689
690 strbuf_reset(&buf);
691 + strbuf_addstr(&buf, line_prefix);
692 strbuf_addstr(&buf, c_meta);
693 strbuf_addstr(&buf, head);
694 quote_two_c_style(&buf, prefix, path, 0);
@@ -696,6 +700,7 @@ static void show_combined_header(struct combine_diff_path *elem,
700 int num_parent,
701 int dense,
702 struct rev_info *rev,
703 + const char *line_prefix,
704 int mode_differs,
705 int show_file_header)
706 {
@@ -714,8 +719,8 @@ static void show_combined_header(struct combine_diff_path *elem,
719 show_log(rev);
720
721 dump_quoted_path(dense ? "diff --cc " : "diff --combined ",
717 - "", elem->path, c_meta, c_reset);
718 - printf("%sindex ", c_meta);
722 + "", elem->path, line_prefix, c_meta, c_reset);
723 + printf("%s%sindex ", line_prefix, c_meta);
724 for (i = 0; i < num_parent; i++) {
725 abb = find_unique_abbrev(elem->parent[i].sha1,
726 abbrev);
@@ -734,11 +739,12 @@ static void show_combined_header(struct combine_diff_path *elem,
739 DIFF_STATUS_ADDED)
740 added = 0;
741 if (added)
737 - printf("%snew file mode %06o",
738 - c_meta, elem->mode);
742 + printf("%s%snew file mode %06o",
743 + line_prefix, c_meta, elem->mode);
744 else {
745 if (deleted)
741 - printf("%sdeleted file ", c_meta);
746 + printf("%s%sdeleted file ",
747 + line_prefix, c_meta);
748 printf("mode ");
749 for (i = 0; i < num_parent; i++) {
750 printf("%s%06o", i ? "," : "",
@@ -755,16 +761,16 @@ static void show_combined_header(struct combine_diff_path *elem,
761
762 if (added)
763 dump_quoted_path("--- ", "", "/dev/null",
758 - c_meta, c_reset);
764 + line_prefix, c_meta, c_reset);
765 else
766 dump_quoted_path("--- ", a_prefix, elem->path,
761 - c_meta, c_reset);
767 + line_prefix, c_meta, c_reset);
768 if (deleted)
769 dump_quoted_path("+++ ", "", "/dev/null",
764 - c_meta, c_reset);
770 + line_prefix, c_meta, c_reset);
771 else
772 dump_quoted_path("+++ ", b_prefix, elem->path,
767 - c_meta, c_reset);
773 + line_prefix, c_meta, c_reset);
774 }
775
776 static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
@@ -782,6 +788,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
788 struct userdiff_driver *userdiff;
789 struct userdiff_driver *textconv = NULL;
790 int is_binary;
791 + const char *line_prefix = diff_line_prefix(opt);
792
793 context = opt->context;
794 userdiff = userdiff_find_by_path(elem->path);
@@ -901,7 +908,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
908 }
909 if (is_binary) {
910 show_combined_header(elem, num_parent, dense, rev,
904 - mode_differs, 0);
911 + line_prefix, mode_differs, 0);
912 printf("Binary files differ\n");
913 free(result);
914 return;
@@ -962,8 +969,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
969
970 if (show_hunks || mode_differs || working_tree_file) {
971 show_combined_header(elem, num_parent, dense, rev,
965 - mode_differs, 1);
966 - dump_sline(sline, cnt, num_parent,
972 + line_prefix, mode_differs, 1);
973 + dump_sline(sline, line_prefix, cnt, num_parent,
974 opt->use_color, result_deleted);
975 }
976 free(result);
@@ -990,6 +997,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
997 int i, offset;
998 const char *prefix;
999 int line_termination, inter_name_termination;
1000 + const char *line_prefix = diff_line_prefix(opt);
1001
1002 line_termination = opt->line_termination;
1003 inter_name_termination = '\t';
@@ -1000,6 +1008,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
1008 show_log(rev);
1009
1010 if (opt->output_format & DIFF_FORMAT_RAW) {
1011 + printf("%s", line_prefix);
1012 offset = strlen(COLONS) - num_parent;
1013 if (offset < 0)
1014 offset = 0;
@@ -1040,6 +1049,7 @@ void show_combined_diff(struct combine_diff_path *p,
1049 struct rev_info *rev)
1050 {
1051 struct diff_options *opt = &rev->diffopt;
1052 +
1053 if (!p->len)
1054 return;
1055 if (opt->output_format & (DIFF_FORMAT_RAW |
@@ -1150,8 +1160,10 @@ void diff_tree_combined(const unsigned char *sha1,
1160
1161 if (show_log_first && i == 0) {
1162 show_log(rev);
1163 +
1164 if (rev->verbose_header && opt->output_format)
1154 - putchar(opt->line_termination);
1165 + printf("%s%c", diff_line_prefix(opt),
1166 + opt->line_termination);
1167 }
1168 diff_flush(&diffopts);
1169 }
@@ -1179,7 +1191,8 @@ void diff_tree_combined(const unsigned char *sha1,
1191
1192 if (opt->output_format & DIFF_FORMAT_PATCH) {
1193 if (needsep)
1182 - putchar(opt->line_termination);
1194 + printf("%s%c", diff_line_prefix(opt),
1195 + opt->line_termination);
1196 for (p = paths; p; p = p->next) {
1197 if (p->len)
1198 show_patch_diff(p, num_parent, dense,