Re: Graph sloc tool for git repos
- From
Jeff King <peff@peff.net>
- Date
- Mar 14, 2016, 02:50 UTC
- Message-ID
- <20160314025052.GB19753@sigill.intra.peff.net>
- In-Reply-To
- <20160314023545.GA19753@sigill.intra.peff.net>
On Sun, Mar 13, 2016 at 10:35:45PM -0400, Jeff King wrote:
Show 10 quoted lines
> Like (this is back on the "we resolved as master" version of my example, > to illustrate how the merge is shown): > > $ git log --first-parent -m --numstat --oneline > 4244c8a resolved > 1 1 file > b9bbaf9 side > 1 0 file > 09037ef base > 1 0 file
You'd probably want --reverse, of course, since the point is to build up the count in the same order as time flows.
So this is the working version I came up with:
git log --reverse --first-parent -m --format=%ct --numstat |
perl -lne '
if (/^\d+$/) {
if (defined $time) {
print "$time $total"
}
$time = $&;
} elsif (/^(\d+)\s+(\d+)\s/) {
$total += $1 - $2;
}
END {
# flush last entry
print "$time $total";
}
'For my git.git repo, the final line it produces is:
1457666843 789457
which should be the final sloc-count right now. If I count the lines in the lines in HEAD, it's close but not quite the same:
$ git ls-tree -r HEAD |
awk '{print $3}' |
xargs -n1 git cat-file blob |
wc -l
790437I'd guess that the difference comes from a few files which are treated as binary (and thus get "-" in their numstat output, but happen to have newlines which cause "wc" to increment its count).
-Peff