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

diff.c: More logical file name quoting for renames in diffstat.

Quote both file names separately when printing a rename, yielding something like "foo" => "bar" instead of the current "foo => bar" Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Alexandre Julliard committed Feb 10, 2007 at 15:39 UTC e5bfbf9b3ee57292aea95313e8659d26f90f8cc5
1 file changed +27 -7
diff.c
+27 -7
@@ -545,6 +545,24 @@ static char *pprint_rename(const char *a, const char *b)
545 int pfx_length, sfx_length;
546 int len_a = strlen(a);
547 int len_b = strlen(b);
548 + int qlen_a = quote_c_style(a, NULL, NULL, 0);
549 + int qlen_b = quote_c_style(b, NULL, NULL, 0);
550 +
551 + if (qlen_a || qlen_b) {
552 + if (qlen_a) len_a = qlen_a;
553 + if (qlen_b) len_b = qlen_b;
554 + name = xmalloc( len_a + len_b + 5 );
555 + if (qlen_a)
556 + quote_c_style(a, name, NULL, 0);
557 + else
558 + memcpy(name, a, len_a);
559 + memcpy(name + len_a, " => ", 4);
560 + if (qlen_b)
561 + quote_c_style(b, name + len_a + 4, NULL, 0);
562 + else
563 + memcpy(name + len_a + 4, b, len_b + 1);
564 + return name;
565 + }
566
567 /* Find common prefix */
568 pfx_length = 0;
@@ -701,12 +719,14 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options)
719 struct diffstat_file *file = data->files[i];
720 int change = file->added + file->deleted;
721
704 - len = quote_c_style(file->name, NULL, NULL, 0);
705 - if (len) {
706 - char *qname = xmalloc(len + 1);
707 - quote_c_style(file->name, qname, NULL, 0);
708 - free(file->name);
709 - file->name = qname;
722 + if (!file->is_renamed) { /* renames are already quoted by pprint_rename */
723 + len = quote_c_style(file->name, NULL, NULL, 0);
724 + if (len) {
725 + char *qname = xmalloc(len + 1);
726 + quote_c_style(file->name, qname, NULL, 0);
727 + free(file->name);
728 + file->name = qname;
729 + }
730 }
731
732 len = strlen(file->name);
@@ -838,7 +858,7 @@ static void show_numstat(struct diffstat_t* data, struct diff_options *options)
858 printf("-\t-\t");
859 else
860 printf("%d\t%d\t", file->added, file->deleted);
841 - if (options->line_termination &&
861 + if (options->line_termination && !file->is_renamed &&
862 quote_c_style(file->name, NULL, NULL, 0))
863 quote_c_style(file->name, NULL, stdout, 0);
864 else