栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

shell脚本按时间统计git代码量

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

shell脚本按时间统计git代码量

shell脚本按时间统计git代码量

统计代码的shell脚本,可按时间统计,可按作者统计,注释都有,请各位看官按需使用,后续会将python脚本写完奉上

脚本来了
  1. 按时间统计代码今年代码的增量,减量,和剩余量,不多说,直接上脚本
#!/bin/bash


################################
# function: getCodeCount()
# usage: getCodeCount dir
# param:
#   dir就是目录名称
################################

# 获取代码今年代码的增量,减量,和剩余量
getCodeCount() {
    cd ${dir}
    echo ${dir} >> /root/count.txt
    git log --since==2021-01-01 --until=2021-12-31  --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total year lines: %sn", add, subs, loc }' >> /root/count.txt
    git log  --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "total lines: %sn", loc }' >> /root/count.txt
    cd ..
}




##################################
# usage: sh codeCount.sh
# comments: 需要在项目代码的最外层目录中执行
##################################

# 获取当前所有项目的目录名称
for dir in `ls`
do
    if [ -d $dir ];then
        echo $dir
        getCodeCount $dir
    fi
done
  1. 按照作者统计时间内代码的增量和总量
#!/bin/bash


###############################
# function: yearCodeCountByAuthor()
# usage: codeCountByAuthor name
# param: 
#   name: 是git中解析出来的作者
##############################

# 获取2021年每个作者所提交代码的量
yearCodeCountByAuthor() {
    git log --author=$1 --since==2021-01-01 --until=2021-12-31 --pretty=tformat: --numstat | grep -E '.java|.xml|.vue|.html|.js|.css|.cs|.h|.m|.swift' | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total year lines: %sn", add, subs, loc }' >> /root/countByAuthor.txt
}


###############################
# function: codeCountByAuthor()
# usage: codeCountByAuthor name
# param: 
#   name: 是git中解析出来的作者
##############################

# 获取每个作者所提交的代码总量
codeCountByAuthor() {
    git log --author=$1 --pretty=tformat: --numstat | grep -E '.java|.xml|.vue|.html|.js|.css|.cs|.h|.m|.swift' | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "total lines: %sn", loc }' >> /root/countByAuthor.txt
}


################################
# function: getCodeCount()
# usage: getCodeCount dir
# param:
#   dir就是目录名称
################################

# 获取代码中的所有作者
getCodeCount() {
    cd ${dir}
    git log --format='%aN' | sort -u | while read name
        do
            echo -en "${dir}t" >> /root/countByAuthor.txt
            echo -en "$namet" >> /root/countByAuthor.txt 
            yearCodeCountByAuthor $name
        done
    cd ..
}




##################################
# usage: sh codeCount.sh
# comments: 需要在项目代码的最外层目录中执行
##################################

# 获取当前所有项目的目录名称
for dir in `ls`
do
    if [ -d $dir ];then
        echo $dir
        getCodeCount $dir
    fi
done
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1011345.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号