Statistics git repository each commit count and code increment and delete Row count script
A simple explanation
Output statistics based on git log;
According to the month statistics, of course, a slight change can be counted according to years;
Traversing all repositories, you can specify different branches at the time of the statistics.
Ii. contents of the script
The script is divided into three parts, part of which is formatted output, as follows:
- #!/bin/bash
- # count The total commits, additions, deletions, and retained lines of code for each item according to the directory defined in Cdc.txt
- # The statistics are based on the natural month or the specified time period for the month (1-12)
- # # # current Directory # # #
- If [$ (echo $ | grep ' ^/')]; Then
- cur_dir=$ (dirname)
- Else
- cur_dir=$ (PWD)/$ (dirname)
- Fi
- # # # definition using File # # #
- repo_file= $cur _dir/cdc.txt #定义版本库目录文件
- everyone_file= $cur _dir/every.txt
- goluk_file= $cur _dir/goluk.csv
- # # # receive month parameter # # #
- Month=$1
- :> $goluk _file
- While read name Project_dir
- Do
- echo $name |awk ' {printf '%-20s%1s%10s%1s%10s%1s%10s%1s%10s\n ', $, \
- ",", "number of commits", ",", "Add Code", ",", "Reduce Code", ",", "Retention Code"} ' >> $goluk _file
- everyone_file= $cur _dir/$project _dir/every.txt
- # # # Rollup calculates the number of individual lines of code
- # # # Delete empty lines
- awk '!/^$/' $everyone _file |\
- # # Calculation
- awk ' {if ($/^[a-za-z]+$/) {if (nr==1) {printf "%20s",}else {printf "\n%20s%8d%8d", $1,adds,dels;adds=0;dels=0}} \
- Else{adds=adds+$1;dels=dels+$2;next}} ' |\
- # # Summary
- awk ' {cnt[$1]++;name[$1]=$1;adds[$1]+=$2;dels[$1]+=$3}end{for (i in name) printf "%-20s%1s%10d%1s%10d%1s%10d%1s%10d\ n ", \
- Name[i], ",", Cnt[i], ",", Adds[i], ",", Dels[i], ",", Adds[i]-dels[i]} ' >> $goluk _file
- Done < $repo _file
Part of the actual statistical calculation section, the code is as follows:
- #!/bin/bash
- # count the total number of commits, additions, deletions, and retained lines of code in the background
- # The statistics are based on the natural month or the specified time period for the month (1-12)
- # # # define Branch # # #
- if [$ = ""]; Then
- Branch=develop
- Else
- Branch=$2
- Fi
- # # # define Repository # # # # #
- #git_repo =cdc.txt
- # # # current Directory # # #
- If [$ (echo $ | grep ' ^/')]; Then
- cur_dir=$ (dirname)
- Else
- cur_dir=$ (PWD)/$ (dirname)
- Fi
- # # # definition using File # # #
- repo_file= $cur _dir/cdc.txt #版本库定义
- commit_file= $cur _dir/commit.txt #提交次数明细
- total_file= $cur _dir/total.txt #每人提交次数汇总
- detail_file= $cur _dir/detail.txt #每人提交行数明细
- everyone_file= $cur _dir/every.txt
- # # # receive month parameter # # #
- Month=$1
- # # # Initialize Intermediate file # # #
- :> $commit _file
- :> $detail _file
- :> $everyone _file
- # # # First count the number of commits each person, recorded in the intermediate file
- function Count () {
- While Read Git_url
- Do
- Echo $git _url
- Goluk_repo= ' echo $git _url |awk-f/' {print $NF} '
- CD $goluk _repo
- git checkout $Branch
- Git pull
- git log--pretty= '%an '--since ==2016-$Month -01--until=2016-$Month-31 | Sort | uniq-c | Sort-k1-n-R >> $commit _file
- Cd.. /
- Done < $repo _file
- }
- # # # code Submission line number
- function Codelines () {
- While Read Git_url
- Do
- Echo $git _url
- Goluk_repo= ' echo $git _url |awk-f/' {print $NF} '
- CD $goluk _repo
- Git pull
- git checkout $Branch
- # Count Each version of the total number of rows
- git log--author=^.*--pretty=tformat:--numstat--since=2016-$Month -01--until=2016-$Month-31 |\
- awk ' {add + = $ '; subs + = $; loc + $-$-$} \
- END {print add,subs,loc, repo_name} ' repo_name= $goluk _repo->> $detail _file
- # # Debug Begin
- # # #git Log--author=^.*--pretty=tformat:%an--numstat--since=2016-$Month -01--until=2016-$Month-31 |\
- # # awk '!/^$/' >> $cur _dir/every2.txt
- # # Debug End
- # Record Each person's code, increase the number of lines, delete the line count details
- git log--pretty= ' Tformat:%an '--numstat--since=2016-$Month -01--until=2016-$Month -31 >> $everyone _file
- Cd.. /
- Done < $repo _file
- }
- #awk ' {sum[$2]+=$1}end{for (i in sum) print I, Sum[i]} ' scrope.txt |sort-k2-nr >
- Count $Month
- # # # Total Submissions Count
- awk ' {sum[$2]+=$1}end{for (i in sum) print I, Sum[i]} ' $commit _file |sort-k2-nr > $total _file
- Codelines $Month
- # # # Rollup Submissions
- awk ' {cnt+=$2}end{printf '%-20d%10d\n ', mon,cnt} ' mon= $Month $total _file
- # # # Total lines of code
- #awk ' {adds+=$1;removes+=$2;saves+=$3}end{print adds,removes,saves} ' $detail _file
- # # # Rollup calculates the number of individual lines of code
- # # # Delete empty lines
- awk '!/^$/' $everyone _file |\
- # # Calculation
- awk ' {if ($/^[a-za-z]+$/) {if (nr==1) {printf "%20s",}else {printf "\n%20s%8d%8d", $1,adds,dels;adds=0;dels=0}} \
- Else{adds=adds+$1;dels=dels+$2;next}} ' |\
- # # Summary
- awk ' {cnt[$1]++;name[$1]=$1;adds[$1]+=$2;dels[$1]+=$3}end{for (i in name) printf "%-20s%10d%10d%10d%10d\n", Name[i], Cnt[i],adds[i],dels[i],adds[i]-dels[i]} '
The last part of the script is for the first git clone version library.
- #!/bin/bash
- # # # define Branch # # #
- Branch=release
- # # # define Repository # # # # #
- Git_repo=cdc.txt
- While read repo
- Do
- git clone $repo
- Done < $git _repo
Third, the use of precautions
1, three parts independent into three script files better
2, the statistical machine must have all the version of the library Read permission, or can not clone.
3, the repository definition file format, the end of the file can not be left blank line
- Git@1.1.1.1:users/p1/cdc/authority
- Git@1.1.1.1:users/p2/cdc/business
4, about the multi-project statistical directory structure
- .
- ├──getstat.sh #第一部分脚本
- ├──android #项目目录
- │├──getallbymon.sh #第二部分脚本
- │├──cdc.txt #本项目源码的git地址
- │├──commit.txt
- │├──detail.txt
- │├──every.txt
- │├──total.txt
- │└──workspace-goluk #项目源码
- ├──cdc.txt # project name and catalog file, separated by spaces
- ├──firmware #结构同上目录
- │├──getallbymon.sh
- │├──getrepo.sh
- │├──cdc.txt
- │├──commit.txt
- │├──detail.txt
- │├──every.txt
- │├──goluk_src
- │├──s2l_linux_sdk
- │└──total.txt
http://www.bkjia.com/PHPjc/1103185.html www.bkjia.com true http://www.bkjia.com/PHPjc/1103185.html techarticle statistics git repository each commit count and code increment and delete Row count script one, simple description based on git log output statistics, according to the month statistics, of course, slightly change can also follow ...