summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/range-diff.c31
-rw-r--r--range-diff.c34
-rw-r--r--range-diff.h4
3 files changed, 63 insertions, 6 deletions
diff --git a/builtin/range-diff.c b/builtin/range-diff.c
index 94c1f362cc..3b06ed9449 100644
--- a/builtin/range-diff.c
+++ b/builtin/range-diff.c
@@ -2,6 +2,7 @@
#include "builtin.h"
#include "parse-options.h"
#include "range-diff.h"
+#include "config.h"
static const char * const builtin_range_diff_usage[] = {
N_("git range-diff [<options>] <old-base>..<old-tip> <new-base>..<new-tip>"),
@@ -13,15 +14,40 @@ NULL
int cmd_range_diff(int argc, const char **argv, const char *prefix)
{
int creation_factor = 60;
+ struct diff_options diffopt = { NULL };
struct option options[] = {
OPT_INTEGER(0, "creation-factor", &creation_factor,
N_("Percentage by which creation is weighted")),
OPT_END()
};
- int res = 0;
+ int i, j, res = 0;
struct strbuf range1 = STRBUF_INIT, range2 = STRBUF_INIT;
+ git_config(git_diff_ui_config, NULL);
+
+ diff_setup(&diffopt);
+ diffopt.output_format = DIFF_FORMAT_PATCH;
+
argc = parse_options(argc, argv, NULL, options,
+ builtin_range_diff_usage, PARSE_OPT_KEEP_UNKNOWN |
+ PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
+
+ for (i = j = 1; i < argc && strcmp("--", argv[i]); ) {
+ int c = diff_opt_parse(&diffopt, argv + i, argc - i, prefix);
+
+ if (!c)
+ argv[j++] = argv[i++];
+ else
+ i += c;
+ }
+ while (i < argc)
+ argv[j++] = argv[i++];
+ argc = j;
+ diff_setup_done(&diffopt);
+
+ /* Make sure that there are no unparsed options */
+ argc = parse_options(argc, argv, NULL,
+ options + ARRAY_SIZE(options) - 1, /* OPT_END */
builtin_range_diff_usage, 0);
if (argc == 2) {
@@ -59,7 +85,8 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
usage_with_options(builtin_range_diff_usage, options);
}
- res = show_range_diff(range1.buf, range2.buf, creation_factor);
+ res = show_range_diff(range1.buf, range2.buf, creation_factor,
+ &diffopt);
strbuf_release(&range1);
strbuf_release(&range2);
diff --git a/range-diff.c b/range-diff.c
index 2d94200d30..71883a4b7d 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -6,6 +6,7 @@
#include "hashmap.h"
#include "xdiff-interface.h"
#include "linear-assignment.h"
+#include "diffcore.h"
struct patch_util {
/* For the search for an exact match */
@@ -258,7 +259,31 @@ static const char *short_oid(struct patch_util *util)
return find_unique_abbrev(&util->oid, DEFAULT_ABBREV);
}
-static void output(struct string_list *a, struct string_list *b)
+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);
+ spec->data = (char *)p;
+ spec->size = strlen(p);
+ spec->should_munmap = 0;
+ spec->is_stdin = 1;
+
+ return spec;
+}
+
+static void patch_diff(const char *a, const char *b,
+ struct diff_options *diffopt)
+{
+ diff_queue(&diff_queued_diff,
+ get_filespec("a", a), get_filespec("b", b));
+
+ diffcore_std(diffopt);
+ diff_flush(diffopt);
+}
+
+static void output(struct string_list *a, struct string_list *b,
+ struct diff_options *diffopt)
{
int i = 0, j = 0;
@@ -300,6 +325,9 @@ static void output(struct string_list *a, struct string_list *b)
printf("%d: %s ! %d: %s\n",
b_util->matching + 1, short_oid(a_util),
j + 1, short_oid(b_util));
+ if (!(diffopt->output_format & DIFF_FORMAT_NO_OUTPUT))
+ patch_diff(a->items[b_util->matching].string,
+ b->items[j].string, diffopt);
a_util->shown = 1;
j++;
}
@@ -307,7 +335,7 @@ static void output(struct string_list *a, struct string_list *b)
}
int show_range_diff(const char *range1, const char *range2,
- int creation_factor)
+ int creation_factor, struct diff_options *diffopt)
{
int res = 0;
@@ -322,7 +350,7 @@ int show_range_diff(const char *range1, const char *range2,
if (!res) {
find_exact_matches(&branch1, &branch2);
get_correspondences(&branch1, &branch2, creation_factor);
- output(&branch1, &branch2);
+ output(&branch1, &branch2, diffopt);
}
string_list_clear(&branch1, 1);
diff --git a/range-diff.h b/range-diff.h
index 7b6eef303f..2407d46a30 100644
--- a/range-diff.h
+++ b/range-diff.h
@@ -1,7 +1,9 @@
#ifndef RANGE_DIFF_H
#define RANGE_DIFF_H
+#include "diff.h"
+
int show_range_diff(const char *range1, const char *range2,
- int creation_factor);
+ int creation_factor, struct diff_options *diffopt);
#endif