info-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CVS Statistics


From: Paul Sander
Subject: Re: CVS Statistics
Date: Mon, 26 Nov 2001 12:53:40 -0800

--- Forwarded mail from address@hidden

>I would like to know the statistics on a particular file ( say test.c
>) from one version to another version ( say from 1.2 to 1.7 ).

>So for instance if i run the command/script 
><cvs_command> -R1.2 -R2.7 test.c 
>i would like to know the number of lines added, deleted and modified
>between version 1.2 to 1.7 for test.c

--- End of forwarded message from address@hidden

The script below produces a report of lines added/changed/modified between
two files.  You can either apply the script for each successive delta or
apply it to the two end versions.  The second application will generally
show fewer changes than the sum of changes reported for the intermediate
deltas.

If you delete everything from the "diff" command up to the top, then you
pipe the output of "cvs diff" into the report generator and save yourself
some steps.

Be aware that using line counts alone is not a good metric; they are inexact
to begin with and they're very easy to manipulate.  To measure code quality
and productivity you need several good metrics.


#!/bin/sh

file1="$1"
file2="$2"

# Count lines in the given file, write to stdout

mywc() {
        wc -l "$1" |
        sed -e 's/^[    ]*//' -e 's/[   ].*$//'
}

# Count lines in first file

lines=`mywc "$file1"`
echo "Lines of code in ${file1}:  $lines"

# Count lines in second file

lines=`mywc "$file2"`
echo "Lines of code in ${file2}:  $lines"

# Lines added/removed/modified computed from difference

diff "$file1" "$file2" |

# Delete the meat, keep just the add/rm/chg commands and line numbers

grep -v "^[<>-]" |

# Normalize diff's report to Start,EndCmdStart,End

sed -e 's/^\([0-9]*\)\([^0-9,]\)/\1,\1\2/' \
    -e 's/\([^0-9,]\)\([0-9]*\)$/\1\2,\2/' |

# Space-separate all of the data

sed -e 's/,/ /g' -e 's/\([^0-9, ]\)/ \1 /' |

# Write the report

awk '
BEGIN {
        add = 0         # count inserted lines
        rm = 0          # count deleted lines
        chg = 0         # count modified lines
        chgadd = 0      # count lines added via modification
        chgrm = 0       # count lines deleted via modification
}
$3 == "a" { add += $5 - $4 + 1; next }
$3 == "d" { rm += $2 - $1 + 1; next }
$3 == "c" {
                        chg += $2 - $1 + 1
                        delta = ( $5 - $4 ) - ( $2 - $1 )
                        if ( delta < 0 ) {
                                chgrm -= delta
                        } else {
                                chgadd += delta
                        }
                        next
                }
{ print "Don'"'"'t know how to handle this:  $0" }
END {
        totadd = add + chgadd
        totrm = rm + chgrm
        print "Lines added:  " totadd " (" add " inserted, " chgadd " added by 
mod)"
        print "Lines deleted:  " totrm " (" rm " deleted, " chgrm " removed by 
mod)"
        print "Lines changed:  " chg " (" chgadd " added, " chgrm " deleted)"
}
'




reply via email to

[Prev in Thread] Current Thread [Next in Thread]