]> asedeno.scripts.mit.edu Git - git.git/blobdiff - combine-diff.c
Merge branch 'maint'
[git.git] / combine-diff.c
index e22db8993286a3b3654865d765c9e98f3604b44a..41aaf83dd315746ae26d1c31ddd78b43c0cb6663 100644 (file)
@@ -646,12 +646,19 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
        sline->p_lno[i] = sline->p_lno[j];
 }
 
-static void dump_quoted_path(const char *prefix, const char *path,
+static void dump_quoted_path(const char *head,
+                            const char *prefix,
+                            const char *path,
                             const char *c_meta, const char *c_reset)
 {
-       printf("%s%s", c_meta, prefix);
-       quote_c_style(path, NULL, stdout, 0);
-       printf("%s\n", c_reset);
+       static struct strbuf buf = STRBUF_INIT;
+
+       strbuf_reset(&buf);
+       strbuf_addstr(&buf, c_meta);
+       strbuf_addstr(&buf, head);
+       quote_two_c_style(&buf, prefix, path, 0);
+       strbuf_addstr(&buf, c_reset);
+       puts(buf.buf);
 }
 
 static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
@@ -711,9 +718,9 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
                        result = xmalloc(len + 1);
                        while (sz < len) {
                                ssize_t done = xread(fd, result+sz, len-sz);
-                               if (done == 0)
-                                       break;
-                               if (done < 0)
+                               if (done == 0 && sz != len)
+                                       die("early EOF '%s'", elem->path);
+                               else if (done < 0)
                                        die("read error '%s'", elem->path);
                                sz += done;
                        }
@@ -791,9 +798,9 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
                int deleted = 0;
 
                if (rev->loginfo && !rev->no_commit_id)
-                       show_log(rev, opt->msg_sep);
+                       show_log(rev);
                dump_quoted_path(dense ? "diff --cc " : "diff --combined ",
-                                elem->path, c_meta, c_reset);
+                                "", elem->path, c_meta, c_reset);
                printf("%sindex ", c_meta);
                for (i = 0; i < num_parent; i++) {
                        abb = find_unique_abbrev(elem->parent[i].sha1,
@@ -829,14 +836,19 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
                        printf("%s\n", c_reset);
                }
                if (added)
-                       dump_quoted_path("--- /dev/", "null", c_meta, c_reset);
+                       dump_quoted_path("--- ", "", "/dev/null",
+                                        c_meta, c_reset);
                else
-                       dump_quoted_path("--- a/", elem->path, c_meta, c_reset);
+                       dump_quoted_path("--- ", opt->a_prefix, elem->path,
+                                        c_meta, c_reset);
                if (deleted)
-                       dump_quoted_path("+++ /dev/", "null", c_meta, c_reset);
+                       dump_quoted_path("+++ ", "", "/dev/null",
+                                        c_meta, c_reset);
                else
-                       dump_quoted_path("+++ b/", elem->path, c_meta, c_reset);
-               dump_sline(sline, cnt, num_parent, DIFF_OPT_TST(opt, COLOR_DIFF));
+                       dump_quoted_path("+++ ", opt->b_prefix, elem->path,
+                                        c_meta, c_reset);
+               dump_sline(sline, cnt, num_parent,
+                          DIFF_OPT_TST(opt, COLOR_DIFF));
        }
        free(result);
 
@@ -869,7 +881,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
                inter_name_termination = 0;
 
        if (rev->loginfo && !rev->no_commit_id)
-               show_log(rev, opt->msg_sep);
+               show_log(rev);
 
        if (opt->output_format & DIFF_FORMAT_RAW) {
                offset = strlen(COLONS) - num_parent;
@@ -950,7 +962,7 @@ void diff_tree_combined(const unsigned char *sha1,
                paths = intersect_paths(paths, i, num_parent);
 
                if (show_log_first && i == 0) {
-                       show_log(rev, opt->msg_sep);
+                       show_log(rev);
                        if (rev->verbose_header && opt->output_format)
                                putchar(opt->line_termination);
                }