match-trees: use hashcpy to splice trees
[gitweb.git] / range-diff.c
index 014112ee401fda47c9f200393c44c372b010fcf4..48b0e1b4ce0ff69b9c7a430174db25b1ca6494f8 100644 (file)
@@ -38,6 +38,14 @@ static int read_patches(const char *range, struct string_list *list)
 
        argv_array_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
                        "--reverse", "--date-order", "--decorate=no",
+                       /*
+                        * Choose indicators that are not used anywhere
+                        * else in diffs, but still look reasonable
+                        * (e.g. will not be confusing when debugging)
+                        */
+                       "--output-indicator-new=>",
+                       "--output-indicator-old=<",
+                       "--output-indicator-context=#",
                        "--no-abbrev-commit", range,
                        NULL);
        cp.out = -1;
@@ -82,6 +90,7 @@ static int read_patches(const char *range, struct string_list *list)
                        strbuf_addch(&buf, '\n');
                        if (!util->diff_offset)
                                util->diff_offset = buf.len;
+                       strbuf_addch(&buf, ' ');
                        strbuf_addbuf(&buf, &line);
                } else if (in_header) {
                        if (starts_with(line.buf, "Author: ")) {
@@ -108,8 +117,19 @@ static int read_patches(const char *range, struct string_list *list)
                         * we are not interested.
                         */
                        continue;
-               else
+               else if (line.buf[0] == '>') {
+                       strbuf_addch(&buf, '+');
+                       strbuf_add(&buf, line.buf + 1, line.len - 1);
+               } else if (line.buf[0] == '<') {
+                       strbuf_addch(&buf, '-');
+                       strbuf_add(&buf, line.buf + 1, line.len - 1);
+               } else if (line.buf[0] == '#') {
+                       strbuf_addch(&buf, ' ');
+                       strbuf_add(&buf, line.buf + 1, line.len - 1);
+               } else {
+                       strbuf_addch(&buf, ' ');
                        strbuf_addbuf(&buf, &line);
+               }
 
                strbuf_addch(&buf, '\n');
                util->diffsize++;
@@ -177,6 +197,12 @@ static void diffsize_consume(void *data, char *line, unsigned long len)
        (*(int *)data)++;
 }
 
+static void diffsize_hunk(void *data, long ob, long on, long nb, long nn,
+                         const char *funcline, long funclen)
+{
+       diffsize_consume(data, NULL, 0);
+}
+
 static int diffsize(const char *a, const char *b)
 {
        xpparam_t pp = { 0 };
@@ -190,7 +216,9 @@ static int diffsize(const char *a, const char *b)
        mf2.size = strlen(b);
 
        cfg.ctxlen = 3;
-       if (!xdi_diff_outf(&mf1, &mf2, diffsize_consume, &count, &pp, &cfg))
+       if (!xdi_diff_outf(&mf1, &mf2,
+                          diffsize_hunk, diffsize_consume, &count,
+                          &pp, &cfg))
                return count;
 
        error(_("failed to generate diff"));
@@ -334,7 +362,7 @@ static struct diff_filespec *get_filespec(const char *name, const char *p)
 {
        struct diff_filespec *spec = alloc_filespec(name);
 
-       fill_filespec(spec, &null_oid, 0, 0644);
+       fill_filespec(spec, &null_oid, 0, 0100644);
        spec->data = (char *)p;
        spec->size = strlen(p);
        spec->should_munmap = 0;
@@ -432,7 +460,11 @@ int show_range_diff(const char *range1, const char *range2,
                struct diff_options opts;
                struct strbuf indent = STRBUF_INIT;
 
-               memcpy(&opts, diffopt, sizeof(opts));
+               if (diffopt)
+                       memcpy(&opts, diffopt, sizeof(opts));
+               else
+                       diff_setup(&opts);
+
                if (!opts.output_format)
                        opts.output_format = DIFF_FORMAT_PATCH;
                opts.flags.suppress_diff_headers = 1;