Compare commits

..

9 Commits
2.1.7 ... 2.2.0

Author SHA1 Message Date
Lukáš Mešťan
7219205696 Merge pull request #131 from treussart/export-csv
Export CSV of detailedGitStats
2021-05-20 07:46:54 +02:00
Tom Ice
dd3c97816e Update README.md to display new functionality
* With pull request #131, we add new functionality for both interactive and non-interactive modes.
  This change updates the README.md to reflect our new menu option for outputting the stats in CSV
2021-05-20 00:17:23 -04:00
Matthieu Treussart
d2b273eead Export CSV of detailedGitStats 2021-05-20 05:25:09 +02:00
Lukáš Mešťan
5b08bb0b52 Merge pull request #129 from treussart/add_git_branch_option
Add git branch option
2021-05-19 08:36:00 +02:00
Matthieu Treussart
08d1a5a6e3 Set git branch in options 2021-05-18 21:51:40 +02:00
Lukáš Mešťan
f5c2b82f02 Merge pull request #127 from pawaer/fix/issue126
Replaced grep commit by grep with regex including git sha hash
2021-04-29 08:36:34 +02:00
Pawaer
bf29c19cf5 Replaced grep commit by grep with regex including git sha hash
myDailyStats() used grep commit to detect count of commits. This
also increases the count by mentioning commit in the commit
message.

Therefore a grep with regex is used that expects a 40 digit/char
SHA1 hash after the word commit.
2021-04-24 21:50:30 +02:00
Lukáš Mešťan
c6cb74a5e0 Merge pull request #125 from arzzen/fix/issue-123
fix shortlog filter
2021-04-02 19:16:02 +02:00
arzzen
3f0befcd07 fix shortlog filter 2021-04-02 13:34:46 +02:00
4 changed files with 176 additions and 38 deletions

View File

