1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-09 13:46:08 +02:00

Merge branch 'jk/diff-cc-stat-fixes'

"git diff --color-moved --cc --stat -p" did not work well due to
funny interaction between a bug in color-moved and the rest, which
has been fixed.

* jk/diff-cc-stat-fixes:
  combine-diff: treat --dirstat like --stat
  combine-diff: treat --summary like --stat
  combine-diff: treat --shortstat like --stat
  combine-diff: factor out stat-format mask
  diff: clear emitted_symbols flag after use
  t4006: resurrect commented-out tests
This commit is contained in:
Junio C Hamano 2019-02-05 14:26:17 -08:00
commit 5d2710bd3c
8 changed files with 147 additions and 30 deletions

View File

@ -1321,6 +1321,14 @@ static const char *path_path(void *obj)
return path->path;
}
/*
* Diff stat formats which we always compute solely against the first parent.
*/
#define STAT_FORMAT_MASK (DIFF_FORMAT_NUMSTAT \
| DIFF_FORMAT_SHORTSTAT \
| DIFF_FORMAT_SUMMARY \
| DIFF_FORMAT_DIRSTAT \
| DIFF_FORMAT_DIFFSTAT)
/* find set of paths that every parent touches */
static struct combine_diff_path *find_paths_generic(const struct object_id *oid,
@ -1342,8 +1350,7 @@ static struct combine_diff_path *find_paths_generic(const struct object_id *oid,
* show stat against the first parent even when doing
* combined diff.
*/
int stat_opt = (output_format &
(DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT));
int stat_opt = output_format & STAT_FORMAT_MASK;
if (i == 0 && stat_opt)
opt->output_format = stat_opt;
else
@ -1470,8 +1477,7 @@ void diff_tree_combined(const struct object_id *oid,
* show stat against the first parent even
* when doing combined diff.
*/
stat_opt = (opt->output_format &
(DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT));
stat_opt = opt->output_format & STAT_FORMAT_MASK;
if (stat_opt) {
diffopts.output_format = stat_opt;
@ -1515,8 +1521,7 @@ void diff_tree_combined(const struct object_id *oid,
show_raw_diff(p, num_parent, rev);
needsep = 1;
}
else if (opt->output_format &
(DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT))
else if (opt->output_format & STAT_FORMAT_MASK)
needsep = 1;
else if (opt->output_format & DIFF_FORMAT_CALLBACK)
handle_combined_callback(opt, paths, num_parent, num_paths);

4
diff.c
View File

@ -5962,8 +5962,10 @@ static void diff_flush_patch_all_file_pairs(struct diff_options *o)
for (i = 0; i < esm.nr; i++)
free((void *)esm.buf[i].line);
esm.nr = 0;
o->emitted_symbols = NULL;
}
esm.nr = 0;
}
void diff_flush(struct diff_options *options)

View File

@ -32,28 +32,37 @@ test_expect_success 'prepare binary file' '
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_i18ncmp expect actual
# '
#
# test_expect_success '--shortstat output after text chmod' '
# git diff HEAD --shortstat >actual &&
# test_i18ncmp 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_i18ncmp expect actual
# '
#
# test_expect_success '--shortstat output after binary chmod' '
# git diff HEAD --shortstat >actual &&
# test_i18ncmp expect actual
# '
test_expect_success '--stat output after text chmod' '
test_chmod -x rezrov &&
cat >expect <<-\EOF &&
rezrov | 0
1 file changed, 0 insertions(+), 0 deletions(-)
EOF
git diff HEAD --stat >actual &&
test_i18ncmp expect actual
'
test_expect_success '--shortstat output after text chmod' '
tail -n 1 <expect >expect.short &&
git diff HEAD --shortstat >actual &&
test_i18ncmp expect.short actual
'
test_expect_success '--stat output after binary chmod' '
test_chmod +x binbin &&
cat >expect <<-EOF &&
binbin | Bin
rezrov | 0
2 files changed, 0 insertions(+), 0 deletions(-)
EOF
git diff HEAD --stat >actual &&
test_i18ncmp expect actual
'
test_expect_success '--shortstat output after binary chmod' '
tail -n 1 <expect >expect.short &&
git diff HEAD --shortstat >actual &&
test_i18ncmp expect.short actual
'
test_done

View File

@ -98,6 +98,12 @@ test_expect_success setup '
git commit -m "update mode" &&
git checkout -f master &&
# Same merge as master, but with parents reversed. Hide it in a
# pseudo-ref to avoid impacting tests with --all.
commit=$(echo reverse |
git commit-tree -p master^2 -p master^1 master^{tree}) &&
git update-ref REVERSE $commit &&
git config diff.renames false &&
git show-branch
@ -239,6 +245,8 @@ diff-tree --cc --stat --summary master
# stat summary should show the diffstat and summary with the first parent
diff-tree -c --stat --summary side
diff-tree --cc --stat --summary side
diff-tree --cc --shortstat master
diff-tree --cc --summary REVERSE
# improved by Timo's patch
diff-tree --cc --patch-with-stat master
# improved by Timo's patch
@ -350,6 +358,7 @@ diff --line-prefix=abc master master^ side
diff --dirstat master~1 master~2
diff --dirstat initial rearrange
diff --dirstat-by-file initial rearrange
diff --dirstat --cc master~1 master
# No-index --abbrev and --no-abbrev
diff --raw initial
:noellipses diff --raw initial

View File

@ -0,0 +1,4 @@
$ git diff-tree --cc --shortstat master
59d314ad6f356dd08601a4cd5e530381da3e3c64
2 files changed, 5 insertions(+)
$

View File

@ -0,0 +1,6 @@
$ git diff-tree --cc --summary REVERSE
2562325a7ee916efb2481da93073b82cec801cbc
create mode 100644 file1
delete mode 100644 file2
delete mode 100644 file3
$

View File

@ -0,0 +1,3 @@
$ git diff --dirstat --cc master~1 master
40.0% dir/
$

79
t/t4066-diff-emit-delay.sh Executable file
View File

@ -0,0 +1,79 @@
#!/bin/sh
test_description='test combined/stat/moved interaction'
. ./test-lib.sh
# This test covers a weird 3-way interaction between "--cc -p", which will run
# the combined diff code, along with "--stat", which will be computed as a
# first-parent stat during the combined diff, and "--color-moved", which
# enables the emitted_symbols list to store the diff in memory.
test_expect_success 'set up history with a merge' '
test_commit A &&
test_commit B &&
git checkout -b side HEAD^ &&
test_commit C &&
git merge -m M master &&
test_commit D
'
test_expect_success 'log --cc -p --stat --color-moved' '
cat >expect <<-\EOF &&
commit D
---
D.t | 1 +
1 file changed, 1 insertion(+)
diff --git a/D.t b/D.t
new file mode 100644
index 0000000..1784810
--- /dev/null
+++ b/D.t
@@ -0,0 +1 @@
+D
commit M
B.t | 1 +
1 file changed, 1 insertion(+)
commit C
---
C.t | 1 +
1 file changed, 1 insertion(+)
diff --git a/C.t b/C.t
new file mode 100644
index 0000000..3cc58df
--- /dev/null
+++ b/C.t
@@ -0,0 +1 @@
+C
commit B
---
B.t | 1 +
1 file changed, 1 insertion(+)
diff --git a/B.t b/B.t
new file mode 100644
index 0000000..223b783
--- /dev/null
+++ b/B.t
@@ -0,0 +1 @@
+B
commit A
---
A.t | 1 +
1 file changed, 1 insertion(+)
diff --git a/A.t b/A.t
new file mode 100644
index 0000000..f70f10e
--- /dev/null
+++ b/A.t
@@ -0,0 +1 @@
+A
EOF
git log --format="commit %s" --cc -p --stat --color-moved >actual &&
test_cmp expect actual
'
test_done