3 # Usage: Run 'contrib/coverage-diff.sh <version1> <version2>' from source-root
9 # while checked out at <version2>. This script combines the *.gcov files
10 # generated by the 'make' commands above with 'git diff <version1> <version2>'
11 # to report new lines that are not covered by the test suite.
20 # Hunk header? Grab the beginning in postimage.
21 if (/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/) {
26 # Have we seen a hunk? Ignore "diff --git" etc.
27 next unless defined $line_num;
29 # Deleted line? Ignore.
34 # Show only the line number of added lines.
38 # Either common context or added line appear in
39 # the postimage. Count it.
45 files=$(git diff --name-only "$V1" "$V2" -- \*.c)
52 git diff "$V1" "$V2" -- "$file" |
56 if ! test -s new_lines.txt
61 hash_file=$(echo $file | sed "s/\//\#/")
63 if ! test -s "$hash_file.gcov"
73 }' "$hash_file.gcov" |
74 sort >uncovered_lines.txt
76 comm -12 uncovered_lines.txt new_lines.txt |
78 sed -e 's/^/ /' >uncovered_new_lines.txt
80 grep -q '[^[:space:]]' <uncovered_new_lines.txt &&
81 echo $file >>coverage-data.txt &&
82 git blame -s "$V2" -- "$file" |
84 grep -f uncovered_new_lines.txt >>coverage-data.txt &&
85 echo >>coverage-data.txt
87 rm -f new_lines.txt uncovered_lines.txt uncovered_new_lines.txt
92 echo "Commits introducing uncovered code:"
94 commit_list=$(cat coverage-data.txt |
95 grep -E '^[0-9a-f]{7,} ' |
101 for commit in $commit_list
103 git log --no-decorate --pretty=format:'%an %h: %s' -1 $commit