{"thread":{"id":"53961","subject":"[PATCH] diff: teach --stat to ignore uninteresting modifications","startedAt":"2020-08-01T23:33:21Z","lastAt":"2020-08-20T00:56:32Z","messageCount":9,"participants":["Matthew Rogers via GitGitGadget","Junio C Hamano","Matt Rogers"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"402628","messageId":"pull.689.git.1596324796918.gitgitgadget@gmail.com","threadId":"53961","inReplyTo":null,"subject":"[PATCH] diff: teach --stat to ignore uninteresting modifications","fromName":"Matthew Rogers via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-08-01T23:33:16Z","receivedAt":"2020-08-01T23:33:21Z","isPatch":true,"sender":{"key":"name:Matthew Rogers","avatar":null},"body":"From: Matthew Rogers <mattr94@gmail.com>\n\nSometimes when diffing, files may show as being momdified even when\nthere are no interesting diffs to show.  This happens naturally when\nusing options such as --ignore-space-change.  We don't want to prevent\nthe display  of all files that have 0 effective diffs since they could\nbe the result of a rename, permission change, or other similar operation\nthat may still be of interest so we special case additions and deletions\nas they are always interesting.\n\nSigned-off-by: Matthew Rogers <mattr94@gmail.com>\n---\n    diff: teach --stat to ignore uninteresting modifications\n    \n    This patch is based on the discussion these email threads:\n    \n    https://lore.kernel.org/git/1484704915.2096.16.camel@mattmccutchen.net/\n    https://lore.kernel.org/git/CAOjrSZtQPQ8Xxuz+7SGykR8Q-gFDEZANSE5yQASqKjpbUAq_5Q@mail.gmail.com/\n    \n    With the code mostly taken from this specific message:\n    https://lore.kernel.org/git/20170118111705.6bqzkklluikda3r5@sigill.intra.peff.net/\n    \n    The summary is that when running git diff --stat in combination with\n    --ignore-all-space or similar options, you'll see many lines of the\n    form:\n    \n    some-file.txt | 0\n    \n    which can be misleading when you are explicitly telling git to \"ignore\n    all space\" or something similar. To rectify this issue, this patch\n    categorizes all files that are modified but have no effective changes as\n    not fit to display to the user.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-689%2FROGERSM94%2Fzero-diffs-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-689/ROGERSM94/zero-diffs-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/689\n\n diff.c                     | 36 +++++++++++++++++++++++++++++-------\n t/t4015-diff-whitespace.sh |  8 +++++++-\n 2 files changed, 36 insertions(+), 8 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex d24aaa3047..9868f82ece 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3153,16 +3153,19 @@ static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *o\n \tgather_dirstat(options, &dir, changed, \"\", 0);\n }\n \n+static void free_diffstat_file(struct diffstat_file *f)\n+{\n+\tfree(f->print_name);\n+\tfree(f->name);\n+\tfree(f->from_name);\n+\tfree(f);\n+}\n+\n void free_diffstat_info(struct diffstat_t *diffstat)\n {\n \tint i;\n-\tfor (i = 0; i < diffstat->nr; i++) {\n-\t\tstruct diffstat_file *f = diffstat->files[i];\n-\t\tfree(f->print_name);\n-\t\tfree(f->name);\n-\t\tfree(f->from_name);\n-\t\tfree(f);\n-\t}\n+\tfor (i = 0; i < diffstat->nr; i++)\n+\t\tfree_diffstat_file(diffstat->files[i]);\n \tfree(diffstat->files);\n }\n \n@@ -3718,6 +3721,25 @@ static void builtin_diffstat(const char *name_a, const char *name_b,\n \t\tif (xdi_diff_outf(&mf1, &mf2, discard_hunk_line,\n \t\t\t\t  diffstat_consume, diffstat, &xpp, &xecfg))\n \t\t\tdie(\"unable to generate diffstat for %s\", one->path);\n+\n+\t\tif (DIFF_FILE_VALID(one) && DIFF_FILE_VALID(two)) {\n+\t\t\tstruct diffstat_file *file = \n+\t\t\t\tdiffstat->files[diffstat->nr - 1];\n+\t\t\t/*\n+\t\t\t * Omit diffstats of modified files where nothing changed. \n+\t\t\t * Even if !same_contents, this might be the case due to\n+\t\t\t * ignoring whitespace changes, etc.\n+\t\t\t * \n+\t\t\t * But note that we special-case additions and deletions,\n+\t\t\t * as adding an empty file, for example is still of interest.\n+\t\t\t */\n+\t\t\tif (p->status == DIFF_STATUS_MODIFIED \n+\t\t\t\t&& !file->added\n+\t\t\t\t&& !file->deleted) {\n+\t\t\t\tfree_diffstat_file(file);\n+\t\t\t\tdiffstat->nr--;\n+\t\t\t}\n+\t\t}\n \t}\n \n \tdiff_free_filespec_data(one);\ndiff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh\nindex 88d3026894..32c1b967f9 100755\n--- a/t/t4015-diff-whitespace.sh\n+++ b/t/t4015-diff-whitespace.sh\n@@ -789,7 +789,7 @@ test_expect_success 'checkdiff allows new blank lines' '\n \tgit diff --check\n '\n \n-test_expect_success 'whitespace-only changes not reported' '\n+test_expect_success 'whitespace-only changes not reported (diff)' '\n \tgit reset --hard &&\n \techo >x \"hello world\" &&\n \tgit add x &&\n@@ -799,6 +799,12 @@ test_expect_success 'whitespace-only changes not reported' '\n \ttest_must_be_empty actual\n '\n \n+test_expect_success 'whitespace-only changes not reported (diffstat)' '\n+\t# reuse state from previous test\n+\tgit diff --stat -b >actual &&\n+\ttest_must_be_empty actual\n+'\n+\n test_expect_success 'whitespace-only changes reported across renames' '\n \tgit reset --hard &&\n \tfor i in 1 2 3 4 5 6 7 8 9; do echo \"$i$i$i$i$i$i\"; done >x &&\n\nbase-commit: e8ab941b671da6890181aea5b5755d1d9eea24ec\n-- \ngitgitgadget\n"},{"id":"402629","messageId":"xmqqv9i128iq.fsf@gitster.c.googlers.com","threadId":"53961","inReplyTo":"pull.689.git.1596324796918.gitgitgadget@gmail.com","subject":"Re: [PATCH] diff: teach --stat to ignore uninteresting modifications","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-08-02T00:31:25Z","receivedAt":"2020-08-02T00:31:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Matthew Rogers via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> +\t\tif (DIFF_FILE_VALID(one) && DIFF_FILE_VALID(two)) {\n> +\t\t\tstruct diffstat_file *file = \n> +\t\t\t\tdiffstat->files[diffstat->nr - 1];\n> +\t\t\t/*\n> +\t\t\t * Omit diffstats of modified files where nothing changed. \n> +\t\t\t * Even if !same_contents, this might be the case due to\n> +\t\t\t * ignoring whitespace changes, etc.\n> +\t\t\t * \n> +\t\t\t * But note that we special-case additions and deletions,\n> +\t\t\t * as adding an empty file, for example is still of interest.\n> +\t\t\t */\n> +\t\t\tif (p->status == DIFF_STATUS_MODIFIED \n> +\t\t\t\t&& !file->added\n> +\t\t\t\t&& !file->deleted) {\n> +\t\t\t\tfree_diffstat_file(file);\n> +\t\t\t\tdiffstat->nr--;\n> +\t\t\t}\n> +\t\t}\n>  \t}\n> \n>  \tdiff_free_filespec_data(one);\n\nThere are some \"trailing whitespace\" errors detected by \"git am/apply\".\n\n> diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh\n> index 88d3026894..32c1b967f9 100755\n> --- a/t/t4015-diff-whitespace.sh\n> +++ b/t/t4015-diff-whitespace.sh\n> @@ -789,7 +789,7 @@ test_expect_success 'checkdiff allows new blank lines' '\n>  \tgit diff --check\n>  '\n>  \n> -test_expect_success 'whitespace-only changes not reported' '\n> +test_expect_success 'whitespace-only changes not reported (diff)' '\n>  \tgit reset --hard &&\n>  \techo >x \"hello world\" &&\n>  \tgit add x &&\n> @@ -799,6 +799,12 @@ test_expect_success 'whitespace-only changes not reported' '\n>  \ttest_must_be_empty actual\n>  '\n>  \n> +test_expect_success 'whitespace-only changes not reported (diffstat)' '\n> +\t# reuse state from previous test\n> +\tgit diff --stat -b >actual &&\n> +\ttest_must_be_empty actual\n> +'\n> +\n\nThis is a \"let's show off our shiny new toy\" test, which shows that\nthe code change covered the case you are interested in changing.\nWe'd also need tests that makes sure that the effect of the code\nchange is not seen when it should not trigger.\n\nFor example, if we further change mode bits of file 'x' (which has a\nwhitespace-only changes applied in the test in the previous hunk),\ne.g.\n\n\tgit update-index --chmod=+x x &&\n\tgit diff --stat -b --cached >actual\n\nshould that be counted as a file with 0-line change that is worth\nreporting, or is it hidden?  I _think_ the new code will do a wrong\nthing here.  That is,\n\n - If the change truly is only mode bits and one and two have\n   \"same_contents\", the new code is bypassed, and we'll continue to\n   show \"0 lines changed, but the file is worth reporting\".\n\n - If the change is whitespace-only change plus mode bits, i.e. one\n   and two do not have \"same_contents\", the new code triggers and\n   the stat output is suppressed for the path.\n\n\n\n"},{"id":"402634","messageId":"CAOjrSZtbEJ5-tnU497r8jE2PYWhKR1Qu14SZRnqceRnLMSheiQ@mail.gmail.com","threadId":"53961","inReplyTo":"xmqqv9i128iq.fsf@gitster.c.googlers.com","subject":"Re: [PATCH] diff: teach --stat to ignore uninteresting modifications","fromName":"Matt Rogers","fromEmail":"mattr94@gmail.com","sentAt":"2020-08-02T01:51:35Z","receivedAt":"2020-08-02T01:51:50Z","isPatch":true,"sender":{"key":"mattr94@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5719846?v=4"},"body":">\n> For example, if we further change mode bits of file 'x' (which has a\n> whitespace-only changes applied in the test in the previous hunk),\n> e.g.\n>\n>         git update-index --chmod=+x x &&\n>         git diff --stat -b --cached >actual\n>\n> should that be counted as a file with 0-line change that is worth\n> reporting, or is it hidden?  I _think_ the new code will do a wrong\n> thing here.  That is,\n>\n>  - If the change truly is only mode bits and one and two have\n>    \"same_contents\", the new code is bypassed, and we'll continue to\n>    show \"0 lines changed, but the file is worth reporting\".\n>\n\nThis first one is the behavior I was going for, I think it's most reasonable\n\n>  - If the change is whitespace-only change plus mode bits, i.e. one\n>    and two do not have \"same_contents\", the new code triggers and\n>    the stat output is suppressed for the path.\n>\n\nI just ran some tests on my end, and you're correct here, I'll try to come\nup with a reroll that addresses this and adds this as a test condition.\n\n-- \nMatthew Rogers\n"},{"id":"403731","messageId":"pull.689.v2.git.1597445151824.gitgitgadget@gmail.com","threadId":"53961","inReplyTo":"pull.689.git.1596324796918.gitgitgadget@gmail.com","subject":"[PATCH v2] diff: teach --stat to ignore uninteresting modifications","fromName":"Matthew Rogers via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-08-14T22:45:51Z","receivedAt":"2020-08-14T22:45:56Z","isPatch":true,"sender":{"key":"name:Matthew Rogers","avatar":null},"body":"From: Matthew Rogers <mattr94@gmail.com>\n\nSometimes when diffing, files may show as being momdified even when\nthere are no interesting diffs to show.  This happens naturally when\nusing options such as --ignore-space-change.  We don't want to prevent\nthe display  of all files that have 0 effective diffs since they could\nbe the result of a rename, permission change, or other similar operation\nthat may still be of interest so we special case additions and deletions\nas they are always interesting.\n\nSigned-off-by: Matthew Rogers <mattr94@gmail.com>\n---\n    diff: teach --stat to ignore uninteresting modifications\n    \n    This patch is based on the discussion these email threads:\n    \n    https://lore.kernel.org/git/1484704915.2096.16.camel@mattmccutchen.net/\n    https://lore.kernel.org/git/CAOjrSZtQPQ8Xxuz+7SGykR8Q-gFDEZANSE5yQASqKjpbUAq_5Q@mail.gmail.com/\n    \n    With the code mostly taken from this specific message:\n    https://lore.kernel.org/git/20170118111705.6bqzkklluikda3r5@sigill.intra.peff.net/\n    \n    The summary is that when running git diff --stat in combination with\n    --ignore-all-space or similar options, you'll see many lines of the\n    form:\n    \n    some-file.txt | 0\n    \n    which can be misleading when you are explicitly telling git to \"ignore\n    all space\" or something similar. To rectify this issue, this patch\n    categorizes all files that are modified but have no effective changes as\n    not fit to display to the user.\n    \n    New in V2:\n    \n     * I've added a test covering the rename case with whitespace-changes\n       and permissions changes\n     * I've also updated the logic in builtin_diffstat to include that logic\n       as well\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-689%2FROGERSM94%2Fzero-diffs-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-689/ROGERSM94/zero-diffs-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/689\n\nRange-diff vs v1:\n\n 1:  640c864ac4 ! 1:  6c5db18618 diff: teach --stat to ignore uninteresting modifications\n     @@ diff.c: static void builtin_diffstat(const char *name_a, const char *name_b,\n      +\t\t\t * But note that we special-case additions and deletions,\n      +\t\t\t * as adding an empty file, for example is still of interest.\n      +\t\t\t */\n     -+\t\t\tif (p->status == DIFF_STATUS_MODIFIED \n     ++\t\t\tif ((p->status == DIFF_STATUS_MODIFIED) \n      +\t\t\t\t&& !file->added\n     -+\t\t\t\t&& !file->deleted) {\n     ++\t\t\t\t&& !file->deleted\n     ++\t\t\t\t&& one->mode == two->mode) {\n      +\t\t\t\tfree_diffstat_file(file);\n      +\t\t\t\tdiffstat->nr--;\n      +\t\t\t}\n     @@ t/t4015-diff-whitespace.sh: test_expect_success 'whitespace-only changes not rep\n       \ttest_must_be_empty actual\n       '\n       \n     +-test_expect_success 'whitespace-only changes reported across renames' '\n      +test_expect_success 'whitespace-only changes not reported (diffstat)' '\n      +\t# reuse state from previous test\n      +\tgit diff --stat -b >actual &&\n      +\ttest_must_be_empty actual\n      +'\n      +\n     - test_expect_success 'whitespace-only changes reported across renames' '\n     ++test_expect_success 'whitespace changes with modification reported (diffstat)' '\n     ++\tgit reset --hard &&\n     ++\techo >x \"hello  world\" &&\n     ++\tgit update-index --chmod=+x x &&\n     ++\tgit diff --stat --cached -b >actual &&\n     ++\tcat <<-EOF >expect &&\n     ++\t x | 0\n     ++\t 1 file changed, 0 insertions(+), 0 deletions(-)\n     ++\tEOF\n     ++\ttest_cmp expect actual\n     ++'\n     ++\n     ++test_expect_success 'whitespace-only changes reported across renames (diffstat)' '\n       \tgit reset --hard &&\n       \tfor i in 1 2 3 4 5 6 7 8 9; do echo \"$i$i$i$i$i$i\"; done >x &&\n     + \tgit add x &&\n     ++\tgit commit -m \"base\" &&\n     ++\tsed -e \"5s/^/ /\" x >z &&\n     ++\tgit rm x &&\n     ++\tgit add z &&\n     ++\tgit diff -w -M --cached --stat >actual &&\n     ++\tcat <<-EOF >expect &&\n     ++\t x => z | 0\n     ++\t 1 file changed, 0 insertions(+), 0 deletions(-)\n     ++\tEOF\n     ++\ttest_cmp expect actual\n     ++'\n     ++\n     ++test_expect_success 'whitespace-only changes reported across renames' '\n     ++\tgit reset --hard HEAD~1 &&\n     ++\tfor i in 1 2 3 4 5 6 7 8 9; do echo \"$i$i$i$i$i$i\"; done >x &&\n     ++\tgit add x &&\n     + \thash_x=$(git hash-object x) &&\n     + \tbefore=$(git rev-parse --short \"$hash_x\") &&\n     + \tgit commit -m \"base\" &&\n\n\n diff.c                     | 37 ++++++++++++++++++++++++++++++-------\n t/t4015-diff-whitespace.sh | 38 ++++++++++++++++++++++++++++++++++++--\n 2 files changed, 66 insertions(+), 9 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex f9709de7b4..131903fa3a 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3153,16 +3153,19 @@ static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *o\n \tgather_dirstat(options, &dir, changed, \"\", 0);\n }\n \n+static void free_diffstat_file(struct diffstat_file *f)\n+{\n+\tfree(f->print_name);\n+\tfree(f->name);\n+\tfree(f->from_name);\n+\tfree(f);\n+}\n+\n void free_diffstat_info(struct diffstat_t *diffstat)\n {\n \tint i;\n-\tfor (i = 0; i < diffstat->nr; i++) {\n-\t\tstruct diffstat_file *f = diffstat->files[i];\n-\t\tfree(f->print_name);\n-\t\tfree(f->name);\n-\t\tfree(f->from_name);\n-\t\tfree(f);\n-\t}\n+\tfor (i = 0; i < diffstat->nr; i++)\n+\t\tfree_diffstat_file(diffstat->files[i]);\n \tfree(diffstat->files);\n }\n \n@@ -3718,6 +3721,26 @@ static void builtin_diffstat(const char *name_a, const char *name_b,\n \t\tif (xdi_diff_outf(&mf1, &mf2, discard_hunk_line,\n \t\t\t\t  diffstat_consume, diffstat, &xpp, &xecfg))\n \t\t\tdie(\"unable to generate diffstat for %s\", one->path);\n+\n+\t\tif (DIFF_FILE_VALID(one) && DIFF_FILE_VALID(two)) {\n+\t\t\tstruct diffstat_file *file = \n+\t\t\t\tdiffstat->files[diffstat->nr - 1];\n+\t\t\t/*\n+\t\t\t * Omit diffstats of modified files where nothing changed. \n+\t\t\t * Even if !same_contents, this might be the case due to\n+\t\t\t * ignoring whitespace changes, etc.\n+\t\t\t * \n+\t\t\t * But note that we special-case additions and deletions,\n+\t\t\t * as adding an empty file, for example is still of interest.\n+\t\t\t */\n+\t\t\tif ((p->status == DIFF_STATUS_MODIFIED) \n+\t\t\t\t&& !file->added\n+\t\t\t\t&& !file->deleted\n+\t\t\t\t&& one->mode == two->mode) {\n+\t\t\t\tfree_diffstat_file(file);\n+\t\t\t\tdiffstat->nr--;\n+\t\t\t}\n+\t\t}\n \t}\n \n \tdiff_free_filespec_data(one);\ndiff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh\nindex 88d3026894..8bdaa0a693 100755\n--- a/t/t4015-diff-whitespace.sh\n+++ b/t/t4015-diff-whitespace.sh\n@@ -789,7 +789,7 @@ test_expect_success 'checkdiff allows new blank lines' '\n \tgit diff --check\n '\n \n-test_expect_success 'whitespace-only changes not reported' '\n+test_expect_success 'whitespace-only changes not reported (diff)' '\n \tgit reset --hard &&\n \techo >x \"hello world\" &&\n \tgit add x &&\n@@ -799,10 +799,44 @@ test_expect_success 'whitespace-only changes not reported' '\n \ttest_must_be_empty actual\n '\n \n-test_expect_success 'whitespace-only changes reported across renames' '\n+test_expect_success 'whitespace-only changes not reported (diffstat)' '\n+\t# reuse state from previous test\n+\tgit diff --stat -b >actual &&\n+\ttest_must_be_empty actual\n+'\n+\n+test_expect_success 'whitespace changes with modification reported (diffstat)' '\n+\tgit reset --hard &&\n+\techo >x \"hello  world\" &&\n+\tgit update-index --chmod=+x x &&\n+\tgit diff --stat --cached -b >actual &&\n+\tcat <<-EOF >expect &&\n+\t x | 0\n+\t 1 file changed, 0 insertions(+), 0 deletions(-)\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'whitespace-only changes reported across renames (diffstat)' '\n \tgit reset --hard &&\n \tfor i in 1 2 3 4 5 6 7 8 9; do echo \"$i$i$i$i$i$i\"; done >x &&\n \tgit add x &&\n+\tgit commit -m \"base\" &&\n+\tsed -e \"5s/^/ /\" x >z &&\n+\tgit rm x &&\n+\tgit add z &&\n+\tgit diff -w -M --cached --stat >actual &&\n+\tcat <<-EOF >expect &&\n+\t x => z | 0\n+\t 1 file changed, 0 insertions(+), 0 deletions(-)\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'whitespace-only changes reported across renames' '\n+\tgit reset --hard HEAD~1 &&\n+\tfor i in 1 2 3 4 5 6 7 8 9; do echo \"$i$i$i$i$i$i\"; done >x &&\n+\tgit add x &&\n \thash_x=$(git hash-object x) &&\n \tbefore=$(git rev-parse --short \"$hash_x\") &&\n \tgit commit -m \"base\" &&\n\nbase-commit: 878e727637ec5815ccb3301eb994a54df95b21b8\n-- \ngitgitgadget\n"},{"id":"403897","messageId":"xmqqpn7pymsb.fsf@gitster.c.googlers.com","threadId":"53961","inReplyTo":"pull.689.v2.git.1597445151824.gitgitgadget@gmail.com","subject":"Re: [PATCH v2] diff: teach --stat to ignore uninteresting modifications","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-08-17T21:39:48Z","receivedAt":"2020-08-17T21:39:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Matthew Rogers via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Matthew Rogers <mattr94@gmail.com>\n>\n> Sometimes when diffing, files may show as being momdified even when\n\nmomdified? mummified? ah, modified.\n\n> there are no interesting diffs to show.  This happens naturally when\n> using options such as --ignore-space-change.  \n\nRead the next paragraph and notice that it explains the cases where\nthe patch does not want not to show, and then read the above again\nto realize that the above does not say anything about what it wants\nto do to cases the next paragraph does not cover.  It only says such\na case often happens when --ignore-space-change is used.\n\n\tWhen options like --ignore-space-change is in use, files\n\twith modification can have no interesting textual changes\n\tworth showing.  In such cases, \"git diff --stat\" shows 0\n\tlines of additions and deletions.  Teach \"git diff --stat\"\n\tnot to show such a path in its output, which would be more\n\tnatural.\n\nperhaps?\n\n> We don't want to prevent\n> the display  of all files that have 0 effective diffs since they could\n> be the result of a rename, permission change, or other similar operation\n> that may still be of interest so we special case additions and deletions\n> as they are always interesting.\n\nYup.  That makes sense.  \n\nIt would be nice if this does not have to be implemented as a list\nof exceptions, though.  Rather, a more targetted \"omit output only\nin this narrow case\" would be nicer, but the check with the mode\nbits should do at lesat for now.\n\n> diff --git a/diff.c b/diff.c\n> index f9709de7b4..131903fa3a 100644\n> --- a/diff.c\n> +++ b/diff.c\n> @@ -3153,16 +3153,19 @@ static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *o\n>  \tgather_dirstat(options, &dir, changed, \"\", 0);\n>  }\n>  \n> +static void free_diffstat_file(struct diffstat_file *f)\n> +{\n> +\tfree(f->print_name);\n> +\tfree(f->name);\n> +\tfree(f->from_name);\n> +\tfree(f);\n> +}\n> +\n>  void free_diffstat_info(struct diffstat_t *diffstat)\n>  {\n>  \tint i;\n> -\tfor (i = 0; i < diffstat->nr; i++) {\n> -\t\tstruct diffstat_file *f = diffstat->files[i];\n> -\t\tfree(f->print_name);\n> -\t\tfree(f->name);\n> -\t\tfree(f->from_name);\n> -\t\tfree(f);\n> -\t}\n> +\tfor (i = 0; i < diffstat->nr; i++)\n> +\t\tfree_diffstat_file(diffstat->files[i]);\n>  \tfree(diffstat->files);\n>  }\n>  \n> @@ -3718,6 +3721,26 @@ static void builtin_diffstat(const char *name_a, const char *name_b,\n>  \t\tif (xdi_diff_outf(&mf1, &mf2, discard_hunk_line,\n>  \t\t\t\t  diffstat_consume, diffstat, &xpp, &xecfg))\n>  \t\t\tdie(\"unable to generate diffstat for %s\", one->path);\n> +\n> +\t\tif (DIFF_FILE_VALID(one) && DIFF_FILE_VALID(two)) {\n> +\t\t\tstruct diffstat_file *file = \n> +\t\t\t\tdiffstat->files[diffstat->nr - 1];\n> +\t\t\t/*\n> +\t\t\t * Omit diffstats of modified files where nothing changed. \n> +\t\t\t * Even if !same_contents, this might be the case due to\n> +\t\t\t * ignoring whitespace changes, etc.\n> +\t\t\t * \n> +\t\t\t * But note that we special-case additions and deletions,\n\n\t\t\t * renames and mode changes without any content changes,\n\n> +\t\t\t * as adding an empty file, for example is still of interest.\n> +\t\t\t */\n> +\t\t\tif ((p->status == DIFF_STATUS_MODIFIED) \n> +\t\t\t\t&& !file->added\n> +\t\t\t\t&& !file->deleted\n> +\t\t\t\t&& one->mode == two->mode) {\n> +\t\t\t\tfree_diffstat_file(file);\n> +\t\t\t\tdiffstat->nr--;\n> +\t\t\t}\n> +\t\t}\n>  \t}\n>  \n>  \tdiff_free_filespec_data(one);\n> diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh\n> index 88d3026894..8bdaa0a693 100755\n> --- a/t/t4015-diff-whitespace.sh\n> +++ b/t/t4015-diff-whitespace.sh\n> @@ -789,7 +789,7 @@ test_expect_success 'checkdiff allows new blank lines' '\n>  \tgit diff --check\n>  '\n>  \n> -test_expect_success 'whitespace-only changes not reported' '\n> +test_expect_success 'whitespace-only changes not reported (diff)' '\n>  \tgit reset --hard &&\n>  \techo >x \"hello world\" &&\n>  \tgit add x &&\n> @@ -799,10 +799,44 @@ test_expect_success 'whitespace-only changes not reported' '\n>  \ttest_must_be_empty actual\n>  '\n>  \n> -test_expect_success 'whitespace-only changes reported across renames' '\n> +test_expect_success 'whitespace-only changes not reported (diffstat)' '\n> +\t# reuse state from previous test\n> +\tgit diff --stat -b >actual &&\n> +\ttest_must_be_empty actual\n> +'\n> +\n> +test_expect_success 'whitespace changes with modification reported (diffstat)' '\n> +\tgit reset --hard &&\n> +\techo >x \"hello  world\" &&\n> +\tgit update-index --chmod=+x x &&\n> +\tgit diff --stat --cached -b >actual &&\n> +\tcat <<-EOF >expect &&\n> +\t x | 0\n> +\t 1 file changed, 0 insertions(+), 0 deletions(-)\n> +\tEOF\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'whitespace-only changes reported across renames (diffstat)' '\n>  \tgit reset --hard &&\n>  \tfor i in 1 2 3 4 5 6 7 8 9; do echo \"$i$i$i$i$i$i\"; done >x &&\n>  \tgit add x &&\n> +\tgit commit -m \"base\" &&\n> +\tsed -e \"5s/^/ /\" x >z &&\n> +\tgit rm x &&\n> +\tgit add z &&\n> +\tgit diff -w -M --cached --stat >actual &&\n> +\tcat <<-EOF >expect &&\n> +\t x => z | 0\n> +\t 1 file changed, 0 insertions(+), 0 deletions(-)\n> +\tEOF\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'whitespace-only changes reported across renames' '\n> +\tgit reset --hard HEAD~1 &&\n> +\tfor i in 1 2 3 4 5 6 7 8 9; do echo \"$i$i$i$i$i$i\"; done >x &&\n> +\tgit add x &&\n>  \thash_x=$(git hash-object x) &&\n>  \tbefore=$(git rev-parse --short \"$hash_x\") &&\n>  \tgit commit -m \"base\" &&\n>\n> base-commit: 878e727637ec5815ccb3301eb994a54df95b21b8\n"},{"id":"403902","messageId":"CAOjrSZt7BZy=wnKhFfj+07-2GT+hOf+70HEJL6Hr04NaabK=eg@mail.gmail.com","threadId":"53961","inReplyTo":"xmqqpn7pymsb.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v2] diff: teach --stat to ignore uninteresting modifications","fromName":"Matt Rogers","fromEmail":"mattr94@gmail.com","sentAt":"2020-08-17T22:37:02Z","receivedAt":"2020-08-17T22:37:14Z","isPatch":true,"sender":{"key":"mattr94@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5719846?v=4"},"body":"On Mon, Aug 17, 2020 at 5:39 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> \"Matthew Rogers via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n>\n> > From: Matthew Rogers <mattr94@gmail.com>\n> >\n> > Sometimes when diffing, files may show as being momdified even when\n>\n> momdified? mummified? ah, modified.\n>\n> > there are no interesting diffs to show.  This happens naturally when\n> > using options such as --ignore-space-change.\n>\n> Read the next paragraph and notice that it explains the cases where\n> the patch does not want not to show, and then read the above again\n> to realize that the above does not say anything about what it wants\n> to do to cases the next paragraph does not cover.  It only says such\n> a case often happens when --ignore-space-change is used.\n>\n>         When options like --ignore-space-change is in use, files\n>         with modification can have no interesting textual changes\n>         worth showing.  In such cases, \"git diff --stat\" shows 0\n>         lines of additions and deletions.  Teach \"git diff --stat\"\n>         not to show such a path in its output, which would be more\n>         natural.\n>\n> perhaps?\n>\n> > We don't want to prevent\n> > the display  of all files that have 0 effective diffs since they could\n> > be the result of a rename, permission change, or other similar operation\n> > that may still be of interest so we special case additions and deletions\n> > as they are always interesting.\n>\n> Yup.  That makes sense.\n\nI'll send a reroll with the message improved as you suggested, as well\nas updating\n\n>\n> It would be nice if this does not have to be implemented as a list\n> of exceptions, though.  Rather, a more targetted \"omit output only\n> in this narrow case\" would be nicer, but the check with the mode\n> bits should do at lesat for now.\n>\n> > diff --git a/diff.c b/diff.c\n> > index f9709de7b4..131903fa3a 100644\n> > --- a/diff.c\n> > +++ b/diff.c\n> > @@ -3153,16 +3153,19 @@ static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *o\n> >       gather_dirstat(options, &dir, changed, \"\", 0);\n> >  }\n> >\n> > +static void free_diffstat_file(struct diffstat_file *f)\n> > +{\n> > +     free(f->print_name);\n> > +     free(f->name);\n> > +     free(f->from_name);\n> > +     free(f);\n> > +}\n> > +\n> >  void free_diffstat_info(struct diffstat_t *diffstat)\n> >  {\n> >       int i;\n> > -     for (i = 0; i < diffstat->nr; i++) {\n> > -             struct diffstat_file *f = diffstat->files[i];\n> > -             free(f->print_name);\n> > -             free(f->name);\n> > -             free(f->from_name);\n> > -             free(f);\n> > -     }\n> > +     for (i = 0; i < diffstat->nr; i++)\n> > +             free_diffstat_file(diffstat->files[i]);\n> >       free(diffstat->files);\n> >  }\n> >\n> > @@ -3718,6 +3721,26 @@ static void builtin_diffstat(const char *name_a, const char *name_b,\n> >               if (xdi_diff_outf(&mf1, &mf2, discard_hunk_line,\n> >                                 diffstat_consume, diffstat, &xpp, &xecfg))\n> >                       die(\"unable to generate diffstat for %s\", one->path);\n> > +\n> > +             if (DIFF_FILE_VALID(one) && DIFF_FILE_VALID(two)) {\n> > +                     struct diffstat_file *file =\n> > +                             diffstat->files[diffstat->nr - 1];\n> > +                     /*\n> > +                      * Omit diffstats of modified files where nothing changed.\n> > +                      * Even if !same_contents, this might be the case due to\n> > +                      * ignoring whitespace changes, etc.\n> > +                      *\n> > +                      * But note that we special-case additions and deletions,\n>\n>                          * renames and mode changes without any content changes,\n>\n> > +                      * as adding an empty file, for example is still of interest.\n> > +                      */\n> > +                     if ((p->status == DIFF_STATUS_MODIFIED)\n> > +                             && !file->added\n> > +                             && !file->deleted\n> > +                             && one->mode == two->mode) {\n> > +                             free_diffstat_file(file);\n> > +                             diffstat->nr--;\n> > +                     }\n> > +             }\n> >       }\n> >\n> >       diff_free_filespec_data(one);\n> > diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh\n> > index 88d3026894..8bdaa0a693 100755\n> > --- a/t/t4015-diff-whitespace.sh\n> > +++ b/t/t4015-diff-whitespace.sh\n> > @@ -789,7 +789,7 @@ test_expect_success 'checkdiff allows new blank lines' '\n> >       git diff --check\n> >  '\n> >\n> > -test_expect_success 'whitespace-only changes not reported' '\n> > +test_expect_success 'whitespace-only changes not reported (diff)' '\n> >       git reset --hard &&\n> >       echo >x \"hello world\" &&\n> >       git add x &&\n> > @@ -799,10 +799,44 @@ test_expect_success 'whitespace-only changes not reported' '\n> >       test_must_be_empty actual\n> >  '\n> >\n> > -test_expect_success 'whitespace-only changes reported across renames' '\n> > +test_expect_success 'whitespace-only changes not reported (diffstat)' '\n> > +     # reuse state from previous test\n> > +     git diff --stat -b >actual &&\n> > +     test_must_be_empty actual\n> > +'\n> > +\n> > +test_expect_success 'whitespace changes with modification reported (diffstat)' '\n> > +     git reset --hard &&\n> > +     echo >x \"hello  world\" &&\n> > +     git update-index --chmod=+x x &&\n> > +     git diff --stat --cached -b >actual &&\n> > +     cat <<-EOF >expect &&\n> > +      x | 0\n> > +      1 file changed, 0 insertions(+), 0 deletions(-)\n> > +     EOF\n> > +     test_cmp expect actual\n> > +'\n> > +\n> > +test_expect_success 'whitespace-only changes reported across renames (diffstat)' '\n> >       git reset --hard &&\n> >       for i in 1 2 3 4 5 6 7 8 9; do echo \"$i$i$i$i$i$i\"; done >x &&\n> >       git add x &&\n> > +     git commit -m \"base\" &&\n> > +     sed -e \"5s/^/ /\" x >z &&\n> > +     git rm x &&\n> > +     git add z &&\n> > +     git diff -w -M --cached --stat >actual &&\n> > +     cat <<-EOF >expect &&\n> > +      x => z | 0\n> > +      1 file changed, 0 insertions(+), 0 deletions(-)\n> > +     EOF\n> > +     test_cmp expect actual\n> > +'\n> > +\n> > +test_expect_success 'whitespace-only changes reported across renames' '\n> > +     git reset --hard HEAD~1 &&\n> > +     for i in 1 2 3 4 5 6 7 8 9; do echo \"$i$i$i$i$i$i\"; done >x &&\n> > +     git add x &&\n> >       hash_x=$(git hash-object x) &&\n> >       before=$(git rev-parse --short \"$hash_x\") &&\n> >       git commit -m \"base\" &&\n> >\n> > base-commit: 878e727637ec5815ccb3301eb994a54df95b21b8\n\n\n\n-- \nMatthew Rogers\n"},{"id":"403903","messageId":"CAOjrSZuRKSaCo8HjZtsO6mzLxfuLgKyS5RADY0P4e71RGVaxLg@mail.gmail.com","threadId":"53961","inReplyTo":"CAOjrSZt7BZy=wnKhFfj+07-2GT+hOf+70HEJL6Hr04NaabK=eg@mail.gmail.com","subject":"Re: [PATCH v2] diff: teach --stat to ignore uninteresting modifications","fromName":"Matt Rogers","fromEmail":"mattr94@gmail.com","sentAt":"2020-08-17T22:37:54Z","receivedAt":"2020-08-17T22:38:07Z","isPatch":true,"sender":{"key":"mattr94@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5719846?v=4"},"body":"...As well as updating the comment.\n\n(sorry for the double mail I fat fingered ctrl+enter while typing)\n\nOn Mon, Aug 17, 2020 at 6:37 PM Matt Rogers <mattr94@gmail.com> wrote:\n>\n> On Mon, Aug 17, 2020 at 5:39 PM Junio C Hamano <gitster@pobox.com> wrote:\n> >\n> > \"Matthew Rogers via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n> >\n> > > From: Matthew Rogers <mattr94@gmail.com>\n> > >\n> > > Sometimes when diffing, files may show as being momdified even when\n> >\n> > momdified? mummified? ah, modified.\n> >\n> > > there are no interesting diffs to show.  This happens naturally when\n> > > using options such as --ignore-space-change.\n> >\n> > Read the next paragraph and notice that it explains the cases where\n> > the patch does not want not to show, and then read the above again\n> > to realize that the above does not say anything about what it wants\n> > to do to cases the next paragraph does not cover.  It only says such\n> > a case often happens when --ignore-space-change is used.\n> >\n> >         When options like --ignore-space-change is in use, files\n> >         with modification can have no interesting textual changes\n> >         worth showing.  In such cases, \"git diff --stat\" shows 0\n> >         lines of additions and deletions.  Teach \"git diff --stat\"\n> >         not to show such a path in its output, which would be more\n> >         natural.\n> >\n> > perhaps?\n> >\n> > > We don't want to prevent\n> > > the display  of all files that have 0 effective diffs since they could\n> > > be the result of a rename, permission change, or other similar operation\n> > > that may still be of interest so we special case additions and deletions\n> > > as they are always interesting.\n> >\n> > Yup.  That makes sense.\n>\n> I'll send a reroll with the message improved as you suggested, as well\n> as updating\n>\n> >\n> > It would be nice if this does not have to be implemented as a list\n> > of exceptions, though.  Rather, a more targetted \"omit output only\n> > in this narrow case\" would be nicer, but the check with the mode\n> > bits should do at lesat for now.\n> >\n> > > diff --git a/diff.c b/diff.c\n> > > index f9709de7b4..131903fa3a 100644\n> > > --- a/diff.c\n> > > +++ b/diff.c\n> > > @@ -3153,16 +3153,19 @@ static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *o\n> > >       gather_dirstat(options, &dir, changed, \"\", 0);\n> > >  }\n> > >\n> > > +static void free_diffstat_file(struct diffstat_file *f)\n> > > +{\n> > > +     free(f->print_name);\n> > > +     free(f->name);\n> > > +     free(f->from_name);\n> > > +     free(f);\n> > > +}\n> > > +\n> > >  void free_diffstat_info(struct diffstat_t *diffstat)\n> > >  {\n> > >       int i;\n> > > -     for (i = 0; i < diffstat->nr; i++) {\n> > > -             struct diffstat_file *f = diffstat->files[i];\n> > > -             free(f->print_name);\n> > > -             free(f->name);\n> > > -             free(f->from_name);\n> > > -             free(f);\n> > > -     }\n> > > +     for (i = 0; i < diffstat->nr; i++)\n> > > +             free_diffstat_file(diffstat->files[i]);\n> > >       free(diffstat->files);\n> > >  }\n> > >\n> > > @@ -3718,6 +3721,26 @@ static void builtin_diffstat(const char *name_a, const char *name_b,\n> > >               if (xdi_diff_outf(&mf1, &mf2, discard_hunk_line,\n> > >                                 diffstat_consume, diffstat, &xpp, &xecfg))\n> > >                       die(\"unable to generate diffstat for %s\", one->path);\n> > > +\n> > > +             if (DIFF_FILE_VALID(one) && DIFF_FILE_VALID(two)) {\n> > > +                     struct diffstat_file *file =\n> > > +                             diffstat->files[diffstat->nr - 1];\n> > > +                     /*\n> > > +                      * Omit diffstats of modified files where nothing changed.\n> > > +                      * Even if !same_contents, this might be the case due to\n> > > +                      * ignoring whitespace changes, etc.\n> > > +                      *\n> > > +                      * But note that we special-case additions and deletions,\n> >\n> >                          * renames and mode changes without any content changes,\n> >\n> > > +                      * as adding an empty file, for example is still of interest.\n> > > +                      */\n> > > +                     if ((p->status == DIFF_STATUS_MODIFIED)\n> > > +                             && !file->added\n> > > +                             && !file->deleted\n> > > +                             && one->mode == two->mode) {\n> > > +                             free_diffstat_file(file);\n> > > +                             diffstat->nr--;\n> > > +                     }\n> > > +             }\n> > >       }\n> > >\n> > >       diff_free_filespec_data(one);\n> > > diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh\n> > > index 88d3026894..8bdaa0a693 100755\n> > > --- a/t/t4015-diff-whitespace.sh\n> > > +++ b/t/t4015-diff-whitespace.sh\n> > > @@ -789,7 +789,7 @@ test_expect_success 'checkdiff allows new blank lines' '\n> > >       git diff --check\n> > >  '\n> > >\n> > > -test_expect_success 'whitespace-only changes not reported' '\n> > > +test_expect_success 'whitespace-only changes not reported (diff)' '\n> > >       git reset --hard &&\n> > >       echo >x \"hello world\" &&\n> > >       git add x &&\n> > > @@ -799,10 +799,44 @@ test_expect_success 'whitespace-only changes not reported' '\n> > >       test_must_be_empty actual\n> > >  '\n> > >\n> > > -test_expect_success 'whitespace-only changes reported across renames' '\n> > > +test_expect_success 'whitespace-only changes not reported (diffstat)' '\n> > > +     # reuse state from previous test\n> > > +     git diff --stat -b >actual &&\n> > > +     test_must_be_empty actual\n> > > +'\n> > > +\n> > > +test_expect_success 'whitespace changes with modification reported (diffstat)' '\n> > > +     git reset --hard &&\n> > > +     echo >x \"hello  world\" &&\n> > > +     git update-index --chmod=+x x &&\n> > > +     git diff --stat --cached -b >actual &&\n> > > +     cat <<-EOF >expect &&\n> > > +      x | 0\n> > > +      1 file changed, 0 insertions(+), 0 deletions(-)\n> > > +     EOF\n> > > +     test_cmp expect actual\n> > > +'\n> > > +\n> > > +test_expect_success 'whitespace-only changes reported across renames (diffstat)' '\n> > >       git reset --hard &&\n> > >       for i in 1 2 3 4 5 6 7 8 9; do echo \"$i$i$i$i$i$i\"; done >x &&\n> > >       git add x &&\n> > > +     git commit -m \"base\" &&\n> > > +     sed -e \"5s/^/ /\" x >z &&\n> > > +     git rm x &&\n> > > +     git add z &&\n> > > +     git diff -w -M --cached --stat >actual &&\n> > > +     cat <<-EOF >expect &&\n> > > +      x => z | 0\n> > > +      1 file changed, 0 insertions(+), 0 deletions(-)\n> > > +     EOF\n> > > +     test_cmp expect actual\n> > > +'\n> > > +\n> > > +test_expect_success 'whitespace-only changes reported across renames' '\n> > > +     git reset --hard HEAD~1 &&\n> > > +     for i in 1 2 3 4 5 6 7 8 9; do echo \"$i$i$i$i$i$i\"; done >x &&\n> > > +     git add x &&\n> > >       hash_x=$(git hash-object x) &&\n> > >       before=$(git rev-parse --short \"$hash_x\") &&\n> > >       git commit -m \"base\" &&\n> > >\n> > > base-commit: 878e727637ec5815ccb3301eb994a54df95b21b8\n>\n>\n>\n> --\n> Matthew Rogers\n\n\n\n-- \nMatthew Rogers\n"},{"id":"404077","messageId":"pull.689.v3.git.1597884092580.gitgitgadget@gmail.com","threadId":"53961","inReplyTo":"pull.689.v2.git.1597445151824.gitgitgadget@gmail.com","subject":"[PATCH v3] diff: teach --stat to ignore uninteresting modifications","fromName":"Matthew Rogers via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-08-20T00:41:32Z","receivedAt":"2020-08-20T00:41:40Z","isPatch":true,"sender":{"key":"name:Matthew Rogers","avatar":null},"body":"From: Matthew Rogers <mattr94@gmail.com>\n\nWhen options such as --ignore-space-change are in use, files with\nmodifications can have no interesting textual changes worth showing.  In\nsuch cases, \"git diff --stat\" shows 0 lines of additions and deletions.\nTeach \"git diff --stat\" not to show such a path in its output, which\nwould be more natural.\n\nHowever, we don't want to prevent the display  of all files that have 0\neffective diffs since they could be the result of a rename, permission\nchange, or other similar operation that may still be of interest so we\nspecial case additions and deletions as they are always interesting.\n\nSigned-off-by: Matthew Rogers <mattr94@gmail.com>\n---\n    diff: teach --stat to ignore uninteresting modifications\n    \n    This patch is based on the discussion these email threads:\n    \n    https://lore.kernel.org/git/1484704915.2096.16.camel@mattmccutchen.net/\n    https://lore.kernel.org/git/CAOjrSZtQPQ8Xxuz+7SGykR8Q-gFDEZANSE5yQASqKjpbUAq_5Q@mail.gmail.com/\n    \n    With the code mostly taken from this specific message:\n    https://lore.kernel.org/git/20170118111705.6bqzkklluikda3r5@sigill.intra.peff.net/\n    \n    The summary is that when running git diff --stat in combination with\n    --ignore-all-space or similar options, you'll see many lines of the\n    form:\n    \n    some-file.txt | 0\n    \n    which can be misleading when you are explicitly telling git to \"ignore\n    all space\" or something similar. To rectify this issue, this patch\n    categorizes all files that are modified but have no effective changes as\n    not fit to display to the user.\n    \n    New in V2:\n    \n     * I've added a test covering the rename case with whitespace-changes\n       and permissions changes\n     * I've also updated the logic in builtin_diffstat to include that logic\n       as well\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-689%2FROGERSM94%2Fzero-diffs-v3\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-689/ROGERSM94/zero-diffs-v3\nPull-Request: https://github.com/gitgitgadget/git/pull/689\n\nRange-diff vs v2:\n\n 1:  6c5db18618 ! 1:  7c3113846e diff: teach --stat to ignore uninteresting modifications\n     @@ Metadata\n       ## Commit message ##\n          diff: teach --stat to ignore uninteresting modifications\n      \n     -    Sometimes when diffing, files may show as being momdified even when\n     -    there are no interesting diffs to show.  This happens naturally when\n     -    using options such as --ignore-space-change.  We don't want to prevent\n     -    the display  of all files that have 0 effective diffs since they could\n     -    be the result of a rename, permission change, or other similar operation\n     -    that may still be of interest so we special case additions and deletions\n     -    as they are always interesting.\n     +    When options such as --ignore-space-change are in use, files with\n     +    modifications can have no interesting textual changes worth showing.  In\n     +    such cases, \"git diff --stat\" shows 0 lines of additions and deletions.\n     +    Teach \"git diff --stat\" not to show such a path in its output, which\n     +    would be more natural.\n     +\n     +    However, we don't want to prevent the display  of all files that have 0\n     +    effective diffs since they could be the result of a rename, permission\n     +    change, or other similar operation that may still be of interest so we\n     +    special case additions and deletions as they are always interesting.\n      \n          Signed-off-by: Matthew Rogers <mattr94@gmail.com>\n      \n     @@ diff.c: static void builtin_diffstat(const char *name_a, const char *name_b,\n      +\t\t\t * Even if !same_contents, this might be the case due to\n      +\t\t\t * ignoring whitespace changes, etc.\n      +\t\t\t * \n     -+\t\t\t * But note that we special-case additions and deletions,\n     -+\t\t\t * as adding an empty file, for example is still of interest.\n     ++\t\t\t * But note that we special-case additions, deletions,\n     ++\t\t\t * renames, and mode changes as adding an empty file, \n     ++\t\t\t * for example is still of interest.\n      +\t\t\t */\n      +\t\t\tif ((p->status == DIFF_STATUS_MODIFIED) \n      +\t\t\t\t&& !file->added\n\n\n diff.c                     | 38 +++++++++++++++++++++++++++++++-------\n t/t4015-diff-whitespace.sh | 38 ++++++++++++++++++++++++++++++++++++--\n 2 files changed, 67 insertions(+), 9 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex f9709de7b4..4f54b41395 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3153,16 +3153,19 @@ static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *o\n \tgather_dirstat(options, &dir, changed, \"\", 0);\n }\n \n+static void free_diffstat_file(struct diffstat_file *f)\n+{\n+\tfree(f->print_name);\n+\tfree(f->name);\n+\tfree(f->from_name);\n+\tfree(f);\n+}\n+\n void free_diffstat_info(struct diffstat_t *diffstat)\n {\n \tint i;\n-\tfor (i = 0; i < diffstat->nr; i++) {\n-\t\tstruct diffstat_file *f = diffstat->files[i];\n-\t\tfree(f->print_name);\n-\t\tfree(f->name);\n-\t\tfree(f->from_name);\n-\t\tfree(f);\n-\t}\n+\tfor (i = 0; i < diffstat->nr; i++)\n+\t\tfree_diffstat_file(diffstat->files[i]);\n \tfree(diffstat->files);\n }\n \n@@ -3718,6 +3721,27 @@ static void builtin_diffstat(const char *name_a, const char *name_b,\n \t\tif (xdi_diff_outf(&mf1, &mf2, discard_hunk_line,\n \t\t\t\t  diffstat_consume, diffstat, &xpp, &xecfg))\n \t\t\tdie(\"unable to generate diffstat for %s\", one->path);\n+\n+\t\tif (DIFF_FILE_VALID(one) && DIFF_FILE_VALID(two)) {\n+\t\t\tstruct diffstat_file *file = \n+\t\t\t\tdiffstat->files[diffstat->nr - 1];\n+\t\t\t/*\n+\t\t\t * Omit diffstats of modified files where nothing changed. \n+\t\t\t * Even if !same_contents, this might be the case due to\n+\t\t\t * ignoring whitespace changes, etc.\n+\t\t\t * \n+\t\t\t * But note that we special-case additions, deletions,\n+\t\t\t * renames, and mode changes as adding an empty file, \n+\t\t\t * for example is still of interest.\n+\t\t\t */\n+\t\t\tif ((p->status == DIFF_STATUS_MODIFIED) \n+\t\t\t\t&& !file->added\n+\t\t\t\t&& !file->deleted\n+\t\t\t\t&& one->mode == two->mode) {\n+\t\t\t\tfree_diffstat_file(file);\n+\t\t\t\tdiffstat->nr--;\n+\t\t\t}\n+\t\t}\n \t}\n \n \tdiff_free_filespec_data(one);\ndiff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh\nindex 88d3026894..8bdaa0a693 100755\n--- a/t/t4015-diff-whitespace.sh\n+++ b/t/t4015-diff-whitespace.sh\n@@ -789,7 +789,7 @@ test_expect_success 'checkdiff allows new blank lines' '\n \tgit diff --check\n '\n \n-test_expect_success 'whitespace-only changes not reported' '\n+test_expect_success 'whitespace-only changes not reported (diff)' '\n \tgit reset --hard &&\n \techo >x \"hello world\" &&\n \tgit add x &&\n@@ -799,10 +799,44 @@ test_expect_success 'whitespace-only changes not reported' '\n \ttest_must_be_empty actual\n '\n \n-test_expect_success 'whitespace-only changes reported across renames' '\n+test_expect_success 'whitespace-only changes not reported (diffstat)' '\n+\t# reuse state from previous test\n+\tgit diff --stat -b >actual &&\n+\ttest_must_be_empty actual\n+'\n+\n+test_expect_success 'whitespace changes with modification reported (diffstat)' '\n+\tgit reset --hard &&\n+\techo >x \"hello  world\" &&\n+\tgit update-index --chmod=+x x &&\n+\tgit diff --stat --cached -b >actual &&\n+\tcat <<-EOF >expect &&\n+\t x | 0\n+\t 1 file changed, 0 insertions(+), 0 deletions(-)\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'whitespace-only changes reported across renames (diffstat)' '\n \tgit reset --hard &&\n \tfor i in 1 2 3 4 5 6 7 8 9; do echo \"$i$i$i$i$i$i\"; done >x &&\n \tgit add x &&\n+\tgit commit -m \"base\" &&\n+\tsed -e \"5s/^/ /\" x >z &&\n+\tgit rm x &&\n+\tgit add z &&\n+\tgit diff -w -M --cached --stat >actual &&\n+\tcat <<-EOF >expect &&\n+\t x => z | 0\n+\t 1 file changed, 0 insertions(+), 0 deletions(-)\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'whitespace-only changes reported across renames' '\n+\tgit reset --hard HEAD~1 &&\n+\tfor i in 1 2 3 4 5 6 7 8 9; do echo \"$i$i$i$i$i$i\"; done >x &&\n+\tgit add x &&\n \thash_x=$(git hash-object x) &&\n \tbefore=$(git rev-parse --short \"$hash_x\") &&\n \tgit commit -m \"base\" &&\n\nbase-commit: 878e727637ec5815ccb3301eb994a54df95b21b8\n-- \ngitgitgadget\n"},{"id":"404078","messageId":"xmqqzh6qb0ef.fsf@gitster.c.googlers.com","threadId":"53961","inReplyTo":"pull.689.v3.git.1597884092580.gitgitgadget@gmail.com","subject":"Re: [PATCH v3] diff: teach --stat to ignore uninteresting modifications","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-08-20T00:56:24Z","receivedAt":"2020-08-20T00:56:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Matthew Rogers via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Matthew Rogers <mattr94@gmail.com>\n>\n> When options such as --ignore-space-change are in use, files with\n> modifications can have no interesting textual changes worth showing.  In\n> such cases, \"git diff --stat\" shows 0 lines of additions and deletions.\n> Teach \"git diff --stat\" not to show such a path in its output, which\n> would be more natural.\n>\n> However, we don't want to prevent the display  of all files that have 0\n> effective diffs since they could be the result of a rename, permission\n> change, or other similar operation that may still be of interest so we\n> special case additions and deletions as they are always interesting.\n>\n> Signed-off-by: Matthew Rogers <mattr94@gmail.com>\n> ---\n\nLooks good, thanks.  Will queue.\n\n\nBy the way, before making your commits, please make sure you do not\nhave whitespace errors.  I've let my \"git am\" to fix them, so no\nneed to resend, but for future reference...\n\n.git/rebase-apply/patch:116: trailing whitespace.\n\t\t\tstruct diffstat_file *file = \n.git/rebase-apply/patch:119: trailing whitespace.\n\t\t\t * Omit diffstats of modified files where nothing changed. \n.git/rebase-apply/patch:122: trailing whitespace.\n\t\t\t * \n.git/rebase-apply/patch:124: trailing whitespace.\n\t\t\t * renames, and mode changes as adding an empty file, \n.git/rebase-apply/patch:127: trailing whitespace.\n\t\t\tif ((p->status == DIFF_STATUS_MODIFIED) \nwarning: 5 lines applied after fixing whitespace errors.\nApplying: diff: teach --stat to ignore uninteresting modifications\n\n"}]}