Merge branch 'zj/diff-empty-chmod'
"git diff --stat" used to fully count a binary file with modified execution bits whose contents is unmodified, which was not right. By Zbigniew Jędrzejewski-Szmek (4) and Johannes Sixt (1) * zj/diff-empty-chmod: t4006: Windows do not have /dev/zero diff --stat: do not run diff on indentical files diff --stat: report mode-only changes for binary files like text files tests: check --[short]stat output after chmod test: modernize style of t4006 Conflicts: diff.c
This commit is contained in:
commit
fc1320bfe2
43
diff.c
43
diff.c
@ -1614,8 +1614,12 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
|
|||||||
if (data->files[i]->is_binary) {
|
if (data->files[i]->is_binary) {
|
||||||
fprintf(options->file, "%s", line_prefix);
|
fprintf(options->file, "%s", line_prefix);
|
||||||
show_name(options->file, prefix, name, len);
|
show_name(options->file, prefix, name, len);
|
||||||
fprintf(options->file, " %*s ", number_width, "Bin");
|
fprintf(options->file, " %*s", number_width, "Bin");
|
||||||
fprintf(options->file, "%s%"PRIuMAX"%s",
|
if (!added && !deleted) {
|
||||||
|
putc('\n', options->file);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fprintf(options->file, " %s%"PRIuMAX"%s",
|
||||||
del_c, deleted, reset);
|
del_c, deleted, reset);
|
||||||
fprintf(options->file, " -> ");
|
fprintf(options->file, " -> ");
|
||||||
fprintf(options->file, "%s%"PRIuMAX"%s",
|
fprintf(options->file, "%s%"PRIuMAX"%s",
|
||||||
@ -1689,17 +1693,16 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < data->nr; i++) {
|
for (i = 0; i < data->nr; i++) {
|
||||||
if (!data->files[i]->is_binary &&
|
int added = data->files[i]->added;
|
||||||
!data->files[i]->is_unmerged) {
|
int deleted= data->files[i]->deleted;
|
||||||
int added = data->files[i]->added;
|
|
||||||
int deleted= data->files[i]->deleted;
|
if (data->files[i]->is_unmerged)
|
||||||
if (!data->files[i]->is_renamed &&
|
continue;
|
||||||
(added + deleted == 0)) {
|
if (!data->files[i]->is_renamed && (added + deleted == 0)) {
|
||||||
total_files--;
|
total_files--;
|
||||||
} else {
|
} else {
|
||||||
adds += added;
|
adds += added;
|
||||||
dels += deleted;
|
dels += deleted;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options->output_prefix) {
|
if (options->output_prefix) {
|
||||||
@ -2399,6 +2402,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
|
|||||||
{
|
{
|
||||||
mmfile_t mf1, mf2;
|
mmfile_t mf1, mf2;
|
||||||
struct diffstat_file *data;
|
struct diffstat_file *data;
|
||||||
|
int same_contents;
|
||||||
|
|
||||||
data = diffstat_add(diffstat, name_a, name_b);
|
data = diffstat_add(diffstat, name_a, name_b);
|
||||||
|
|
||||||
@ -2407,10 +2411,17 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
same_contents = !hashcmp(one->sha1, two->sha1);
|
||||||
|
|
||||||
if (diff_filespec_is_binary(one) || diff_filespec_is_binary(two)) {
|
if (diff_filespec_is_binary(one) || diff_filespec_is_binary(two)) {
|
||||||
data->is_binary = 1;
|
data->is_binary = 1;
|
||||||
data->added = diff_filespec_size(two);
|
if (same_contents) {
|
||||||
data->deleted = diff_filespec_size(one);
|
data->added = 0;
|
||||||
|
data->deleted = 0;
|
||||||
|
} else {
|
||||||
|
data->added = diff_filespec_size(two);
|
||||||
|
data->deleted = diff_filespec_size(one);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (complete_rewrite) {
|
else if (complete_rewrite) {
|
||||||
@ -2420,7 +2431,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
|
|||||||
data->added = count_lines(two->data, two->size);
|
data->added = count_lines(two->data, two->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else if (!same_contents) {
|
||||||
/* Crazy xdl interfaces.. */
|
/* Crazy xdl interfaces.. */
|
||||||
xpparam_t xpp;
|
xpparam_t xpp;
|
||||||
xdemitconf_t xecfg;
|
xdemitconf_t xecfg;
|
||||||
|
@ -8,23 +8,52 @@ test_description='Test mode change diffs.
|
|||||||
'
|
'
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
test_expect_success \
|
sed_script='s/\(:100644 100755\) \('"$_x40"'\) \2 /\1 X X /'
|
||||||
'setup' \
|
|
||||||
'echo frotz >rezrov &&
|
|
||||||
git update-index --add rezrov &&
|
|
||||||
tree=`git write-tree` &&
|
|
||||||
echo $tree'
|
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success 'setup' '
|
||||||
'chmod' \
|
echo frotz >rezrov &&
|
||||||
'test_chmod +x rezrov &&
|
git update-index --add rezrov &&
|
||||||
git diff-index $tree >current'
|
tree=`git write-tree` &&
|
||||||
|
echo $tree
|
||||||
|
'
|
||||||
|
|
||||||
sed -e 's/\(:100644 100755\) \('"$_x40"'\) \2 /\1 X X /' <current >check
|
test_expect_success 'chmod' '
|
||||||
echo ":100644 100755 X X M rezrov" >expected
|
test_chmod +x rezrov &&
|
||||||
|
git diff-index $tree >current &&
|
||||||
|
sed -e "$sed_script" <current >check &&
|
||||||
|
echo ":100644 100755 X X M rezrov" >expected &&
|
||||||
|
test_cmp expected check
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success 'prepare binary file' '
|
||||||
'verify' \
|
git commit -m rezrov &&
|
||||||
'test_cmp expected check'
|
printf "\00\01\02\03\04\05\06" >binbin &&
|
||||||
|
git add binbin &&
|
||||||
|
git commit -m binbin
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success '--stat output after text chmod' '
|
||||||
|
test_chmod -x rezrov &&
|
||||||
|
echo " 0 files changed" >expect &&
|
||||||
|
git diff HEAD --stat >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success '--shortstat output after text chmod' '
|
||||||
|
git diff HEAD --shortstat >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success '--stat output after binary chmod' '
|
||||||
|
test_chmod +x binbin &&
|
||||||
|
echo " 0 files changed" >expect &&
|
||||||
|
git diff HEAD --stat >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success '--shortstat output after binary chmod' '
|
||||||
|
git diff HEAD --shortstat >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user