Code

Prettify log decorations even more
[git.git] / combine-diff.c
index f617e9ded6b7ff2bb7a8d3629480c2ad22667428..60d03676bbd0dba7be79c7098d7cae553962ca98 100644 (file)
@@ -24,7 +24,7 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
                        path = q->queue[i]->two->path;
                        len = strlen(path);
                        p = xmalloc(combine_diff_path_size(num_parent, len));
-                       p->path = (char*) &(p->parent[num_parent]);
+                       p->path = (char *) &(p->parent[num_parent]);
                        memcpy(p->path, path, len);
                        p->path[len] = 0;
                        p->len = len;
@@ -150,8 +150,6 @@ static void append_lost(struct sline *sline, int n, const char *line, int len)
 }
 
 struct combine_diff_state {
-       struct xdiff_emit_state xm;
-
        unsigned int lno;
        int ob, on, nb, nn;
        unsigned long nmask;
@@ -223,19 +221,18 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
 
        parent_file.ptr = grab_blob(parent, mode, &sz);
        parent_file.size = sz;
+       memset(&xpp, 0, sizeof(xpp));
        xpp.flags = XDF_NEED_MINIMAL;
        memset(&xecfg, 0, sizeof(xecfg));
-       ecb.outf = xdiff_outf;
-       ecb.priv = &state;
        memset(&state, 0, sizeof(state));
-       state.xm.consume = consume_line;
        state.nmask = nmask;
        state.sline = sline;
        state.lno = 1;
        state.num_parent = num_parent;
        state.n = n;
 
-       xdi_diff(&parent_file, result_file, &xpp, &xecfg, &ecb);
+       xdi_diff_outf(&parent_file, result_file, consume_line, &state,
+                     &xpp, &xecfg, &ecb);
        free(parent_file.ptr);
 
        /* Assign line numbers for this parent.
@@ -537,7 +534,6 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
                return; /* result deleted */
 
        while (1) {
-               struct sline *sl = &sline[lno];
                unsigned long hunk_end;
                unsigned long rlines;
                const char *hunk_comment = NULL;
@@ -603,7 +599,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
                        struct lline *ll;
                        int j;
                        unsigned long p_mask;
-                       sl = &sline[lno++];
+                       struct sline *sl = &sline[lno++];
                        ll = (sl->flag & no_pre_delete) ? NULL : sl->lost_head;
                        while (ll) {
                                fputs(c_old, stdout);
@@ -695,9 +691,13 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
        int i, show_hunks;
        int working_tree_file = is_null_sha1(elem->sha1);
        int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? 40 : DEFAULT_ABBREV;
+       const char *a_prefix, *b_prefix;
        mmfile_t result_file;
 
        context = opt->context;
+       a_prefix = opt->a_prefix ? opt->a_prefix : "a/";
+       b_prefix = opt->b_prefix ? opt->b_prefix : "b/";
+
        /* Read the result of merge first */
        if (!working_tree_file)
                result = grab_blob(elem->sha1, elem->mode, &result_size);
@@ -710,15 +710,15 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
                        goto deleted_file;
 
                if (S_ISLNK(st.st_mode)) {
-                       size_t len = xsize_t(st.st_size);
-                       result_size = len;
-                       result = xmalloc(len + 1);
-                       if (result_size != readlink(elem->path, result, len)) {
+                       struct strbuf buf = STRBUF_INIT;
+
+                       if (strbuf_readlink(&buf, elem->path, st.st_size) < 0) {
                                error("readlink(%s): %s", elem->path,
                                      strerror(errno));
                                return;
                        }
-                       result[len] = 0;
+                       result_size = buf.len;
+                       result = strbuf_detach(&buf, NULL);
                        elem->mode = canon_mode(st.st_mode);
                } else if (S_ISDIR(st.st_mode)) {
                        unsigned char sha1[20];
@@ -754,9 +754,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
 
                        /* If not a fake symlink, apply filters, e.g. autocrlf */
                        if (is_file) {
-                               struct strbuf buf;
+                               struct strbuf buf = STRBUF_INIT;
 
-                               strbuf_init(&buf, 0);
                                if (convert_to_git(elem->path, result, len, &buf, safe_crlf)) {
                                        free(result);
                                        result = strbuf_detach(&buf, &len);
@@ -879,13 +878,13 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
                        dump_quoted_path("--- ", "", "/dev/null",
                                         c_meta, c_reset);
                else
-                       dump_quoted_path("--- ", opt->a_prefix, elem->path,
+                       dump_quoted_path("--- ", a_prefix, elem->path,
                                         c_meta, c_reset);
                if (deleted)
                        dump_quoted_path("+++ ", "", "/dev/null",
                                         c_meta, c_reset);
                else
-                       dump_quoted_path("+++ ", opt->b_prefix, elem->path,
+                       dump_quoted_path("+++ ", b_prefix, elem->path,
                                         c_meta, c_reset);
                dump_sline(sline, cnt, num_parent,
                           DIFF_OPT_TST(opt, COLOR_DIFF));
@@ -1064,7 +1063,7 @@ void diff_tree_combined_merge(const unsigned char *sha1,
        for (parents = commit->parents, num_parent = 0;
             parents;
             parents = parents->next, num_parent++)
-               hashcpy((unsigned char*)(parent + num_parent),
+               hashcpy((unsigned char *)(parent + num_parent),
                        parents->item->object.sha1);
        diff_tree_combined(sha1, parent, num_parent, dense, rev);
 }