{"thread":{"id":"9830","subject":"[PATCH] git-diff: don't squelch the new SHA1 in submodule diffs","startedAt":"2007-09-08T10:30:22Z","lastAt":"2007-09-09T00:18:43Z","messageCount":2,"participants":["Sven Verdoolaege","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"52987","messageId":"20070908103022.GA15229MdfPADPa@greensroom.kotnet.org","threadId":"9830","inReplyTo":null,"subject":"[PATCH] git-diff: don't squelch the new SHA1 in submodule diffs","fromName":"Sven Verdoolaege","fromEmail":"skimo@kotnet.org","sentAt":"2007-09-08T10:30:22Z","receivedAt":"2007-09-08T10:30:22Z","isPatch":true,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"The code to squelch empty diffs introduced by commit\nfb13227e089f22dc31a3b1624559153821056848 would inadvertently\npopulate filespec \"two\" of a submodule change using the uninitialized\n(null) SHA1, thereby replacing the submodule SHA1 by 0{40} in the output.\n\nThis change teaches diffcore_skip_stat_unmatch to handle\nsubmodule changes correctly.\n\nSigned-off-by: Sven Verdoolaege <skimo@kotnet.org>\n---\n diff.c                     |   21 +++++++++++++++++----\n t/t7400-submodule-basic.sh |    4 ++++\n 2 files changed, 21 insertions(+), 4 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 0d30d05..1aca5df 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3144,6 +3144,22 @@ static void diffcore_apply_filter(const char *filter)\n \t*q = outq;\n }\n \n+/* Check whether two filespecs with the same mode and size are identical */\n+static int diff_filespec_is_identical(struct diff_filespec *one,\n+\t\t\t\t      struct diff_filespec *two)\n+{\n+\tif (S_ISGITLINK(one->mode)) {\n+\t\tdiff_fill_sha1_info(one);\n+\t\tdiff_fill_sha1_info(two);\n+\t\treturn !hashcmp(one->sha1, two->sha1);\n+\t}\n+\tif (diff_populate_filespec(one, 0))\n+\t\treturn 0;\n+\tif (diff_populate_filespec(two, 0))\n+\t\treturn 0;\n+\treturn !memcmp(one->data, two->data, one->size);\n+}\n+\n static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)\n {\n \tint i;\n@@ -3175,10 +3191,7 @@ static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)\n \t\t    diff_populate_filespec(p->one, 1) ||\n \t\t    diff_populate_filespec(p->two, 1) ||\n \t\t    (p->one->size != p->two->size) ||\n-\n-\t\t    diff_populate_filespec(p->one, 0) || /* (2) */\n-\t\t    diff_populate_filespec(p->two, 0) ||\n-\t\t    memcmp(p->one->data, p->two->data, p->one->size))\n+\t\t    !diff_filespec_is_identical(p->one, p->two)) /* (2) */\n \t\t\tdiff_q(&outq, p);\n \t\telse {\n \t\t\t/*\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 9d142ed..4fe3a41 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -152,6 +152,10 @@ test_expect_success 'the --cached sha1 should be rev1' '\n \tgit-submodule --cached status | grep \"^+$rev1\"\n '\n \n+test_expect_success 'git diff should report the SHA1 of the new submodule commit' '\n+\tgit-diff | grep \"^+Subproject commit $rev2\"\n+'\n+\n test_expect_success 'update should checkout rev1' '\n \tgit-submodule update &&\n \thead=$(cd lib && git rev-parse HEAD) &&\n-- \n1.5.3.1.20.g3d038\n"},{"id":"53033","messageId":"Pine.LNX.4.64.0709090117331.28586@racer.site","threadId":"9830","inReplyTo":"20070908103022.GA15229MdfPADPa@greensroom.kotnet.org","subject":"Re: [PATCH] git-diff: don't squelch the new SHA1 in submodule diffs","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-09-09T00:18:43Z","receivedAt":"2007-09-09T00:18:43Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 8 Sep 2007, Sven Verdoolaege wrote:\n\n> The code to squelch empty diffs introduced by commit\n> fb13227e089f22dc31a3b1624559153821056848 would inadvertently\n> populate filespec \"two\" of a submodule change using the uninitialized\n> (null) SHA1, thereby replacing the submodule SHA1 by 0{40} in the output.\n> \n> This change teaches diffcore_skip_stat_unmatch to handle\n> submodule changes correctly.\n\nAh, I was wondering... This struck me as odd in msysGit, but I did not \nknow if it was a problem I introduced in 4msysgit or not.  Unfortunately, \nI did not have the time to investigate further.\n\nThanks,\nDscho\n"}]}