@matheusbsbs / matheus-bagliano / commits / 462a15bc82
Fork 0

combine-diff: Fix path quoting

Earlier when showing combined diff, the filenames on the ---/+++ header lines were quoted incorrectly. a/ (or b/) prefix was output literally and then the path was output, with c-quoting. This fixes the quoting logic, and while at it, adjusts the code to use the customizable prefix (a_prefix and b_prefix) introduced recently. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Dec 26, 2007 at 16:51 UTC 462a15bc82e6adbcb8db5fcc4791ec70a026aa4b
1 file changed +31 -10
combine-diff.c
+31 -10
@@ -646,12 +646,28 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
646 sline->p_lno[i] = sline->p_lno[j];
647 }
648
649 -static void dump_quoted_path(const char *prefix, const char *path,
649 +static void dump_quoted_path(const char *head,
650 + const char *prefix,
651 + const char *path,
652 const char *c_meta, const char *c_reset)
653 {
652 - printf("%s%s", c_meta, prefix);
653 - quote_c_style(path, NULL, stdout, 0);
654 - printf("%s\n", c_reset);
654 + static struct strbuf buf = STRBUF_INIT;
655 +
656 + strbuf_reset(&buf);
657 + strbuf_addstr(&buf, c_meta);
658 + strbuf_addstr(&buf, head);
659 + if (quote_c_style(prefix, NULL, NULL, 0) ||
660 + quote_c_style(path, NULL, NULL, 0)) {
661 + strbuf_addch(&buf, '"');
662 + quote_c_style(prefix, &buf, NULL, 1);
663 + quote_c_style(path, &buf, NULL, 1);
664 + strbuf_addch(&buf, '"');
665 + } else {
666 + strbuf_addstr(&buf, prefix);
667 + strbuf_addstr(&buf, path);
668 + }
669 + strbuf_addstr(&buf, c_reset);
670 + puts(buf.buf);
671 }
672
673 static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
@@ -793,7 +809,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
809 if (rev->loginfo && !rev->no_commit_id)
810 show_log(rev, opt->msg_sep);
811 dump_quoted_path(dense ? "diff --cc " : "diff --combined ",
796 - elem->path, c_meta, c_reset);
812 + "", elem->path, c_meta, c_reset);
813 printf("%sindex ", c_meta);
814 for (i = 0; i < num_parent; i++) {
815 abb = find_unique_abbrev(elem->parent[i].sha1,
@@ -829,14 +845,19 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
845 printf("%s\n", c_reset);
846 }
847 if (added)
832 - dump_quoted_path("--- /dev/", "null", c_meta, c_reset);
848 + dump_quoted_path("--- ", "", "/dev/null",
849 + c_meta, c_reset);
850 else
834 - dump_quoted_path("--- a/", elem->path, c_meta, c_reset);
851 + dump_quoted_path("--- ", opt->a_prefix, elem->path,
852 + c_meta, c_reset);
853 if (deleted)
836 - dump_quoted_path("+++ /dev/", "null", c_meta, c_reset);
854 + dump_quoted_path("+++ ", "", "/dev/null",
855 + c_meta, c_reset);
856 else
838 - dump_quoted_path("+++ b/", elem->path, c_meta, c_reset);
839 - dump_sline(sline, cnt, num_parent, DIFF_OPT_TST(opt, COLOR_DIFF));
857 + dump_quoted_path("+++ ", opt->b_prefix, elem->path,
858 + c_meta, c_reset);
859 + dump_sline(sline, cnt, num_parent,
860 + DIFF_OPT_TST(opt, COLOR_DIFF));
861 }
862 free(result);
863