diff --stat: report mode-only changes for binary files like text files
Mode-only changes to binary files without content change were reported as if they were rewritten, but text files in the same situation were reported as "unchanged". Let's treat binary files like text files here, and simply say that they are unchanged. Output of --shortstat is modified in the same way. Reported-by: Martin Mareš <mj@ucw.cz> Signed-off-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									4434e6ba6c
								
							
						
					
					
						commit
						e18872b2f0
					
				
							
								
								
									
										22
									
								
								diff.c
								
								
								
								
							
							
						
						
									
										22
									
								
								diff.c
								
								
								
								
							|  | @ -1583,8 +1583,12 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options) | |||
| 		if (data->files[i]->is_binary) { | ||||
| 			fprintf(options->file, "%s", line_prefix); | ||||
| 			show_name(options->file, prefix, name, len); | ||||
| 			fprintf(options->file, "  Bin "); | ||||
| 			fprintf(options->file, "%s%"PRIuMAX"%s", | ||||
| 			fprintf(options->file, "  Bin"); | ||||
| 			if (!added && !deleted) { | ||||
| 				putc('\n', options->file); | ||||
| 				continue; | ||||
| 			} | ||||
| 			fprintf(options->file, " %s%"PRIuMAX"%s", | ||||
| 				del_c, deleted, reset); | ||||
| 			fprintf(options->file, " -> "); | ||||
| 			fprintf(options->file, "%s%"PRIuMAX"%s", | ||||
|  | @ -1657,19 +1661,18 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option | |||
| 		return; | ||||
|  | ||||
| 	for (i = 0; i < data->nr; i++) { | ||||
| 		if (!data->files[i]->is_binary && | ||||
| 		    !data->files[i]->is_unmerged) { | ||||
| 		int added = data->files[i]->added; | ||||
| 		int deleted= data->files[i]->deleted; | ||||
| 			if (!data->files[i]->is_renamed && | ||||
| 			    (added + deleted == 0)) { | ||||
|  | ||||
| 		if (data->files[i]->is_unmerged) | ||||
| 			continue; | ||||
| 		if (!data->files[i]->is_renamed && (added + deleted == 0)) { | ||||
| 			total_files--; | ||||
| 		} else { | ||||
| 			adds += added; | ||||
| 			dels += deleted; | ||||
| 		} | ||||
| 	} | ||||
| 	} | ||||
| 	if (options->output_prefix) { | ||||
| 		struct strbuf *msg = NULL; | ||||
| 		msg = options->output_prefix(options, | ||||
|  | @ -2377,9 +2380,14 @@ static void builtin_diffstat(const char *name_a, const char *name_b, | |||
|  | ||||
| 	if (diff_filespec_is_binary(one) || diff_filespec_is_binary(two)) { | ||||
| 		data->is_binary = 1; | ||||
| 		if (!hashcmp(one->sha1, two->sha1)) { | ||||
| 			data->added = 0; | ||||
| 			data->deleted = 0; | ||||
| 		} else { | ||||
| 			data->added = diff_filespec_size(two); | ||||
| 			data->deleted = diff_filespec_size(one); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	else if (complete_rewrite) { | ||||
| 		diff_populate_filespec(one, 0); | ||||
|  |  | |||
|  | @ -46,18 +46,12 @@ test_expect_success '--shortstat output after text chmod' ' | |||
|  | ||||
| test_expect_success '--stat output after binary chmod' ' | ||||
| 	test_chmod +x binbin && | ||||
| 	cat >expect <<-EOF && | ||||
| 	 binbin |  Bin 1024 -> 1024 bytes | ||||
| 	 1 file changed, 0 insertions(+), 0 deletions(-) | ||||
| 	EOF | ||||
| 	echo " 0 files changed" >expect && | ||||
| 	git diff HEAD --stat >actual && | ||||
| 	test_cmp expect actual | ||||
| ' | ||||
|  | ||||
| test_expect_success '--shortstat output after binary chmod' ' | ||||
| 	cat >expect <<-EOF && | ||||
| 	 1 file changed, 0 insertions(+), 0 deletions(-) | ||||
| 	EOF | ||||
| 	git diff HEAD --shortstat >actual && | ||||
| 	test_cmp expect actual | ||||
| ' | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Zbigniew Jędrzejewski-Szmek
						Zbigniew Jędrzejewski-Szmek