分享一个自己写的svn代码统计的脚本,不喜绕行:

统计项目每个人修改的文件的个数和行数

#!/bin/bash
# 统计项目每个人修改的文件的个数和行数

Svn_pro=http://192.168.1.1/svn/project

# 版本库最后修改的信息
Now_date=`date '+%F'`
next_date=`date -d "next day" +%Y-%m-%d`

#echo -e " 版本库最后修改信息: "
#svn info http://192.168.1.1/svn/project  --username  username --password password 2>/dev/null | awk 'NR>6 '
(( user_count=${#Svn_user[@]}-1 ))

# 修改的文件
#list_value=`svn diff -r {$Now_date}:{$next_date} --summarize http://192.168.1.1/svn/project  --username  username --password password | awk '{print $2}' `
list_value=`svn diff -r {$Now_date}:{$next_date} --summarize http://192.168.1.1/svn/project  --username  username --password password | awk '{print $2}' `
list=(`echo $list_value`)
(( count=${#list[@]}-1 ))
for i in `seq 0 $count`
do
    edit=`svn blame -r {$Now_date}:{$next_date}  ${list[$i]}  --username  username --password password | awk '{print $2}' | grep -v "-" | wc -l`
    if [ $edit -ne 0 ];then
    #echo -e "-----------------------------------------------------------------------------------------------" >> $0.log
    #echo -e "${list[$i]}文件增加行数:" >> $0.log
    #svn blame -r {$Now_date}:{$next_date}  ${list[$i]}  --username  username --password password | awk '{print $2}' | grep -v "-" | sort | uniq -c
    svn blame -r {$Now_date}:{$next_date}  ${list[$i]}  --username  username --password password | awk '{print $2}' | grep -v "-" | sort | uniq -c >> $0.log
    fi
done

#echo -e "Author\t\tTotal lines"
awk '{sum[$2]+=$1}END{for(c in sum){printf "%-16s%-10s\n",sum[c],c}}' $0.log  > total
#echo "--------------------------------------------------------"
#echo -e "Change file\tAuthor"
cat $0.log | awk '{print $2}' | sort | uniq -c > file

echo -e "Author Change_file Total_lines"
awk 'NR==FNR{a[i]=$0;i++}NR>FNR{print a[j]" "$0;j++}' total file | awk '{print $4,$3,$1}'

rm -f $0.log total file

统计代码修改的详情

#!/bin/bash
# 统计项目代码修改的详情
Svn_pro=http://192.168.1.1/svn/project

# 版本库最后修改的信息
Now_date=`date '+%F'`
next_date=`date -d "next day" +%Y-%m-%d`

#echo -e " 版本库最后修改信息: "
#svn info http://192.168.1.1/svn/project   --username  username --password password 2>/dev/null | awk 'NR>6 '
(( user_count=${#Svn_user[@]}-1 ))

# 修改的文件
#list_value=`svn diff -r {$Now_date}:{$next_date} --summarize http://192.168.1.1/svn/project   --username  xiaodx --password Pa@1234 | awk '{print $2}' `
list_value=`svn diff -r {$Now_date}:{$next_date} --summarize http://192.168.1.1/svn/project   --username  xiaodx --password Pa@1234 | awk '{print $2}' `
list=(`echo $list_value`)
(( count=${#list[@]}-1 ))
for i in `seq 0 $count`
do
    edit=`svn blame -r {$Now_date}:{$next_date}  ${list[$i]}  --username  xiaodx --password Pa@1234 | awk '{print $2}' | grep -v "-" | wc -l`
    if [ $edit -ne 0 ];then
#   echo -e "-----------------------------------------------------------------------------------------------"
#   echo -e "\033[36m ${list[$i]}t文件增加行数:\033[0m" >> $0.log
    echo -e "${list[$i]}文件增加行数:" >> $0.log
#   svn blame -r {$Now_date}:{$next_date}  ${list[$i]}  --username  xiaodx --password Pa@1234 | awk '{print $2}' | grep -v "-" | sort | uniq -c
    svn blame -r {$Now_date}:{$next_date}  ${list[$i]}  --username  xiaodx --password Pa@1234 | awk '{print $2}' | grep -v "-" | sort | uniq -c >> $0.log
    fi
done