range-diff: allow to diff files regardless of submodule config

If we have `submodule.diff = log' in the configuration file or `--submodule=log' is given as argument, range-diff fails to compare both diffs and we only get the following output: Submodule a 0000000...0000000 (new submodule) Even if the repository doesn't have any submodule. That's because the mode in diff_filespec is not correct and when flushing the diff, down in builtin_diff() we will enter the condition: if (o->submodule_format == DIFF_SUBMODULE_LOG && (!one->mode || S_ISGITLINK(one->mode)) && (!two->mode || S_ISGITLINK(two->mode))) { show_submodule_summary(o, one->path ? one->path : two->path, &one->oid, &two->oid, two->dirty_submodule); return; It turns out that S_ISGITLINK will return true (mode == 0160000 here). Similar thing happens if submodule.diff is "diff". Do like it's done in grep.c when calling fill_filespec() and force it to be recognized as a file by adding S_IFREG to the mode. Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com> Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lucas De Marchi committed Oct 24, 2018 at 12:46 UTC 0e573e8fcc395b5249c1c4713c2e385893c98b8c
2 files changed +30 -1
range-diff.c
+1 -1
@@ -354,7 +354,7 @@ static struct diff_filespec *get_filespec(const char *name, const char *p)
354 {
355 struct diff_filespec *spec = alloc_filespec(name);
356
357 - fill_filespec(spec, &null_oid, 0, 0644);
357 + fill_filespec(spec, &null_oid, 0, 0100644);
358 spec->data = (char *)p;
359 spec->size = strlen(p);
360 spec->should_munmap = 0;
t/t3206-range-diff.sh
+29
@@ -122,6 +122,35 @@ test_expect_success 'changed commit' '
122 test_cmp expected actual
123 '
124
125 +test_expect_success 'changed commit with sm config' '
126 + git range-diff --no-color --submodule=log topic...changed >actual &&
127 + cat >expected <<-EOF &&
128 + 1: 4de457d = 1: a4b3333 s/5/A/
129 + 2: fccce22 = 2: f51d370 s/4/A/
130 + 3: 147e64e ! 3: 0559556 s/11/B/
131 + @@ -10,7 +10,7 @@
132 + 9
133 + 10
134 + -11
135 + -+B
136 + ++BB
137 + 12
138 + 13
139 + 14
140 + 4: a63e992 ! 4: d966c5c s/12/B/
141 + @@ -8,7 +8,7 @@
142 + @@
143 + 9
144 + 10
145 + - B
146 + + BB
147 + -12
148 + +B
149 + 13
150 + EOF
151 + test_cmp expected actual
152 +'
153 +
154 test_expect_success 'no commits on one side' '
155 git commit --amend -m "new message" &&
156 git range-diff master HEAD@{1} HEAD