summaryrefslogtreecommitdiff
path: root/range-diff.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2018-08-13 11:33:07 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-08-13 17:44:50 (GMT)
commitc8c5e43ac3f9a5b785faf16f10bb8e2c493606a4 (patch)
tree1e7bb98b5729f1649e096e57957c1bc54d70a715 /range-diff.c
parent9dc46e0268028059aecd140254bfe30277d04767 (diff)
downloadgit-c8c5e43ac3f9a5b785faf16f10bb8e2c493606a4.zip
git-c8c5e43ac3f9a5b785faf16f10bb8e2c493606a4.tar.gz
git-c8c5e43ac3f9a5b785faf16f10bb8e2c493606a4.tar.bz2
range-diff: also show the diff between patches
Just like tbdiff, we now show the diff between matching patches. This is a "diff of two diffs", so it can be a bit daunting to read for the beginner. An alternative would be to display an interdiff, i.e. the hypothetical diff which is the result of first reverting the old diff and then applying the new diff. Especially when rebasing frequently, an interdiff is often not feasible, though: if the old diff cannot be applied in reverse (due to a moving upstream), an interdiff can simply not be inferred. This commit brings `range-diff` closer to feature parity with regard to tbdiff. To make `git range-diff` respect e.g. color.diff.* settings, we have to adjust git_branch_config() accordingly. Note: while we now parse diff options such as --color, the effect is not yet the same as in tbdiff, where also the commit pairs would be colored. This is left for a later commit. Note also: while tbdiff accepts the `--no-patches` option to suppress these diffs between patches, we prefer the `-s` (or `--no-patch`) option that is automatically supported via our use of diff_opt_parse(). And finally note: to support diff options, we have to call `parse_options()` such that it keeps unknown options, and then loop over those and let `diff_opt_parse()` handle them. After that loop, we have to call `parse_options()` again, to make sure that no unknown options are left. Helped-by: Thomas Gummerer <t.gummerer@gmail.com> Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'range-diff.c')
-rw-r--r--range-diff.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/range-diff.c b/range-diff.c
index 2d94200..71883a4 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);