mirror of
https://github.com/git-quick-stats/git-quick-stats.git
synced 2025-12-21 12:13:52 +01:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7219205696 | ||
|
|
dd3c97816e | ||
|
|
d2b273eead | ||
|
|
5b08bb0b52 | ||
|
|
08d1a5a6e3 | ||
|
|
f5c2b82f02 | ||
|
|
bf29c19cf5 | ||
|
|
c6cb74a5e0 | ||
|
|
3f0befcd07 | ||
|
|
292876846d | ||
|
|
e70c288225 | ||
|
|
4d2621b084 |
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Lukáš Mešťan
|
||||
Copyright (c) 2021 Lukáš Mešťan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
20
README.md
20
README.md
@@ -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 don’t think there is a single person alive who knows them all. Probably not even [Linus Torvalds](https://github.com/torvalds) himself :).
|
||||
|
||||

|
||||

|
||||
|
||||
## Table of Contents
|
||||
|
||||
@@ -53,15 +53,15 @@
|
||||
|
||||
## Screenshots
|
||||
|
||||

|
||||

|
||||
|
||||

|
||||

|
||||
|
||||
## 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
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
## Installation
|
||||
|
||||
|
||||
180
git-quick-stats
180
git-quick-stats
@@ -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
|
||||
@@ -224,12 +229,101 @@ showMenu() {
|
||||
# OUTS: None
|
||||
################################################################################
|
||||
function optionPicked() {
|
||||
local -r bold=$(tput bold)
|
||||
local -r red=$(tput setaf 1)
|
||||
local -r reset=$(tput sgr0)
|
||||
local msg=${*:-"${reset}Error: No message passed"}
|
||||
local msg=${*:-"Error: No message passed"}
|
||||
|
||||
echo -e "${bold}${red}${msg}${reset}\n"
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
}'
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -380,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
|
||||
@@ -411,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 '{
|
||||
}
|
||||
@@ -456,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
|
||||
@@ -542,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"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -629,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;;
|
||||
@@ -701,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\"."
|
||||
@@ -718,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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user