Re: Graph sloc tool for git repos

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

 



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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]