@@ -5,7 +5,7 @@
>
> Any git repository may contain tons of information about commits, contributors, and files. Extracting this information is not always trivial, mostly because there are a gadzillion options to a gadzillion git commands I dont think there is a single person alive who knows them all. Probably not even [Linus Torvalds](https://github.com/torvalds) himself :).
![mainMenuScreenshot](https://user-images.githubusercontent.com/8818630/58364013-61e53800-7e7b-11e9-87f9-790d6744fbd5.png)
![mainMenuScreenshot](https://user-images.githubusercontent.com/8818630/118892347-c7375c80-b8ce-11eb-84f0-6e04bb65f850.png)
## Table of Contents
@@ -53,15 +53,15 @@
## Screenshots
![commitsByWeekdayScreenshot](https://user-images.githubusercontent.com/8818630/58364011-61e53800-7e7b-11e9-9417-16cbb241ac2e.png)
![commitsByWeekdayScreenshot](https://user-images.githubusercontent.com/8818630/118892353-c8688980-b8ce-11eb-96be-a48e1b7dc73b.png)
![commitsByHourScreenshot](https://user-images.githubusercontent.com/8818630/58364010-61e53800-7e7b-11e9-8711-a40b50aebf52.png)
![commitsByHourScreenshot](https://user-images.githubusercontent.com/8818630/118892355-c9012000-b8ce-11eb-991c-ac0e2a335cd6.png)
## Usage
### Interactive
git-quick-stats has a built-in interactive menu that can be executed as such:
`git-quick-stats` has a built-in interactive menu that can be executed as such:
```bash
git-quick-stats
@@ -98,6 +98,8 @@ Possible arguments in short and long form:
give a detailed list of git stats
-R, --git-stats-by-branch
see detailed list of git stats by branch
-V, --csv-output-by-branch
output daily stats by branch in CSV format
-d, --commits-per-day
displays a list of commits per day
-m, --commits-by-month
@@ -178,6 +180,14 @@ export _GIT_MERGE_VIEW="enable"
export _GIT_MERGE_VIEW="exclusive"
```
### Git branch
You can set the variable `_GIT_BRANCH` to set the branch of the stats. Works with commands `--git-stats-by-branch` and `--csv-output-by-branch`.
```bash
export _GIT_BRANCH="master"
```
### Color themes
You can change to the legacy color scheme by toggling the variable `_MENU_THEME` between `default` and `legacy`
@@ -186,7 +196,7 @@ You can change to the legacy color scheme by toggling the variable `_MENU_THEME`
export _MENU_THEME=legacy
```
![legacyThemeScreenshot](https://user-images.githubusercontent.com/8818630/58364012-61e53800-7e7b-11e9-910a-aaff836260eb.png)
![legacyThemeScreenshot](https://user-images.githubusercontent.com/8818630/118892356-c9012000-b8ce-11eb-8fd8-1b71e0ca6466.png)
## Installation

View File

@@ -61,7 +61,7 @@ fi
_log_options=${_GIT_LOG_OPTIONS:-}
if [[ -n "${_log_options}" ]]; then
_log_options=$_log_options
else
else
_log_options=""
fi
@@ -115,6 +115,8 @@ OPTIONS
give a detailed list of git stats
-R, --git-stats-by-branch
see detailed list of git stats by branch
-V, --csv-output-by-branch
output daily stats by branch in CSV format
-d, --commits-per-day
displays a list of commits per day
-m, --commits-by-month
@@ -158,7 +160,9 @@ ADDITIONAL USAGE
You can also set _GIT_MERGE_VIEW to only show merge commits
ex: export _GIT_MERGE_VIEW=exclusive
You can set _MENU_THEME to display the legacy color scheme
ex: export _MENU_THEME=legacy"
ex: export _MENU_THEME=legacy
You can set _GIT_BRANCH to set the branch of the stats
ex: export _GIT_BRANCH=master"
}
################################################################################
@@ -200,19 +204,20 @@ showMenu() {
printf %b "${NUMS} 3)${TEXT} Git changelogs (last $_limit days)\\n"
printf %b "${NUMS} 4)${TEXT} Git changelogs by author\\n"
printf %b "${NUMS} 5)${TEXT} My daily status\\n"
printf %b "${NUMS} 6)${TEXT} Save git log output in JSON format\\n"
printf %b "${NUMS} 6)${TEXT} Output daily stats by branch in CSV format\\n"
printf %b "${NUMS} 7)${TEXT} Save git log output in JSON format\\n"
printf %b "\\n${TITLES} List:\\n"
printf %b "${NUMS} 7)${TEXT} Branch tree view (last $_limit)\\n"
printf %b "${NUMS} 8)${TEXT} All branches (sorted by most recent commit)\\n"
printf %b "${NUMS} 9)${TEXT} All contributors (sorted by name)\\n"
printf %b "${NUMS} 10)${TEXT} Git commits per author\\n"
printf %b "${NUMS} 11)${TEXT} Git commits per date\\n"
printf %b "${NUMS} 12)${TEXT} Git commits per month\\n"
printf %b "${NUMS} 13)${TEXT} Git commits per weekday\\n"
printf %b "${NUMS} 14)${TEXT} Git commits per hour\\n"
printf %b "${NUMS} 15)${TEXT} Git commits by author per hour\\n"
printf %b "${NUMS} 8)${TEXT} Branch tree view (last $_limit)\\n"
printf %b "${NUMS} 9)${TEXT} All branches (sorted by most recent commit)\\n"
printf %b "${NUMS} 10)${TEXT} All contributors (sorted by name)\\n"
printf %b "${NUMS} 11)${TEXT} Git commits per author\\n"
printf %b "${NUMS} 12)${TEXT} Git commits per date\\n"
printf %b "${NUMS} 13)${TEXT} Git commits per month\\n"
printf %b "${NUMS} 14)${TEXT} Git commits per weekday\\n"
printf %b "${NUMS} 15)${TEXT} Git commits per hour\\n"
printf %b "${NUMS} 16)${TEXT} Git commits by author per hour\\n"
printf %b "\\n${TITLES} Suggest:\\n"
printf %b "${NUMS} 16)${TEXT} Code reviewers (based on git history)\\n"
printf %b "${NUMS} 17)${TEXT} Code reviewers (based on git history)\\n"
printf %b "\\n${HELP_TXT}Please enter a menu option or ${EXIT_TXT}press Enter to exit.\\n"
printf %b "${TEXT}> ${NORMAL}"
read -r opt
@@ -229,6 +234,98 @@ function optionPicked() {
echo -e "${msg}\n"
}
################################################################################
# DESC: Shows detailed contribution stats per author by parsing every commit in
# the repo and outputting their contribution stats
# ARGS: $branch (optional): Users can specify an alternative branch instead of
# the current default one
# OUTS: None
################################################################################
function csvOutput() {
local is_branch_existing=false
local branch="${1:-}"
local _branch=""
# Check if requesting for a specific branch
if [[ -n "${branch}" ]]; then
# Check if branch exist
if [[ $(git show-ref refs/heads/"${branch}") ]] ; then
is_branch_existing=true
_branch="${branch}"
else
is_branch_existing=false
_branch=""
fi
fi
echo "author,insertions,insertions_per,deletions,deletions_per,files,files_per,commits,commits_per,lines_changed,lines_changed_per"
git -c log.showSignature=false log ${_branch} --use-mailmap $_merges --numstat \
--pretty="format:commit %H%nAuthor: %aN <%aE>%nDate: %ad%n%n%w(0,4,4)%B%n" \
"$_since" "$_until" $_log_options $_pathspec | LC_ALL=C awk '
function printStats(author) {
printf "%s,", author
if(more["total"] > 0) {
printf "%d,%.0f%%,", more[author], \
(more[author] / more["total"] * 100)
}
if(less["total"] > 0) {
printf "%d,%.0f%%,", less[author], \
(less[author] / less["total"] * 100)
}
if(file["total"] > 0) {
printf "%d,%.0f%%,", file[author], \
(file[author] / file["total"] * 100)
}
if(commits["total"] > 0) {
printf "%d,%.0f%%,", commits[author], \
(commits[author] / commits["total"] * 100)
}
if (first[author] != "") {
if ( ((more["total"] + less["total"]) * 100) > 0) {
printf "%d,", more[author] + less[author]
printf "%.0f%%\n", ((more[author] + less[author]) / \
(more["total"] + less["total"]) * 100)
}
}
}
/^Author:/ {
$1 = ""
author = $0
commits[author] += 1
commits["total"] += 1
}
/^Date:/ {
$1="";
first[author] = substr($0, 2)
if(last[author] == "" ) { last[author] = first[author] }
}
/^[0-9]/ {
more[author] += $1
less[author] += $2
file[author] += 1
more["total"] += $1
less["total"] += $2
file["total"] += 1
}
END {
for (author in commits) {
if (author != "total") {
printStats(author)
}
}
}'
}
################################################################################
# DESC: Shows detailed contribution stats per author by parsing every commit in
# the repo and outputting their contribution stats
@@ -377,11 +474,13 @@ function jsonOutput() {
function commitsByMonth() {
optionPicked "Git commits by month:"
echo -e "\tmonth\tsum"
local startYear=$(echo "$_since" | grep -Eo "[0-9]{4}")
local endYear=$(echo "$_until" | grep -Eo "[0-9]{4}")
for i in Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
do
echo -en "\t$i\t"
git -c log.showSignature=false shortlog -n $_merges --format='%ad %s' \
"$_since" "$_until" $_log_options | grep " $i " | wc -l
"$_since" "$_until" $_log_options | grep -E "($startYear|$endYear)" | grep " $i " | wc -l
done | awk '{
count[$1] = $2
total += $2
@@ -408,12 +507,14 @@ function commitsByMonth() {
function commitsByWeekday() {
optionPicked "Git commits by weekday:"
echo -e "\tday\tsum"
local startYear=$(echo "$_since" | grep -Eo "[0-9]{4}")
local endYear=$(echo "$_until" | grep -Eo "[0-9]{4}")
local counter=1
for i in Mon Tue Wed Thu Fri Sat Sun
do
echo -en "\t$counter\t$i\t"
git -c log.showSignature=false shortlog -n $_merges --format='%ad %s' \
"$_since" "$_until" $_log_options | grep "$i " | wc -l
"$_since" "$_until" $_log_options | grep -E "($startYear|$endYear)" | grep "$i " | wc -l
counter=$((counter+1))
done | awk '{
}
@@ -453,11 +554,14 @@ function commitsByHour() {
_author="--author=${author}"
fi
echo -e "\thour\tsum"
local startYear=$(echo "$_since" | grep -Eo "[0-9]{4}")
local endYear=$(echo "$_until" | grep -Eo "[0-9]{4}")
for i in $(seq -w 0 23)
do
echo -ne "\t$i\t"
git -c log.showSignature=false shortlog -n $_merges --format='%ad %s' \
"${_author}" "$_since" "$_until" $_log_options | grep ' '$i: | wc -l
"${_author}" "$_since" "$_until" $_log_options | grep -E "($startYear|$endYear)" | grep ' '$i: | wc -l
done | awk '{
count[$1] = $2
total += $2
@@ -539,7 +643,7 @@ function myDailyStats() {
--author="$(git config user.name)" $_merges \
--since=$(date "+%Y-%m-%dT00:00:00") \
--until=$(date "+%Y-%m-%dT23:59:59") --reverse $_log_options \
| grep commit | wc -l) "commits"
| grep -E "commit [a-f0-9]{40}" | wc -l) "commits"
}
################################################################################
@@ -626,11 +730,17 @@ if [[ "$#" -eq 1 ]]; then
-r|--suggest-reviewers) suggestReviewers;;
-T|--detailed-git-stats) detailedGitStats;;
-R|--git-stats-by-branch)
branch=""
branch="${_GIT_BRANCH:-}"
while [[ -z "${branch}" ]]; do
read -r -p "Which branch? " branch
done
detailedGitStats "${branch}";;
-V|--csv-output-by-branch)
branch="${_GIT_BRANCH:-}"
while [[ -z "${branch}" ]]; do
read -r -p "Which branch? " branch
done
csvOutput "${branch}";;
-b|--branch-tree) branchTree;;
-d|--commits-per-day) commitsPerDay;;
-a|--commits-per-author) commitsPerAuthor;;
@@ -698,7 +808,12 @@ while [[ "${opt}" != "" ]]; do
done
changelogs "${author}"; showMenu;;
5) myDailyStats; showMenu;;
6) json_path=""
6) branch=""
while [[ -z "${branch}" ]]; do
read -r -p "Which branch? " branch
done
csvOutput "${branch}"; showMenu;;
7) json_path=""
while [[ -z "${json_path}" ]]; do
echo "NOTE: This feature is in beta!"
echo "The file name will be saved as \"output.json\"."
@@ -715,20 +830,20 @@ while [[ "${opt}" != "" ]]; do
fi
done
jsonOutput "${json_path}"; showMenu;;
7) branchTree; showMenu;;
8) branchesByDate; showMenu;;
9) contributors; showMenu;;
10) commitsPerAuthor; showMenu;;
11) commitsPerDay; showMenu;;
12) commitsByMonth; showMenu;;
13) commitsByWeekday; showMenu;;
14) commitsByHour; showMenu;;
15) author=""
8) branchTree; showMenu;;
9) branchesByDate; showMenu;;
10) contributors; showMenu;;
11) commitsPerAuthor; showMenu;;
12) commitsPerDay; showMenu;;
13) commitsByMonth; showMenu;;
14) commitsByWeekday; showMenu;;
15) commitsByHour; showMenu;;
16) author=""
while [[ -z "${author}" ]]; do
read -r -p "Which author? " author
done
commitsByHour "${author}"; showMenu;;
16) suggestReviewers; showMenu;;
17) suggestReviewers; showMenu;;
q|"\n") exit;;
*) clear; optionPicked "Pick an option from the menu"; showMenu;;
esac

View File

@@ -1,13 +1,13 @@
.TH git-quick-stats "1" "January 2020" "git-quick-stats" "User Commands"
.SH NAME
.B git\-quick\-stats
.B git\-quick\-stats
\- Simple and efficient way to access various stats in a git repository.
.SH SYNOPSIS
.PP
For non\-interactive mode:
For non\-interactive mode:
.B git\-quick\-stats [OPTIONS]
.PP
For interactive mode:
For interactive mode:
.B git-quick-stats
.PP
.SH DESCRIPTION
@@ -34,6 +34,11 @@ give a detailed list of git stats
see detailed list of git stats by branch
.HP
.PP
\fB\-V\fR, \fB\-\-csv\-output\-by\-branch\fR
.IP
output daily stats by branch in CSV format
.HP
.PP
\fB\-d\fR, \fB\-\-commits\-per\-day\fR
.IP
displays a list of commits per day
@@ -131,6 +136,10 @@ You can also set _GIT_MERGE_VIEW to only show merge commits, example:
You can switch to the legacy color scheme, example:
.PP
.B export _MENU_THEME=legacy
.PP
You can set _GIT_BRANCH to set the branch of the stats, example:
.PP
.B export _GIT_BRANCH="master"
.
.fi

View File

@@ -26,6 +26,8 @@ OPTIONS
give a detailed list of git stats
-R, --git-stats-by-branch
see detailed list of git stats by branch
-V, --csv-output-by-branch
output daily stats by branch in CSV format
-d, --commits-per-day
displays a list of commits per day
-m, --commits-by-month
@@ -69,7 +71,9 @@ ADDITIONAL USAGE
You can also set _GIT_MERGE_VIEW to only show merge commits
ex: export _GIT_MERGE_VIEW=exclusive
You can set _MENU_THEME to display the legacy color scheme
ex: export _MENU_THEME=legacy"
ex: export _MENU_THEME=legacy
You can set _GIT_BRANCH to set the branch of the stats
ex: export _GIT_BRANCH=master"
assert_raises "$src fail" 1