Skip to content

Commit

Permalink
git-diff: don't squelch the new SHA1 in submodule diffs
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Sven Verdoolaege authored and Junio C Hamano committed Sep 9, 2007
1 parent a51cdb0 commit 5701115
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 17 additions & 4 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -3144,6 +3144,22 @@ static void diffcore_apply_filter(const char *filter)
*q = outq;
}

/* Check whether two filespecs with the same mode and size are identical */
static int diff_filespec_is_identical(struct diff_filespec *one,
struct diff_filespec *two)
{
if (S_ISGITLINK(one->mode)) {
diff_fill_sha1_info(one);
diff_fill_sha1_info(two);
return !hashcmp(one->sha1, two->sha1);
}
if (diff_populate_filespec(one, 0))
return 0;
if (diff_populate_filespec(two, 0))
return 0;
return !memcmp(one->data, two->data, one->size);
}

static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)
{
int i;
Expand Down Expand Up @@ -3175,10 +3191,7 @@ static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)
diff_populate_filespec(p->one, 1) ||
diff_populate_filespec(p->two, 1) ||
(p->one->size != p->two->size) ||

diff_populate_filespec(p->one, 0) || /* (2) */
diff_populate_filespec(p->two, 0) ||
memcmp(p->one->data, p->two->data, p->one->size))
!diff_filespec_is_identical(p->one, p->two)) /* (2) */
diff_q(&outq, p);
else {
/*
Expand Down
4 changes: 4 additions & 0 deletions t/t7400-submodule-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ test_expect_success 'the --cached sha1 should be rev1' '
git-submodule --cached status | grep "^+$rev1"
'

test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
git-diff | grep "^+Subproject commit $rev2"
'

test_expect_success 'update should checkout rev1' '
git-submodule update &&
head=$(cd lib && git rev-parse HEAD) &&
Expand Down

0 comments on commit 5701115

Please sign in to comment.