Statistics git repository Everyone commits and code increases and deletes the number of rows script _php tutorial

Source: Internet
Author: User

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:
 
  1. #!/bin/bash
  2. # count The total commits, additions, deletions, and retained lines of code for each item according to the directory defined in Cdc.txt
  3. # The statistics are based on the natural month or the specified time period for the month (1-12)
  4. # # # current Directory # # #
  5. If [$ (echo $ | grep ' ^/')]; Then
  6. cur_dir=$ (dirname)
  7. Else
  8. cur_dir=$ (PWD)/$ (dirname)
  9. Fi
  10. # # # definition using File # # #
  11. repo_file= $cur _dir/cdc.txt #定义版本库目录文件
  12. everyone_file= $cur _dir/every.txt
  13. goluk_file= $cur _dir/goluk.csv
  14. # # # receive month parameter # # #
  15. Month=$1
  16. :> $goluk _file
  17. While read name Project_dir
  18. Do
  19. echo $name |awk ' {printf '%-20s%1s%10s%1s%10s%1s%10s%1s%10s\n ', $, \
  20. ",", "number of commits", ",", "Add Code", ",", "Reduce Code", ",", "Retention Code"} ' >> $goluk _file
  21. everyone_file= $cur _dir/$project _dir/every.txt
  22. # # # Rollup calculates the number of individual lines of code
  23. # # # Delete empty lines
  24. awk '!/^$/' $everyone _file |\
  25. # # Calculation
  26. awk ' {if ($/^[a-za-z]+$/) {if (nr==1) {printf "%20s",}else {printf "\n%20s%8d%8d", $1,adds,dels;adds=0;dels=0}} \
  27. Else{adds=adds+$1;dels=dels+$2;next}} ' |\
  28. # # Summary
  29. 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 ", \
  30. Name[i], ",", Cnt[i], ",", Adds[i], ",", Dels[i], ",", Adds[i]-dels[i]} ' >> $goluk _file
  31. Done < $repo _file
Part of the actual statistical calculation section, the code is as follows:

 
  1. #!/bin/bash
  2. # count the total number of commits, additions, deletions, and retained lines of code in the background
  3. # The statistics are based on the natural month or the specified time period for the month (1-12)
  4. # # # define Branch # # #
  5. if [$ = ""]; Then
  6. Branch=develop
  7. Else
  8. Branch=$2
  9. Fi
  10. # # # define Repository # # # # #
  11. #git_repo =cdc.txt
  12. # # # current Directory # # #
  13. If [$ (echo $ | grep ' ^/')]; Then
  14. cur_dir=$ (dirname)
  15. Else
  16. cur_dir=$ (PWD)/$ (dirname)
  17. Fi
  18. # # # definition using File # # #
  19. repo_file= $cur _dir/cdc.txt #版本库定义
  20. commit_file= $cur _dir/commit.txt #提交次数明细
  21. total_file= $cur _dir/total.txt #每人提交次数汇总
  22. detail_file= $cur _dir/detail.txt #每人提交行数明细
  23. everyone_file= $cur _dir/every.txt
  24. # # # receive month parameter # # #
  25. Month=$1
  26. # # # Initialize Intermediate file # # #
  27. :> $commit _file
  28. :> $detail _file
  29. :> $everyone _file
  30. # # # First count the number of commits each person, recorded in the intermediate file
  31. function Count () {
  32. While Read Git_url
  33. Do
  34. Echo $git _url
  35. Goluk_repo= ' echo $git _url |awk-f/' {print $NF} '
  36. CD $goluk _repo
  37. git checkout $Branch
  38. Git pull
  39. git log--pretty= '%an '--since ==2016-$Month -01--until=2016-$Month-31 | Sort | uniq-c | Sort-k1-n-R >> $commit _file
  40. Cd.. /
  41. Done < $repo _file
  42. }
  43. # # # code Submission line number
  44. function Codelines () {
  45. While Read Git_url
  46. Do
  47. Echo $git _url
  48. Goluk_repo= ' echo $git _url |awk-f/' {print $NF} '
  49. CD $goluk _repo
  50. Git pull
  51. git checkout $Branch
  52. # Count Each version of the total number of rows
  53. git log--author=^.*--pretty=tformat:--numstat--since=2016-$Month -01--until=2016-$Month-31 |\
  54. awk ' {add + = $ '; subs + = $; loc + $-$-$} \
  55. END {print add,subs,loc, repo_name} ' repo_name= $goluk _repo->> $detail _file
  56. # # Debug Begin
  57. # # #git Log--author=^.*--pretty=tformat:%an--numstat--since=2016-$Month -01--until=2016-$Month-31 |\
  58. # # awk '!/^$/' >> $cur _dir/every2.txt
  59. # # Debug End
  60. # Record Each person's code, increase the number of lines, delete the line count details
  61. git log--pretty= ' Tformat:%an '--numstat--since=2016-$Month -01--until=2016-$Month -31 >> $everyone _file
  62. Cd.. /
  63. Done < $repo _file
  64. }
  65. #awk ' {sum[$2]+=$1}end{for (i in sum) print I, Sum[i]} ' scrope.txt |sort-k2-nr >
  66. Count $Month
  67. # # # Total Submissions Count
  68. awk ' {sum[$2]+=$1}end{for (i in sum) print I, Sum[i]} ' $commit _file |sort-k2-nr > $total _file
  69. Codelines $Month
  70. # # # Rollup Submissions
  71. awk ' {cnt+=$2}end{printf '%-20d%10d\n ', mon,cnt} ' mon= $Month $total _file
  72. # # # Total lines of code
  73. #awk ' {adds+=$1;removes+=$2;saves+=$3}end{print adds,removes,saves} ' $detail _file
  74. # # # Rollup calculates the number of individual lines of code
  75. # # # Delete empty lines
  76. awk '!/^$/' $everyone _file |\
  77. # # Calculation
  78. awk ' {if ($/^[a-za-z]+$/) {if (nr==1) {printf "%20s",}else {printf "\n%20s%8d%8d", $1,adds,dels;adds=0;dels=0}} \
  79. Else{adds=adds+$1;dels=dels+$2;next}} ' |\
  80. # # Summary
  81. 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.


 
  
  1. #!/bin/bash
  2. # # # define Branch # # #
  3. Branch=release
  4. # # # define Repository # # # # #
  5. Git_repo=cdc.txt
  6. While read repo
  7. Do
  8. git clone $repo
  9. 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

 
  
  1. Git@1.1.1.1:users/p1/cdc/authority
  2. Git@1.1.1.1:users/p2/cdc/business

4, about the multi-project statistical directory structure



 
  
  1. .

  2. ├──getstat.sh #第一部分脚本
  3. ├──android #项目目录
  4. │├──getallbymon.sh #第二部分脚本
  5. │├──cdc.txt #本项目源码的git地址
  6. │├──commit.txt
  7. │├──detail.txt
  8. │├──every.txt
  9. │├──total.txt
  10. │└──workspace-goluk #项目源码

  11. ├──cdc.txt # project name and catalog file, separated by spaces

  12. ├──firmware #结构同上目录
  13. │├──getallbymon.sh
  14. │├──getrepo.sh
  15. │├──cdc.txt
  16. │├──commit.txt
  17. │├──detail.txt
  18. │├──every.txt
  19. │├──goluk_src
  20. │├──s2l_linux_sdk
  21. │└──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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.