From: Junio C Hamano <hidden> Date: 2016-06-15 22:55:26
It turns out that there are at least two bugs in the diffstat
counting code. This series comes on top of the earlier 74faaa1 (Fix
"git diff --stat" for interesting - but empty - file changes,
2012-10-17) to fix them.
Junio C Hamano (5):
test: add failing tests for "diff --stat" to t4049
diff --stat: status of unmodified pair in diff-q is not zero
diff --stat: use "file" temporary variable to refer to data->files[i]
diff --stat: move the "total count" logic to the last loop
diff --stat: do not count "unmerged" entries
diff.c | 49 +++++++++++++++++++++++++---------------------
t/t4049-diff-stat-count.sh | 46 ++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 72 insertions(+), 23 deletions(-)
--
1.8.0.1.331.g808d2af
From: Junio C Hamano <hidden> Date: 2016-06-15 22:55:26
There are a few problems in diff.c around --stat area, partially
caused by the recent 74faaa1 (Fix "git diff --stat" for interesting
- but empty - file changes, 2012-10-17), and largely caused by the
earlier change that introduced when --stat-count was added.
Add a few test pieces to t4049 to expose the issues.
Signed-off-by: Junio C Hamano <redacted>
---
t/t4049-diff-stat-count.sh | 46 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)
@@ -4,12 +4,17 @@test_description='diff --stat-count' ../test-lib.sh-test_expect_successsetup'+test_expect_success'setup''>a&&>b&&>c&&>d&&gitaddabcd&&+gitcommit-minitial+'++test_expect_success'limit output to 2 (simple)''+gitreset--hard&&chmod+xcd&&echoa>a&&echob>b&&
@@ -23,4 +28,43 @@ test_expect_success setup 'test_i18ncmpexpectactual'+test_expect_failure'binary changes do not count in lines''+gitreset--hard&&+chmod+xcd&&+echoa>a&&+echob>b&&+cat"$TEST_DIRECTORY"/test-binary-1.png>d&&+cat>expect<<-\EOF+a|1++b|1++...+4fileschanged,2insertions(+)+EOF+gitdiff--stat--stat-count=2>actual&&+test_i18ncmpexpectactual+'++test_expect_failure'exclude unmerged entries from total file count''+gitreset--hard&&+echoa>a&&+echob>b&&+gitls-files-sa>x&&+gitrm-fd&&+forstagein123+do+sed-e"s/ 0 a/ $stage d/"x+done|+gitupdate-index--index-info&&+echod>d&&+chmod+xcd&&+cat>expect<<-\EOF+a|1++b|1++...+4fileschanged,3insertions(+)+EOF+gitdiff--stat--stat-count=2>actual&&+test_i18ncmpexpectactual+'+ test_done
From: Junio C Hamano <hidden> Date: 2016-06-15 22:55:26
It is spelled DIFF_STATUS_UNKNOWN these days, and is different from zero.
Signed-off-by: Junio C Hamano <redacted>
---
diff.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Junio C Hamano <hidden> Date: 2016-06-15 22:55:26
Even though we show a separate *UNMERGED* entry in the patch and
diffstat output (or in the --raw format, for that matter) in
addition to and separately from the diff against the specified stage
(defaulting to #2) for unmerged paths, they should not be counted in
the total number of files affected---that would lead to counting the
same path twice.
The separation done by the previous step makes this fix simple and
straightforward. Among the filepairs in diff_queue, paths that
weren't modified, and the extra "unmerged" entries do not count as
total number of files.
Signed-off-by: Junio C Hamano <redacted>
---
diff.c | 6 ++++--
t/t4049-diff-stat-count.sh | 2 +-
2 files changed, 5 insertions(+), 3 deletions(-)
@@ -44,7 +44,7 @@ test_expect_success 'binary changes do not count in lines' 'test_i18ncmpexpectactual'-test_expect_failure'exclude unmerged entries from total file count''+test_expect_success'exclude unmerged entries from total file count''gitreset--hard&&echoa>a&&echob>b&&
From: Junio C Hamano <hidden> Date: 2016-06-15 22:55:26
The generated code shouldn't change but it is easier to read.
Signed-off-by: Junio C Hamano <redacted>
---
diff.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
@@ -1470,8 +1470,8 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)for(i=0;(i<count)&&(i<data->nr);i++){structdiffstat_file*file=data->files[i];uintmax_tchange=file->added+file->deleted;-if(!data->files[i]->is_interesting&&-(change==0)){++if(!file->is_interesting&&(change==0)){count++;/* not shown == room for one more */continue;}
From: Junio C Hamano <hidden> Date: 2016-06-15 22:55:26
The diffstat generation logic, with --stat-count limit, is
implemented as three loops.
- The first counts the width necessary to show stats up to
specified number of entries, and notes up to how many entries in
the data we need to iterate to show the graph;
- The second iterates that many times to draw the graph, adjusts
the number of "total modified files", and counts the total
added/deleted lines for the part that was shown in the graph;
- The third iterates over the remainder and only does the part to
count "total added/deleted lines" and to adjust "total modified
files" without drawing anything.
Move the logic to count added/deleted lines and modified files from
the second loop to the third loop.
This incidentally fixes a bug. The third loop was not filtering
binary changes (counted in bytes) from the total added/deleted as it
should. The second loop implemented this correctly, so if a binary
change appeared earlier than the --stat-count cutoff, the code
counted number of added/deleted lines correctly, but if it appeared
beyond the cutoff, the number of lines would have mixed with the
byte count in the buggy third loop.
Signed-off-by: Junio C Hamano <redacted>
---
diff.c | 21 ++++++++++++---------
t/t4049-diff-stat-count.sh | 2 +-
2 files changed, 13 insertions(+), 10 deletions(-)
@@ -28,7 +28,7 @@ test_expect_success 'limit output to 2 (simple)' 'test_i18ncmpexpectactual'-test_expect_failure'binary changes do not count in lines''+test_expect_success'binary changes do not count in lines''gitreset--hard&&chmod+xcd&&echoa>a&&
From: Johannes Sixt <hidden> Date: 2016-06-15 22:55:27
From: Johannes Sixt <redacted>
The earlier change 74faaa16 (Fix "git diff --stat" for interesting - but
empty - file changes) needed to change the count of differing files
because the executable-bit changes of two empty files are now counted.
On file systems that do not record the executable bit, however, the old
file count was actually correct (and the updated tests fail) because the
mode change cannot be diagnosed by looking at the file system alone.
Change the mode not only on the file system, but also in the index;
compare the new state against the commit, so that the tests do not depend
on the file system's ability to record the executable bit, when possible.
The exception is the test for unmerged entries, which does depend on the
file system; we have to skip it.
Signed-off-by: Johannes Sixt <redacted>
---
Am 11/27/2012 22:21, schrieb Junio C Hamano:
It turns out that there are at least two bugs in the diffstat
counting code. This series comes on top of the earlier 74faaa1 (Fix
"git diff --stat" for interesting - but empty - file changes,
2012-10-17) to fix them.
The tests still fail on Windows. I am not sure whether there is a
difference in comparing the file system against the index or a commit.
If there is, then the updated tests might not test the same thing.
-- Hannes
t/t4049-diff-stat-count.sh | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
@@ -24,13 +24,13 @@ test_expect_success 'limit output to 2 (simple)' '...4fileschanged,2insertions(+)EOF-gitdiff--stat--stat-count=2>actual&&+gitdiff--stat--stat-count=2HEAD>actual&&test_i18ncmpexpectactual' test_expect_success'binary changes do not count in lines''gitreset--hard&&-chmod+xcd&&+test_chmod+xcd&&echoa>a&&echob>b&&cat"$TEST_DIRECTORY"/test-binary-1.png>d&&
@@ -40,11 +40,11 @@ test_expect_success 'binary changes do not count in lines' '...4fileschanged,2insertions(+)EOF-gitdiff--stat--stat-count=2>actual&&+gitdiff--stat--stat-count=2HEAD>actual&&test_i18ncmpexpectactual'-test_expect_success'exclude unmerged entries from total file count''+test_expect_successFILEMODE'exclude unmerged entries from total file count''gitreset--hard&&echoa>a&&echob>b&&
From: Antoine Pelisse <hidden> Date: 2016-06-15 22:55:28
Hi Junio,
That does make a lot of sense and I would have indeed missed a couple
of things here.
I've been thinking about that "Unmerged" line quite a lot, and I can't
get myself any good reason to keep it.
Would you mind taking a couple of minutes to make it clear ?
I feel like (but I can obviously be wrong):
1. The info is redundant. When performing a merge, all diffs (without
--staged flag) are unmerged
2. While status shows the line once, while diff shows the diff for the file
once, while diff --shortstat counts the file once, diff --stat shows two
lines for the file.
3. diff --numstat shows two lines for the same file. As a script
writer (I guess that's what it's meant for), I would definitely expect
uniqueness in third column/filenames.
Cheers,
Antoine
On Tue, Nov 27, 2012 at 10:21 PM, Junio C Hamano [off-list ref] wrote:
It turns out that there are at least two bugs in the diffstat
counting code. This series comes on top of the earlier 74faaa1 (Fix
"git diff --stat" for interesting - but empty - file changes,
2012-10-17) to fix them.
Junio C Hamano (5):
test: add failing tests for "diff --stat" to t4049
diff --stat: status of unmodified pair in diff-q is not zero
diff --stat: use "file" temporary variable to refer to data->files[i]
diff --stat: move the "total count" logic to the last loop
diff --stat: do not count "unmerged" entries
diff.c | 49 +++++++++++++++++++++++++---------------------
t/t4049-diff-stat-count.sh | 46 ++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 72 insertions(+), 23 deletions(-)
--
1.8.0.1.331.g808d2af