loc.sh - randomcrap - random crap programs of varying quality
(HTM) git clone git://git.codemadness.org/randomcrap
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
loc.sh (1381B)
---
1 #!/bin/sh
2 # count (rough) LOC from a git repository.
3 # writes to the files loc.csv and loc.png.
4
5 linecount() {
6 sort -k 2 | uniq -f 1 | while read -r commit date; do
7 printf '%s\t%s\t' "$date" "$commit"
8 git ls-tree --name-only -r "$commit" | \
9 grep -E 'Makefile|\.(c|h|sh|mk|cpp|cc|hh|js|css)$' | \
10 while read -r file; do
11 git show "$commit:$file" | wc -l
12 done | awk '{ l += int($0) } END { print l }'
13 done
14 }
15
16 # CSV of commits per tag.
17 csvtags() {
18 git tag -l | while read -r tag; do
19 # group by day
20 git log --pretty='format:%H %cd' --date="format:%Y-%m-%d" -1 "$tag" | \
21 linecount
22 done | \
23 sort -k 1,1 | \
24 tee loc.csv
25 }
26
27 # CSV of each commit.
28 csv() {
29 # group by day
30 git log --pretty='format:%H %cd' --date="format:%Y-%m-%d" | \
31 linecount | \
32 tee loc.csv
33 }
34
35 plot() {
36 # plot using GNU plot.
37 gnuplot - <<__EOF__
38 #set term png
39 #set terminal pngcairo enhanced font "Times New Roman,12.0" size 1600,1080
40 set terminal png enhanced font "monospace,12.0" size 1600,1080
41 set output "loc.png"
42
43 set title "bloat-o-meter"
44 set xlabel "Commit date"
45 set ylabel "LOC"
46
47 set xdata time
48 set format x "%Y-%m"
49 set timefmt "%Y-%m-%dT%H:%M:%S"
50
51 set xtics 2592000
52 set xtic rotate by 90 scale 0 right font ",8"
53 plot 'loc.csv' using 1:3 with lp notitle pointtype 5 pointsize 0.3
54
55 __EOF__
56 }
57
58 view() {
59 sxiv loc.png
60 }
61
62 if test x"$1" != x""; then
63 "$1"
64 else
65 csv
66 plot
67 view
68 fi