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:
- #! /Bin/bash
- # 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
- # The statistics are calculated based on the calendar month or the specified time period. $1 is the month (1-12)
- ### Current directory ###
- If [$ (echo $0 | grep '^/')]; then
- Cur_dir = $ (dirname $0)
- Else
- Cur_dir = $ (pwd)/$ (dirname $0)
- Fi
- ### Define a user file ###
- Repo_file = $ cur_dir/cdc.txt # define the version library directory file
- Everyone_file = $ cur_dir/every.txt
- Goluk_file = $ cur_dir/goluk.csv
- ### Parameters for receiving months ###
- Month = $1
- :> $ Goluk_file
- While read name project_dir
- Do
- 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 ,\
- ",", "Submissions", "add code", "reduce code ",",", "Reserved code"} '> $ goluk_file
- Everyone_file = $ cur_dir/$ project_dir/every.txt
- ### Sum up and calculate the number of lines of code for each person
- ### Delete empty rows
- Awk '! /^ $/'$ Everyone_file | \
- ### Computing
- 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 }}\
- Else {adds = adds + $1; dels = dels + $2; next} '| \
- ### Summary
- 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 ",\
- Name [I], ",", cnt [I], ",", adds [I], ",", dels [I], ",", adds [I]-dels [I]} '> $ goluk_file
- Done <$ repo_file
The code is as follows:
- #! /Bin/bash
- # Count the total number of submissions, additions, deletions, and number of reserved code lines in the background
- # The statistics are calculated based on the calendar month or the specified time period. $1 is the month (1-12)
- #### Define a branch ####
- If [$2 = ""]; then
- Branch = develop
- Else
- Branch = $2
- Fi
- #### Define a version Library ####
- Export git_repo1_cdc.txt
- ### Current directory ###
- If [$ (echo $0 | grep '^/')]; then
- Cur_dir = $ (dirname $0)
- Else
- Cur_dir = $ (pwd)/$ (dirname $0)
- Fi
- ### Define a user file ###
- Repo_file = $ cur_dir/cdc.txt # version Library definition
- Commit_file = $ cur_dir/commit.txt # number of submissions
- Total_file = $ cur_dir/total.txt # total number of submissions per person
- Detail_file = $ cur_dir/detail.txt # Number of lines submitted per person
- Everyone_file = $ cur_dir/every.txt
- ### Parameters for receiving months ###
- Month = $1
- ### Initializing intermediate files ###
- :> $ Commit_file
- :> $ Detail_file
- :> $ Everyone_file
- ### Count the submissions of each person and record the submissions to intermediate files
- Function Count (){
- While read git_url
- Do
- Echo $ git_url
- Goluk_repo = 'echo $ git_url | awk-F/'{print $ NF }''
- Cd $ goluk_repo
- Git checkout $ Branch
- Git pull
- Git log -- pretty = '% any' -- since = 2016-$ Month-01 -- until = 2016-$ Month-31 | sort | uniq-c | sort-k1-n -r> $ commit_file
- Cd ../
- Done <$ repo_file
- }
- ### Number of lines submitted by code
- Function Codelines (){
- While read git_url
- Do
- Echo $ git_url
- Goluk_repo = 'echo $ git_url | awk-F/'{print $ NF }''
- Cd $ goluk_repo
- Git pull
- Git checkout $ Branch
- # Count the total number of lines for each version
- Git log -- author = ^. * -- pretty = tformat: -- numstat -- since = 2016-$ Month-01 -- until = 2016-$ Month-31 | \
- Awk '{add + = $1; subs + = $2; loc + = $1-$2 }\
- END {print add, subs, loc, repo_name} 'repo_name = $ goluk_repo-> $ detail_file
- ### Debug begin
- ### Git log -- author = ^. * -- pretty = tformat: % aN -- numstat -- since = 2016-$ Month-01 -- until = 2016-$ Month-31 | \
- ### Awk '! /^ $/'> $ Cur_dir/every2.txt
- # Debug end
- # Record the code of each user, increase the number of lines, and delete the number of lines
- Git log -- pretty = 'tformat: % any' -- numstat -- since = 2016-$ Month-01 -- until = 2016-$ Month-31> $ everyone_file
- Cd ../
- Done <$ repo_file
- }
- # Awk '{sum [$2] + = $1} END {for (I in sum) print I, sum [I]}' scrope.txt | sort-k2-nr>
- Count $ Month
- ### Calculate the total number of submissions
- Awk '{sum [$2] + = $1} END {for (I in sum) print I, sum [I]} '$ commit_file | sort-k2-nr> $ total_file
- Codelines $ Month
- ### Total submissions
- Awk '{cnt + = $2} END {printf "%-20d % 10d \ n", Mon, cnt}' Mon = $ Month $ total_file
- ### Number of summary code lines
- # Awk '{adds + = $1; removes + = $2; saves + = $3} END {print adds, removes, saves}' $ detail_file
- ### Sum up and calculate the number of lines of code for each person
- ### Delete empty rows
- Awk '! /^ $/'$ Everyone_file | \
- ### Computing
- 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 }}\
- Else {adds = adds + $1; dels = dels + $2; next} '| \
- ### Summary
- 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.
- #! /Bin/bash
- #### Define a branch ####
- Branch = release
- #### Define a version Library ####
- Git_repo1_cdc.txt
- While read repo
- Do
- Git clone $ repo
- 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.
- git@1.1.1.1:users/p1/cdc/authority
- git@1.1.1.1:users/p2/cdc/business
4. Statistics directory structure for multiple projects
- .
- ── GetStat. sh # The first part of the script
- ── Android # Project directory
- │ ── GetAllByMon. sh # part 2 script
- │ ── Cdc.txt # git address of the source code of this project
- │ ── Commit.txt
- │ ── Detail.txt
- │ ── Every.txt
- │ ── Total.txt
- │ ── Workspace-goluk # Project source code
- ── Cdc.txt # project name and directory file, separated by spaces
- ├ ── Firmware # Structure same as above Directory
- │ ── GetAllByMon. sh
- │ ── Getrepo. sh
- │ ── Cdc.txt
- │ ── Commit.txt
- │ ── Detail.txt
- │ ── Every.txt
- │ ── Goluk_src
- │ ── S2l_linux_sdk
- │ ── 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...