2008.04.20
Assigning Responsibility
Over the past few days I worked over a large code body correcting various accumulated errors and style digressions. When I finished I wanted to see who wrote the original lines. (It turned out I was not entirely innocent.)
I therefore wrote the following shell script. When run in a local CVS directory with uncommitted code it will go through all changed lines and will assign those lines to the last persons who edited them. It will then report how many of those fixed lines were written by each developer.
#!/bin/sh
# Obtain modified files and line numbers
cvs diff -rHEAD "--old-line-format=%dn%c'\012'" --new-line-format= --unchanged-line-format= |
sed -n '
1i\
echo '\''
# Run cvs annotate on each file
/^diff/ {
s/.* /cvs annotate /
s/$/ |\
awk '\''\
/
p
}
# For each changed line print the name of its last committer
/^[0-9]/ {
s/^/FNR == /
s/$/ {print substr($2, 2, 256) }/
p
}
# Terminate the awk scripts
$a\
'\''
/^Index/a\
'\''' |
sh |
sort |
uniq -c