svn log shell脚本

svn log展示的日志是统计信息一行注释另一行,不是很方便处理

首先需要将日志记录只显示一行

vi ~/.bashrc,增加以下代码,source ~/.bashrc

svnlog(){
    svn log "$@" | awk -f <(cat <<EOF
#!/usr/bin/awk -f

# Convert the "svn log" output into a one liner format, which is easier to grep
# or use in scripts. Pipe "svn log" into this script

# When we get a line that starts with a revision number, put the data in variables
/^r[0-9]+/ {
    rev=\$1
    user=\$3
    date=\$5
    time=\$6
    lines=13
}

# Anything that isn't a revision line, a separator line or an empty line
# will be part of the commit message. Concatenate these into the comment variable
! (/^r[0-9+]/ || /^-+$/ || /^$/) {
  comment = comment \$0
}

# With every separator line, output what we stored before and reset the comment variable
# To skip the first line we also check if we've already stored a revision
/^-+$/ && rev {
   print rev " | " user " | " date " | " time " | " comment
   comment = ""
}
EOF
)
}

然后,提取需要的字段,格式化为需要的文本

提取昨天的svn提交记录

datefrom=$(date -d "yesterday" +%Y-%m-%d)
dateto=$(date -d "now" +%Y-%m-%d)
svnlog -r {$datefrom}:{$dateto} SVNURL | sort -t ' ' -k 3 | awk -F '|' '{printf "%s|%s|%s|%s|%s\n",$1,$3,$4,$2,$5}'

image-20220402174053034

refer:

https://www.cnblogs.com/scue/p/4379669.html

posted @ 2022-04-06 17:15  天下太平  阅读(134)  评论(0编辑  收藏  举报