Code

Merge branch 'master' of git://repo.or.cz/git/fastimport
[git.git] / diff.c
diff --git a/diff.c b/diff.c
index acd689643cd625cbaa6589b82ac4117971f45211..aaab3095a5f44d5d835bda4bc60112481bf94ed9 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -545,6 +545,24 @@ static char *pprint_rename(const char *a, const char *b)
        int pfx_length, sfx_length;
        int len_a = strlen(a);
        int len_b = strlen(b);
+       int qlen_a = quote_c_style(a, NULL, NULL, 0);
+       int qlen_b = quote_c_style(b, NULL, NULL, 0);
+
+       if (qlen_a || qlen_b) {
+               if (qlen_a) len_a = qlen_a;
+               if (qlen_b) len_b = qlen_b;
+               name = xmalloc( len_a + len_b + 5 );
+               if (qlen_a)
+                       quote_c_style(a, name, NULL, 0);
+               else
+                       memcpy(name, a, len_a);
+               memcpy(name + len_a, " => ", 4);
+               if (qlen_b)
+                       quote_c_style(b, name + len_a + 4, NULL, 0);
+               else
+                       memcpy(name + len_a + 4, b, len_b + 1);
+               return name;
+       }
 
        /* Find common prefix */
        pfx_length = 0;
@@ -701,12 +719,14 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options)
                struct diffstat_file *file = data->files[i];
                int change = file->added + file->deleted;
 
-               len = quote_c_style(file->name, NULL, NULL, 0);
-               if (len) {
-                       char *qname = xmalloc(len + 1);
-                       quote_c_style(file->name, qname, NULL, 0);
-                       free(file->name);
-                       file->name = qname;
+               if (!file->is_renamed) {  /* renames are already quoted by pprint_rename */
+                       len = quote_c_style(file->name, NULL, NULL, 0);
+                       if (len) {
+                               char *qname = xmalloc(len + 1);
+                               quote_c_style(file->name, qname, NULL, 0);
+                               free(file->name);
+                               file->name = qname;
+                       }
                }
 
                len = strlen(file->name);
@@ -838,7 +858,7 @@ static void show_numstat(struct diffstat_t* data, struct diff_options *options)
                        printf("-\t-\t");
                else
                        printf("%d\t%d\t", file->added, file->deleted);
-               if (options->line_termination &&
+               if (options->line_termination && !file->is_renamed &&
                    quote_c_style(file->name, NULL, NULL, 0))
                        quote_c_style(file->name, NULL, stdout, 0);
                else
@@ -2409,19 +2429,24 @@ static void flush_one_pair(struct diff_filepair *p, struct diff_options *opt)
 
 static void show_file_mode_name(const char *newdelete, struct diff_filespec *fs)
 {
+       char *name = quote_one(fs->path);
        if (fs->mode)
-               printf(" %s mode %06o %s\n", newdelete, fs->mode, fs->path);
+               printf(" %s mode %06o %s\n", newdelete, fs->mode, name);
        else
-               printf(" %s %s\n", newdelete, fs->path);
+               printf(" %s %s\n", newdelete, name);
+       free(name);
 }
 
 
 static void show_mode_change(struct diff_filepair *p, int show_name)
 {
        if (p->one->mode && p->two->mode && p->one->mode != p->two->mode) {
-               if (show_name)
+               if (show_name) {
+                       char *name = quote_one(p->two->path);
                        printf(" mode change %06o => %06o %s\n",
-                              p->one->mode, p->two->mode, p->two->path);
+                              p->one->mode, p->two->mode, name);
+                       free(name);
+               }
                else
                        printf(" mode change %06o => %06o\n",
                               p->one->mode, p->two->mode);
@@ -2455,8 +2480,10 @@ static void diff_summary(struct diff_filepair *p)
                break;
        default:
                if (p->score) {
-                       printf(" rewrite %s (%d%%)\n", p->two->path,
+                       char *name = quote_one(p->two->path);
+                       printf(" rewrite %s (%d%%)\n", name,
                                (int)(0.5 + p->score * 100.0/MAX_SCORE));
+                       free(name);
                        show_mode_change(p, 0);
                } else  show_mode_change(p, 1);
                break;