时间:2021-07-01 10:21:17 帮助过:8人阅读
一部分为实际统计计算部分,代码如下:
- #!/bin/bash
- # 按照cdc.txt 中定义的目录统计个项目的总提交次数、增加、删除、留存代码行数
- # 统计按照自然月进行或者指定时段进行 $1 为月份(1-12)
- ### 当前目录###
- if [ $(echo $0 | grep '^/') ]; then
- cur_dir=$(dirname $0)
- else
- cur_dir=$(pwd)/$(dirname $0)
- fi
- ### 定义使用文件###
- repo_file=$cur_dir/cdc.txt #定义版本库目录文件
- everyone_file=$cur_dir/every.txt
- goluk_file=$cur_dir/goluk.csv
- ### 接收月份参数###
- Month=$1
- :>$goluk_file
- while read name project_dir
- do
- echo $name |awk '{printf "%-20s%1s%10s%1s%10s%1s%10s%1s%10s\n",$1, \
- "," , "提交次数" , "," , "增加代码" , "," , "减少代码" , "," , "留存代码"}' >> $goluk_file
- everyone_file=$cur_dir/$project_dir/every.txt
- ### 汇总计算各人的代码行数
- ### 删除空行
- awk '!/^$/' $everyone_file |\
- ### 计算
- awk '{if($1 ~ /^[a-zA-Z]+$/) {if(NR==1){printf "%20s",$1 }else {printf "\n%20s%8d%8d",$1,adds,dels;adds=0;dels=0}} \
- else{adds=adds+$1;dels=dels+$2;next} }' |\
- ### 汇总
- 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
最后一部分脚本,是首次git clone版本库用的
- #!/bin/bash
- # 统计后台的总的提交次数、增加、删除、留存代码行数
- # 统计按照自然月进行或者指定时段进行 $1 为月份(1-12)
- #### 定义分支 ####
- if [ $2 = "" ] ; then
- Branch=develop
- else
- Branch=$2
- fi
- #### 定义版本库 ####
- #git_repo=cdc.txt
- ### 当前目录###
- if [ $(echo $0 | grep '^/') ]; then
- cur_dir=$(dirname $0)
- else
- cur_dir=$(pwd)/$(dirname $0)
- fi
- ### 定义使用文件###
- 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
- ### 接收月份参数###
- Month=$1
- ### 初始化中间文件###
- :>$commit_file
- :>$detail_file
- :>$everyone_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
- }
- ### 代码提交行数
- 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
- # 统计各版本总行数
- git log --author=^.* --pretty=tformat: --numstat --since=2016-$Month-01 --until=2016-$Month-31 |\
- awk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } \
- 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
- # 记录各人代码、增加行数、删除行数明细
- 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
- ### 计算总提交次数
- awk '{sum[$2]+=$1}END{for(i in sum)print i ,sum[i]}' $commit_file |sort -k2 -nr > $total_file
- Codelines $Month
- ### 汇总提交数
- awk '{cnt+=$2}END{printf "%-20d%10d\n",Mon,cnt}' Mon=$Month $total_file
- ### 汇总代码行数
- #awk '{adds+=$1;removes+=$2;saves+=$3}END{print adds,removes,saves}' $detail_file
- ### 汇总计算各人的代码行数
- ### 删除空行
- awk '!/^$/' $everyone_file |\
- ### 计算
- awk '{if($1 ~ /^[a-zA-Z]+$/) {if(NR==1){printf "%20s",$1 }else {printf "\n%20s%8d%8d",$1,adds,dels;adds=0;dels=0}} \
- else{adds=adds+$1;dels=dels+$2;next} }' |\
- ### 汇总
- 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]}'
- #!/bin/bash
- #### 定义分支 ####
- Branch=release
- #### 定义版本库 ####
- git_repo=cdc.txt
- while read repo
- do
- git clone $repo
- done < $git_repo
- git@1.1.1.1:users/p1/cdc/authority
- git@1.1.1.1:users/p2/cdc/business
- .
- ├── GetStat.sh #第一部分脚本
- ├── android #项目目录
- │ ├── GetAllByMon.sh #第二部分脚本
- │ ├── cdc.txt #本项目源码的git地址
- │ ├── commit.txt
- │ ├── detail.txt
- │ ├── every.txt
- │ ├── total.txt
- │ └── workspace-goluk #项目源码
- ├── cdc.txt # 项目名称和目录文件,以空格分隔
- ├── 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.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1103185.htmlTechArticle统计Git版本库每个人提交次数和代码的增加和删除行数脚本 一、简单说明 基于git log的输出统计; 按照月份统计,当然稍微改动也可以按照...