threads / patch / 30820

v2diff: Only count lines in show_shortstats

Subject: [PATCH v2] diff: Only count lines in show_shortstats

## tl;dr

3 messages between Jun 15, 2012 and Jun 15, 2012. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Alexander Strasser· Jun 15, 2012, 19:02 UTC · lore

Do not mix byte and line counts. Binary files have byte counts; skip them when accumulating line insertions/deletions.

The regression was introduced in e18872b.
Signed-off-by: Alexander Strasser <eclipse7@gmx.net>
---
 Zbigniew, Junio:
   I hope I did submit the patch correctly this time.
   This is a reroll with the following differences to v1:
   * I changed the additional test for t4012 to adhere to modern
     style on request by Zbigniew. I had the impression this might
     be in conflict with Junio's comment
     "Style fixes should be done later after dust from more important
      changes (e.g. a bugfix) settles."
     But maybe that was directed at modernizing the remaining of
     parts of that test file.
   * I deleted the 2-space indent in the commit message paragraphs
   * I omitted the parenthesis in the subject message
   The above points are the reason I resent this for discussion to
 the list.
   I apologize for the long delay, some misunderstandings on my side
 made me think the initial submission was considered for inclusion.
 diff.c                 | 2 +-
 t/t4012-diff-binary.sh | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)
Show changes to 2 files +7 −1

diff.c, t/t4012-diff-binary.sh

diff --git a/diff.c b/diff.c
index 77edd50..1a594df 100644
--- a/diff.c
+++ b/diff.c
@@ -1700,7 +1700,7 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option
 			continue;
 		if (!data->files[i]->is_renamed && (added + deleted == 0)) {
 			total_files--;
-		} else {
+		} else if (!data->files[i]->is_binary) { /* don't count bytes */
 			adds += added;
 			dels += deleted;
 		}
diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh
index 8b4e80d..7d03c1d 100755
--- a/t/t4012-diff-binary.sh
+++ b/t/t4012-diff-binary.sh
@@ -36,6 +36,12 @@ test_expect_success '"apply --stat" output for binary file change' '
 	test_i18ncmp expected current
 '
 
+test_expect_success 'diff --shortstat output for binary file change' '
+	echo " 4 files changed, 2 insertions(+), 2 deletions(-)" >expected &&
+	git diff --shortstat >current &&
+	test_i18ncmp expected current
+'
+
 test_expect_success 'apply --numstat notices binary file change' '
 	git diff >diff &&
 	git apply --numstat <diff >current &&
-- 
1.7.10.2.552.gaa3bb87
Junio C Hamano· Jun 15, 2012, 19:38 UTC · re: Alexander Strasser · lore

Re: [PATCH v2] diff: Only count lines in show_shortstats

Alexander Strasser <eclipse7@gmx.net> writes:
Show 7 quoted lines
> Do not mix byte and line counts. Binary files have byte counts;
> skip them when accumulating line insertions/deletions.
>
> The regression was introduced in e18872b.
>
> Signed-off-by: Alexander Strasser <eclipse7@gmx.net>
> ---
Administrivia.

Please do not use Mail-Followup-To: header to deflect direct response to you away to other people. When I want to reply to you and Cc: others, I do not want to see other people's name on To: field---I have to move them manually to the Cc: line in my editor. When somebody else wants to reply to you, I do not want to see my name on its To: line, as such a message that is addressed to you may not be of immediate interest for me.

Show 13 quoted lines
>
>  Zbigniew, Junio:
>    I hope I did submit the patch correctly this time.
>
>    This is a reroll with the following differences to v1:
>
>    * I changed the additional test for t4012 to adhere to modern
>      style on request by Zbigniew. I had the impression this might
>      be in conflict with Junio's comment
>      "Style fixes should be done later after dust from more important
>       changes (e.g. a bugfix) settles."
>      But maybe that was directed at modernizing the remaining of
>      parts of that test file.
Yes, that "maybe" is correct.
>    * I deleted the 2-space indent in the commit message paragraphs
OK.
>    * I omitted the parenthesis in the subject message
OK.
Show 31 quoted lines
>  diff.c                 | 2 +-
>  t/t4012-diff-binary.sh | 6 ++++++
>  2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/diff.c b/diff.c
> index 77edd50..1a594df 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -1700,7 +1700,7 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option
>  			continue;
>  		if (!data->files[i]->is_renamed && (added + deleted == 0)) {
>  			total_files--;
> -		} else {
> +		} else if (!data->files[i]->is_binary) { /* don't count bytes */
>  			adds += added;
>  			dels += deleted;
>  		}
> diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh
> index 8b4e80d..7d03c1d 100755
> --- a/t/t4012-diff-binary.sh
> +++ b/t/t4012-diff-binary.sh
> @@ -36,6 +36,12 @@ test_expect_success '"apply --stat" output for binary file change' '
>  	test_i18ncmp expected current
>  '
>  
> +test_expect_success 'diff --shortstat output for binary file change' '
> +	echo " 4 files changed, 2 insertions(+), 2 deletions(-)" >expected &&
> +	git diff --shortstat >current &&
> +	test_i18ncmp expected current
> +'
> +

It would also have been interesting if we can see the result for a diff that involves _only_ binary files, no?

>  test_expect_success 'apply --numstat notices binary file change' '
>  	git diff >diff &&
>  	git apply --numstat <diff >current &&
Thanks.
Alexander Strasser· Jun 15, 2012, 21:19 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] diff: Only count lines in show_shortstats

Hi,
Junio C Hamano wrote:
Show 13 quoted lines
> Alexander Strasser <eclipse7@gmx.net> writes:
> 
> > Do not mix byte and line counts. Binary files have byte counts;
> > skip them when accumulating line insertions/deletions.
> >
> > The regression was introduced in e18872b.
> >
> > Signed-off-by: Alexander Strasser <eclipse7@gmx.net>
> > ---
> 
> Administrivia.
> 
> Please do not use Mail-Followup-To: header to deflect direct
  I did not know about that mail header. I am not sure about the
exact ramifications but I hope I told my MUA to stop inserting
that header behind my back.
[...]
Show 9 quoted lines
> > +test_expect_success 'diff --shortstat output for binary file change' '
> > +	echo " 4 files changed, 2 insertions(+), 2 deletions(-)" >expected &&
> > +	git diff --shortstat >current &&
> > +	test_i18ncmp expected current
> > +'
> > +
> 
> It would also have been interesting if we can see the result for a
> diff that involves _only_ binary files, no?
  Seems like an interesting test to me. I will add it and send as v3
in a moment.
[...]
  Alexander

← back to recent threads