Count the number of times submitted by each Git version library and increase or delete the number of lines in the code. Script _ PHP Tutorial

Source: Internet
Author: User
Count the number of times each Git version Library submitted and the number of lines added or deleted by code. Count the number of times submitted by each Git version Library and the number of lines added or deleted by code. Script 1. simple description: gitlog-based output statistics. statistics are collected by month, of course, slightly changed scripts can also be used to count the number of times each Git version Library submitted and the number of lines added or deleted by code.
1. simple description
Git log-based output statistics;
The statistics are calculated by month. of course, the statistics can be calculated by year or month;
Traverse all version libraries and specify different branches during statistics.

II. script content
The script consists of three parts: formatted output, as follows:
 
 
  1. #! /Bin/bash
  2. # Count the total number of submissions, additions, deletions, and number of lines of code for each project according to the directory defined in cdc.txt
  3. # The statistics are calculated based on the calendar month or the specified time period. $1 is the month (1-12)
  4. ### Current directory ###
  5. If [$ (echo $0 | grep '^/')]; then
  6. Cur_dir = $ (dirname $0)
  7. Else
  8. Cur_dir = $ (pwd)/$ (dirname $0)
  9. Fi
  10. ### Define a user file ###
  11. Repo_file = $ cur_dir/cdc.txt # define the version library directory file
  12. Everyone_file = $ cur_dir/every.txt
  13. Goluk_file = $ cur_dir/goluk.csv
  14. ### Parameters for receiving months ###
  15. Month = $1
  16. :> $ Goluk_file
  17. While read name project_dir
  18. Do
  19. Echo $ name | awk '{printf "%-20 s % 1 s % 10 s % 1 s % 10 s % 1 s % 1 s % 10 s % 1 s % 10s \ n ", $1 ,\
  20. ",", "Submissions", "add code", "reduce code ",",", "Reserved code"} '> $ goluk_file
  21. Everyone_file = $ cur_dir/$ project_dir/every.txt
  22. ### Sum up and calculate the number of lines of code for each person
  23. ### Delete empty rows
  24. Awk '! /^ $/'$ Everyone_file | \
  25. ### Computing
  26. Awk '{if ($1 ~ /^ [A-zA-Z] + $/) {if (NR = 1) {printf "% 20 s ", $1} else {printf "\ n % 20 s % 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 "%-20 s % 1 s % 10d % 1 s % 10d % 1 s % 10d % 1 s % 1 s % 10d \ n ",\
  30. Name [I], ",", cnt [I], ",", adds [I], ",", dels [I], ",", adds [I]-dels [I]} '> $ goluk_file
  31. Done <$ repo_file
The code is as follows:

 
 
  1. #! /Bin/bash
  2. # Count the total number of submissions, additions, deletions, and number of reserved code lines in the background
  3. # The statistics are calculated based on the calendar month or the specified time period. $1 is the month (1-12)
  4. #### Define a branch ####
  5. If [$2 = ""]; then
  6. Branch = develop
  7. Else
  8. Branch = $2
  9. Fi
  10. #### Define a version Library ####
  11. Export git_repo1_cdc.txt
  12. ### Current directory ###
  13. If [$ (echo $0 | grep '^/')]; then
  14. Cur_dir = $ (dirname $0)
  15. Else
  16. Cur_dir = $ (pwd)/$ (dirname $0)
  17. Fi
  18. ### Define a user file ###
  19. Repo_file = $ cur_dir/cdc.txt # version Library definition
  20. Commit_file = $ cur_dir/commit.txt # number of submissions
  21. Total_file = $ cur_dir/total.txt # total number of submissions per person
  22. Detail_file = $ cur_dir/detail.txt # Number of lines submitted per person
  23. Everyone_file = $ cur_dir/every.txt
  24. ### Parameters for receiving months ###
  25. Month = $1
  26. ### Initializing intermediate files ###
  27. :> $ Commit_file
  28. :> $ Detail_file
  29. :> $ Everyone_file
  30. ### Count the submissions of each person and record the submissions to intermediate files
  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 = '% any' -- 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. ### Number of lines submitted by code
  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 the total number of lines for each version
  53. Git log -- author = ^. * -- pretty = tformat: -- numstat -- since = 2016-$ Month-01 -- until = 2016-$ Month-31 | \
  54. Awk '{add + = $1; subs + = $2; loc + = $1-$2 }\
  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 the code of each user, increase the number of lines, and delete the number of lines
  61. Git log -- pretty = 'tformat: % any' -- 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. ### Calculate the total number of submissions
  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. ### Total submissions
  71. Awk '{cnt + = $2} END {printf "%-20d % 10d \ n", Mon, cnt}' Mon = $ Month $ total_file
  72. ### Number of summary code lines
  73. # Awk '{adds + = $1; removes + = $2; saves + = $3} END {print adds, removes, saves}' $ detail_file
  74. ### Sum up and calculate the number of lines of code for each person
  75. ### Delete empty rows
  76. Awk '! /^ $/'$ Everyone_file | \
  77. ### Computing
  78. Awk '{if ($1 ~ /^ [A-zA-Z] + $/) {if (NR = 1) {printf "% 20 s ", $1} else {printf "\ n % 20 s % 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 "%-20 s % 10d % 10d % 10d % 10d \ n ", name [I], cnt [I], adds [I], dels [I], adds [I]-dels [I]}'
The last part of the script is used by the git clone version Library for the first time.


 
 
  1. #! /Bin/bash
  2. #### Define a branch ####
  3. Branch = release
  4. #### Define a version Library ####
  5. Git_repo1_cdc.txt
  6. While read repo
  7. Do
  8. Git clone $ repo
  9. Done <$ git_repo


III. usage considerations

1. it is better to separate the three parts into three script files.
2. the counting machine must have the read permission for all versions of the database; otherwise, the machine cannot be cloned.
3. the version library defines the file format. leave no blank lines at the end of the file.

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

4. Statistics directory structure for multiple projects



 
 
  1. .

  2. ── GetStat. sh # The first part of the script
  3. ── Android # Project directory
  4. │ ── GetAllByMon. sh # part 2 script
  5. │ ── Cdc.txt # git address of the source code of this project
  6. │ ── Commit.txt
  7. │ ── Detail.txt
  8. │ ── Every.txt
  9. │ ── Total.txt
  10. │ ── Workspace-goluk # Project source code

  11. ── Cdc.txt # project name and directory file, separated by spaces

  12. ├ ── Firmware # Structure same as above Directory
  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


Summary 1. a brief description of git log-based output statistics. by month statistics, of course, a slight change can also be made according...

Related Article

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.