1#!/bin/tcsh
2
3## This script counts up who is to 'blame' for lines of code/text in the AFNI
4## files. It runs for a long time (30+ minutes), running 'git blame' over
5## 1000+ files, and grepping out counts from each one for over a dozen
6## co-conspirators.
7## -- RWCox -- Sep 2019
8
9# set list of source files to query
10# stuff from outside sources (e.g., eispack, sonnets.h) is not included here
11
12if ( 1 ) then
13  set flist = ( af*.[ch] mri*.[ch] thd*.[ch] cs*.[ch] 3d*.[ch] edt*.[ch] suma*.[ch]     \
14                plug*.c niml/niml*.[ch] coxplot/*.[ch] SUMA/*.[ch] 1d*.[ch] model*.c    \
15                display.[ch] imseq.[ch] bbox.[ch] xim.[ch] xutil.[ch] xutil_webber.[ch] \
16                nifti_statlib.[ch] `find nifti -name '*.[ch]'`                          \
17                rickr/*.[ch] ptaylor/*.[ch] gifti/*.[ch] svm/*.[ch]                     \
18                `git ls-tree --name-only -r master | grep scripts_install`              \
19                `find discoraj -type f` `find shiny -type f -name '*.R'`                \
20                python_scripts/afnipy/*.py R_scripts/*.R                           \
21                ../tests/scripts/*.py ../tests/scripts/utils/*.py                         )
22else
23# for quicker testing
24  set flist = ( afni.c imseq.c )
25endif
26
27# run the Count Lines Of Code script, if present (this is fast)
28
29which cloc-1.64.pl >& /dev/null
30if ( $status == 0 ) then
31  cloc-1.64.pl --quiet $flist
32endif
33
34# list of authors needing only one alias (not case sensitive)
35
36set alist = ( Cox Craddock discoraj Froehlich Gang        \
37              Gaudes Glen Hammett Kaczmarzyk LeeJ3        \
38              Laconte Lisinski Clark Johnson Julia        \
39              Molfese Oosterhof Rick Schwabacher Warren Markello )
40
41# list of authors needing two aliases (i.e., troublemakers)
42
43set blist1 = ( Nielson      Saad Taylor  afniHQ )
44set blist2 = ( shotgunosine ziad mrneont Ubuntu )
45
46# tsum = total sum of lines
47set tsum = 0
48
49# nn = number of files processed
50set nn   = 0
51
52# counts for the alist
53set anum = $#alist
54set aqq  = ( `count -dig 1 1 $anum` )
55set asum = ( )
56foreach uuu ( $alist )
57  set asum = ( $asum 0 )
58end
59
60# counts for the blist
61set bnum = $#blist1
62set bqq  = ( `count -dig 1 1 $bnum` )
63set bsum = ( )
64foreach uuu ( $blist1 )
65  set bsum = ( $bsum 0 )
66end
67
68# grep option to remove known authors, to count unknowns
69
70set gunk = ( -v -i )
71foreach uuu ( $alist $blist1 $blist2 )
72  set gunk = ( $gunk -e $uuu )
73end
74
75# will acccumulate all unknown lines in to one file
76if( -f gsum.unk.txt ) \rm -f gsum.unk.txt
77touch gsum.unk.txt
78
79# loop over source files, plus README documents
80
81printf "\nblaming "
82
83set glist = ( $flist ../doc/README/README.* )
84foreach fff ( $glist )
85
86 # get the list of blamees for this file (grep out blank lines)
87  git blame $fff | grep -v '[0-9]) $' > gsum.junk.txt
88
89 # lines in this file
90  set aa = `wc -l < gsum.junk.txt` ; @ tsum += $aa
91
92 # loop over the alist and grep out count for each one
93  foreach qq ( $aqq )
94    set aa = `grep -i "$alist[$qq]" gsum.junk.txt | wc -l` ; @ asum[$qq] += $aa
95  end
96
97 # loop over the blist, and get their counts
98  foreach qq ( $bqq )
99    set aa = `grep -i -e "$blist1[$qq]" -e "$blist2[$qq]" gsum.junk.txt | wc -l` ; @ bsum[$qq] += $aa
100  end
101
102 # accumulate the lines with unknown authors
103  grep $gunk gsum.junk.txt >> gsum.unk.txt
104
105 # print a progress pacifier
106  @ nn ++ ; if( $nn % 20 == 0 ) printf "%d/%d " $nn $#glist
107
108end
109
110# cleanup after loop over files
111
112printf "... total line count = %d \n" $tsum
113\rm -f gsum.junk.txt
114touch gsum.junk.txt
115
116# count total number of unknown lines now
117
118set aa = `wc -l < gsum.unk.txt` ; @ unksum = $aa
119
120# format lines for the final report
121
122foreach qq ( $aqq )
123  if ( $asum[$qq] > 0 ) then
124    set perc  = `ccalc "100*$asum[$qq]/$tsum"`
125    printf " %12s  %6s  %5.2f%%\n" "$alist[$qq]" $asum[$qq] $perc >> gsum.junk.txt
126  endif
127end
128
129foreach qq ( $bqq )
130  if ( $bsum[$qq] > 0 ) then
131    set perc  = `ccalc "100*$bsum[$qq]/$tsum"`
132    printf " %12s  %6s  %5.2f%%\n" "$blist1[$qq]" $bsum[$qq] $perc >> gsum.junk.txt
133  endif
134end
135
136if ( $unksum > 0 ) then
137  set perc  = `ccalc "100*$unksum/$tsum"`
138  printf " %12s  %6s  %5.2f%%\n" Unknown $unksum $perc >> gsum.junk.txt
139endif
140
141# header lines to the final report
142
143echo " Contributor   Lines   %-age"    > gsum.out.txt
144echo " ------------  ------  ------"  >> gsum.out.txt
145
146# sort output lines by second column, put in final report
147
148sort -n -r --key=2 gsum.junk.txt      >> gsum.out.txt
149
150echo
151cat gsum.out.txt
152
153# toss out the junk
154
155\rm -f gsum.junk.txt
156
157exit 0
158