Skip to content

Commit 5701115

Browse files
Sven Verdoolaegegitster
authored andcommitted
git-diff: don't squelch the new SHA1 in submodule diffs
The code to squelch empty diffs introduced by commit fb13227 would inadvertently populate filespec "two" of a submodule change using the uninitialized (null) SHA1, thereby replacing the submodule SHA1 by 0{40} in the output. This change teaches diffcore_skip_stat_unmatch to handle submodule changes correctly. Signed-off-by: Sven Verdoolaege <skimo@kotnet.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent a51cdb0 commit 5701115

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

diff.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,6 +3144,22 @@ static void diffcore_apply_filter(const char *filter)
31443144
*q = outq;
31453145
}
31463146

3147+
/* Check whether two filespecs with the same mode and size are identical */
3148+
static int diff_filespec_is_identical(struct diff_filespec *one,
3149+
struct diff_filespec *two)
3150+
{
3151+
if (S_ISGITLINK(one->mode)) {
3152+
diff_fill_sha1_info(one);
3153+
diff_fill_sha1_info(two);
3154+
return !hashcmp(one->sha1, two->sha1);
3155+
}
3156+
if (diff_populate_filespec(one, 0))
3157+
return 0;
3158+
if (diff_populate_filespec(two, 0))
3159+
return 0;
3160+
return !memcmp(one->data, two->data, one->size);
3161+
}
3162+
31473163
static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)
31483164
{
31493165
int i;
@@ -3175,10 +3191,7 @@ static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)
31753191
diff_populate_filespec(p->one, 1) ||
31763192
diff_populate_filespec(p->two, 1) ||
31773193
(p->one->size != p->two->size) ||
3178-
3179-
diff_populate_filespec(p->one, 0) || /* (2) */
3180-
diff_populate_filespec(p->two, 0) ||
3181-
memcmp(p->one->data, p->two->data, p->one->size))
3194+
!diff_filespec_is_identical(p->one, p->two)) /* (2) */
31823195
diff_q(&outq, p);
31833196
else {
31843197
/*

t/t7400-submodule-basic.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ test_expect_success 'the --cached sha1 should be rev1' '
152152
git-submodule --cached status | grep "^+$rev1"
153153
'
154154

155+
test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
156+
git-diff | grep "^+Subproject commit $rev2"
157+
'
158+
155159
test_expect_success 'update should checkout rev1' '
156160
git-submodule update &&
157161
head=$(cd lib && git rev-parse HEAD) &&

0 commit comments

Comments
 (0)