From: Jeff King <peff@peff.net>
To: Kai Hendry <hendry@iki.fi>
Cc: git@vger.kernel.org
Subject: Re: Graph sloc tool for git repos
Date: Sun, 13 Mar 2016 22:50:53 -0400 [thread overview]
Message-ID: <20160314025052.GB19753@sigill.intra.peff.net> (raw)
In-Reply-To: <20160314023545.GA19753@sigill.intra.peff.net>
On Sun, Mar 13, 2016 at 10:35:45PM -0400, Jeff King wrote:
> 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
790437
I'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
prev parent reply other threads:[~2016-03-14 2:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-12 11:00 Graph sloc tool for git repos Kai Hendry
2016-03-14 2:35 ` Jeff King
2016-03-14 2:50 ` Jeff King [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160314025052.GB19753@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=hendry@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).