mirror of
https://github.com/git-quick-stats/git-quick-stats.git
synced 2025-12-21 12:13:52 +01:00
Compare commits
1 Commits
feat/activ
...
fix/issue-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
340ed6b078 |
5
.github/FUNDING.yml
vendored
5
.github/FUNDING.yml
vendored
@@ -1 +1,6 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: [arzzen]
|
||||
open_collective: git-quick-stats
|
||||
ko_fi: lukasmestan
|
||||
custom: ['https://lukasmestan.com/thanks/']
|
||||
|
||||
4
.mailmap
4
.mailmap
@@ -1,3 +1,3 @@
|
||||
Lukas <test@gmail.com> Lukáš <arzzen@users.noreply.github.com>
|
||||
Lukas <lukas@gmail.com> arzzen
|
||||
Lukas Mestan <lukas.mestan@gmail.com> Lukáš Mešťan <arzzen@users.noreply.github.com>
|
||||
Lukas Mestan <lukas.mestan@gmail.com> arzzen
|
||||
|
||||
|
||||
@@ -23,6 +23,5 @@ ENV _GIT_SINCE= \
|
||||
TERM=xterm-256color
|
||||
|
||||
WORKDIR /git
|
||||
RUN git config --global --add safe.directory /git
|
||||
ENTRYPOINT [ "/usr/local/bin/docker-entrypoint" ]
|
||||
CMD [ "/usr/bin/git", "quick-stats" ]
|
||||
CMD [ "/usr/bin/git", "quick-stats" ]
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 git-quick-stats.sh
|
||||
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
|
||||
|
||||
4
Makefile
4
Makefile
@@ -30,8 +30,8 @@ uninstall:
|
||||
@$(TASK_DONE)
|
||||
|
||||
reinstall:
|
||||
@curl -sO https://raw.githubusercontent.com/git-quick-stats/git-quick-stats/master/git-quick-stats
|
||||
@curl -sO https://raw.githubusercontent.com/git-quick-stats/git-quick-stats/master/git-quick-stats.1
|
||||
@curl -sO https://raw.githubusercontent.com/arzzen/git-quick-stats/master/git-quick-stats
|
||||
@curl -sO https://raw.githubusercontent.com/arzzen/git-quick-stats/master/git-quick-stats.1
|
||||
$(MAKE) install
|
||||
@$(TASK_DONE)
|
||||
|
||||
|
||||
94
README.md
94
README.md
@@ -1,6 +1,6 @@
|
||||
# GIT quick statistics [](https://twitter.com/intent/tweet?text=Simple%20and%20efficient%20way%20to%20access%20various%20statistics%20in%20git%20repository&url=https://github.com/arzzen/git-quick-stat&via=arzzen&hashtags=git,stats,tool,statistics,developers)
|
||||
|
||||
[](https://formulae.brew.sh/formula/git-quick-stats#default)
|
||||
[](#backers) [](#sponsors) [](https://formulae.brew.sh/formula/git-quick-stats#default)
|
||||
|
||||
> `git-quick-stats` is a simple and efficient way to access various statistics in a git repository.
|
||||
>
|
||||
@@ -14,34 +14,34 @@
|
||||
|
||||
[**Usage**](#usage)
|
||||
|
||||
- [**Interactive**](#interactive)
|
||||
- [**Non-interactive**](#non-interactive)
|
||||
- [**Command-line arguments**](#command-line-arguments)
|
||||
- [**Git log since and until**](#git-log-since-and-until)
|
||||
- [**Git log limit**](#git-log-limit)
|
||||
- [**Git log options**](#git-log-options)
|
||||
- [**Git pathspec**](#git-pathspec)
|
||||
- [**Git merge view strategy**](#git-merge-view-strategy)
|
||||
- [**Color themes**](#color-themes)
|
||||
* [**Interactive**](#interactive)
|
||||
* [**Non-interactive**](#non-interactive)
|
||||
* [**Command-line arguments**](#command-line-arguments)
|
||||
* [**Git log since and until**](#git-log-since-and-until)
|
||||
* [**Git log limit**](#git-log-limit)
|
||||
* [**Git log options**](#git-log-options)
|
||||
* [**Git pathspec**](#git-pathspec)
|
||||
* [**Git merge view strategy**](#git-merge-view-strategy)
|
||||
* [**Color themes**](#color-themes)
|
||||
|
||||
[**Installation**](#installation)
|
||||
|
||||
- [**UNIX and Linux**](#unix-and-linux)
|
||||
- [**macOS**](#macos-homebrew)
|
||||
- [**Windows**](#windows)
|
||||
- [**Docker**](#docker)
|
||||
* [**UNIX and Linux**](#unix-and-linux)
|
||||
* [**macOS**](#macos-homebrew)
|
||||
* [**Windows**](#windows)
|
||||
* [**Docker**](#docker)
|
||||
|
||||
[**System requirements**](#system-requirements)
|
||||
|
||||
- [**Dependencies**](#dependencies)
|
||||
* [**Dependencies**](#dependencies)
|
||||
|
||||
[**FAQ**](#faq)
|
||||
|
||||
[**Contribution**](#contribution)
|
||||
|
||||
- [**Code reviews**](#code-reviews)
|
||||
- [**Some tips for good pull requests**](#some-tips-for-good-pull-requests)
|
||||
- [**Formatting**](#formatting)
|
||||
* [**Code reviews**](#code-reviews)
|
||||
* [**Some tips for good pull requests**](#some-tips-for-good-pull-requests)
|
||||
* [**Formatting**](#formatting)
|
||||
|
||||
[**Tests**](#tests)
|
||||
|
||||
@@ -49,8 +49,8 @@
|
||||
|
||||
[**Contributors**](#contributors)
|
||||
|
||||
- [**Backers**](#backers)
|
||||
- [**Sponsors**](#sponsors)
|
||||
* [**Backers**](#backers)
|
||||
* [**Sponsors**](#sponsors)
|
||||
|
||||
## Screenshots
|
||||
|
||||
@@ -204,12 +204,6 @@ You can set the variable `_GIT_BRANCH` to set the branch of the stats. Works wit
|
||||
export _GIT_BRANCH="master"
|
||||
```
|
||||
|
||||
You can set the variable `_GIT_IGNORE_AUTHORS` to filter out specific authors. It will affect the "All contributors", ""Suggested code reviewers" and "New contributors" options.
|
||||
|
||||
```bash
|
||||
export _GIT_IGNORE_AUTHORS="(author@examle.com|username)"
|
||||
```
|
||||
|
||||
### Color themes
|
||||
|
||||
You can change to the legacy color scheme by toggling the variable `_MENU_THEME` between `default` and `legacy`
|
||||
@@ -233,7 +227,7 @@ apt install git-quick-stats
|
||||
### UNIX and Linux
|
||||
|
||||
```bash
|
||||
git clone https://github.com/git-quick-stats/git-quick-stats.git && cd git-quick-stats
|
||||
git clone https://github.com/arzzen/git-quick-stats.git && cd git-quick-stats
|
||||
sudo make install
|
||||
```
|
||||
|
||||
@@ -277,8 +271,8 @@ based on the shell of your choice.
|
||||
|
||||
If you are installing with Cygwin, use these scripts:
|
||||
|
||||
- [installer](https://gist.github.com/arzzen/35e09866dfdadf2108b2420045739245)
|
||||
- [uninstaller](https://gist.github.com/arzzen/21c660014d0663b6c5710014714779d6)
|
||||
* [installer](https://gist.github.com/arzzen/35e09866dfdadf2108b2420045739245)
|
||||
* [uninstaller](https://gist.github.com/arzzen/21c660014d0663b6c5710014714779d6)
|
||||
|
||||
If you are wishing to use this with WSL, follow the UNIX and Linux instructions.
|
||||
|
||||
@@ -286,14 +280,14 @@ If you are wishing to use this with WSL, follow the UNIX and Linux instructions.
|
||||
|
||||
You can use the Docker image provided:
|
||||
|
||||
- Build: `docker build -t arzzen/git-quick-stats .`
|
||||
- Run interactive menu: `docker run --rm -it -v $(pwd):/git arzzen/git-quick-stats`
|
||||
- Docker pull command: `docker pull arzzen/git-quick-stats` [docker repository](https://hub.docker.com/r/arzzen/git-quick-stats)
|
||||
* Build: `docker build -t arzzen/git-quick-stats .`
|
||||
* Run interactive menu: `docker run --rm -it -v $(pwd):/git arzzen/git-quick-stats`
|
||||
* Docker pull command: `docker pull arzzen/git-quick-stats` [docker repository](https://hub.docker.com/r/arzzen/git-quick-stats)
|
||||
|
||||
## System requirements
|
||||
|
||||
- An OS with a Bash shell
|
||||
- Tools we use:
|
||||
* An OS with a Bash shell
|
||||
* Tools we use:
|
||||
|
||||
```bash
|
||||
awk
|
||||
@@ -315,21 +309,21 @@ uniq
|
||||
|
||||
### Dependencies
|
||||
|
||||
- [`bsdextrautils`](https://packages.debian.org/sid/bsdextrautils) `apt install bsdextrautils`
|
||||
- [`coreutils`](https://packages.debian.org/sid/coreutils) `apt install coreutils`
|
||||
- [`gawk`](https://packages.debian.org/sid/gawk) `apt install gawk`
|
||||
- [`grep`](https://packages.debian.org/sid/grep) `apt install grep`
|
||||
- [`ncurses-bin`](https://packages.debian.org/sid/ncurses-bin) `apt install ncurses-bin`
|
||||
* [`bsdextrautils`](https://packages.debian.org/sid/bsdextrautils) `apt install bsdextrautils`
|
||||
* [`coreutils`](https://packages.debian.org/sid/coreutils) `apt install coreutils`
|
||||
* [`gawk`](https://packages.debian.org/sid/gawk) `apt install gawk`
|
||||
* [`grep`](https://packages.debian.org/sid/grep) `apt install grep`
|
||||
* [`ncurses-bin`](https://packages.debian.org/sid/ncurses-bin) `apt install ncurses-bin`
|
||||
|
||||
## FAQ
|
||||
|
||||
_Q:_ I get some errors after run git-quick-stats in cygwin like `/usr/local/bin/git-quick-stats: line 2: $'\r': command not found`
|
||||
*Q:* I get some errors after run git-quick-stats in cygwin like `/usr/local/bin/git-quick-stats: line 2: $'\r': command not found`
|
||||
|
||||
_A:_ You can run the dos2unix app in cygwin as follows: `/bin/dos2unix.exe /usr/local/bin/git-quick-stats`. This will convert the script from the CR-LF convention that Microsoft uses to the LF convention that UNIX, OS X, and Linux use. You should then should be able to run it as normal.
|
||||
*A:* You can run the dos2unix app in cygwin as follows: `/bin/dos2unix.exe /usr/local/bin/git-quick-stats`. This will convert the script from the CR-LF convention that Microsoft uses to the LF convention that UNIX, OS X, and Linux use. You should then should be able to run it as normal.
|
||||
|
||||
_Q:_ How they could be used in a project with many git projects and statistics would show a summary of all git projects?
|
||||
*Q:* How they could be used in a project with many git projects and statistics would show a summary of all git projects?
|
||||
|
||||
_A:_ If you want to include submodule logs, you can try using the following: `export _GIT_LOG_OPTIONS="-p --submodule=log"`
|
||||
*A:* If you want to include submodule logs, you can try using the following: `export _GIT_LOG_OPTIONS="-p --submodule=log"`
|
||||
(more info about [git log --submodule](https://git-scm.com/docs/git-log#Documentation/git-log.txt---submoduleltformatgt))
|
||||
|
||||
## Contribution
|
||||
@@ -343,13 +337,13 @@ We use GitHub pull requests for this purpose.
|
||||
|
||||
### Some tips for good pull requests
|
||||
|
||||
- Use our code </br>
|
||||
* Use our code </br>
|
||||
When in doubt, try to stay true to the existing code of the project.
|
||||
- Write a descriptive commit message. What problem are you solving and what
|
||||
* Write a descriptive commit message. What problem are you solving and what
|
||||
are the consequences? Where and what did you test? Some good tips:
|
||||
[here](http://robots.thoughtbot.com/5-useful-tips-for-a-better-commit-message)
|
||||
and [here](https://www.kernel.org/doc/Documentation/SubmittingPatches).
|
||||
- If your PR consists of multiple commits which are successive improvements /
|
||||
* If your PR consists of multiple commits which are successive improvements /
|
||||
fixes to your first commit, consider squashing them into a single commit
|
||||
(`git rebase -i`) such that your PR is a single commit on top of the current
|
||||
HEAD. This make reviewing the code so much easier, and our history more
|
||||
@@ -371,15 +365,15 @@ make test
|
||||
|
||||
MIT see [LICENSE][] for the full license text.
|
||||
|
||||
[read this page]: http://github.com/git-quick-stats/git-quick-stats/blob/master/.github/CONTRIBUTING.md
|
||||
[landing page]: https://git-quick-stats.sh
|
||||
[LICENSE]: https://github.com/git-quick-stats/git-quick-stats/blob/master/LICENSE
|
||||
[read this page]: http://github.com/arzzen/git-quick-stats/blob/master/.github/CONTRIBUTING.md
|
||||
[landing page]: http://arzzen.github.io/git-quick-stats
|
||||
[LICENSE]: https://github.com/arzzen/git-quick-stats/blob/master/LICENSE
|
||||
|
||||
## Contributors
|
||||
|
||||
This project exists thanks to all the people who contribute.
|
||||
|
||||
[](https://github.com/git-quick-stats/git-quick-stats/graphs/contributors)
|
||||
[](https://github.com/arzzen/git-quick-stats/graphs/contributors)
|
||||
|
||||
### Backers
|
||||
|
||||
|
||||
236
git-quick-stats
236
git-quick-stats
@@ -17,7 +17,7 @@ _since=${_GIT_SINCE:-}
|
||||
if [[ -n "${_since}" ]]; then
|
||||
_since="--since=$_since"
|
||||
else
|
||||
_since="--since=$(git log --reverse --format='%ad' --date=iso | head -n1)"
|
||||
_since="--since=$(git log --reverse --format='%ad' | head -n1)"
|
||||
fi
|
||||
|
||||
# End of git log date. Respects all git datetime formats
|
||||
@@ -68,68 +68,10 @@ else
|
||||
_log_options=""
|
||||
fi
|
||||
|
||||
# Ignore author regex
|
||||
_ignore_authors=${_GIT_IGNORE_AUTHORS:-}
|
||||
if [[ -n "${_ignore_authors}" ]]; then
|
||||
_ignore_authors=$_ignore_authors
|
||||
else
|
||||
_ignore_authors=""
|
||||
fi
|
||||
|
||||
# Default menu theme
|
||||
# Set the legacy theme by typing "export _MENU_THEME=legacy"
|
||||
_theme="${_MENU_THEME:=default}"
|
||||
|
||||
# DESC: Shows a calendar heatmap of commits per day-of-week per month for a given author
|
||||
# ARGS: $author (required)
|
||||
function commitsCalendarByAuthor() {
|
||||
local author="${1:-}"
|
||||
[[ -z "$author" ]] && { echo "Usage: commitsCalendarByAuthor <author>"; return 1; }
|
||||
|
||||
optionPicked "Commit Activity Calendar for '$author'"
|
||||
|
||||
# Print header
|
||||
printf "\n Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\n"
|
||||
|
||||
# Gather commit counts
|
||||
git -c log.showSignature=false log --use-mailmap $_merges \
|
||||
--date=iso --author="$author" "$_since" "$_until" $_log_options \
|
||||
--pretty='%ad' $_pathspec | awk '
|
||||
{
|
||||
split($0, a, " ");
|
||||
# a[1] = YYYY-MM-DD
|
||||
split(a[1], date_fields, "-");
|
||||
mon = date_fields[2] + 0;
|
||||
cmd = "date -d \"" a[1] "\" +%u";
|
||||
cmd | getline weekday;
|
||||
close(cmd);
|
||||
# weekday: 1=Mon, ..., 7=Sun
|
||||
count[weekday][mon]++;
|
||||
}
|
||||
END {
|
||||
# Output matrix
|
||||
for (d=1; d<=7; d++) {
|
||||
if (d==1) printf "Mon ";
|
||||
else if (d==2) printf "Tue ";
|
||||
else if (d==3) printf "Wed ";
|
||||
else if (d==4) printf "Thu ";
|
||||
else if (d==5) printf "Fri ";
|
||||
else if (d==6) printf "Sat ";
|
||||
else if (d==7) printf "Sun ";
|
||||
for (m=1; m<=12; m++) {
|
||||
c = count[d][m]+0;
|
||||
if (c==0) out="...";
|
||||
else if (c<=9) out="░░░";
|
||||
else if (c<=19) out="▒▒▒";
|
||||
else out="▓▓▓";
|
||||
printf "%s%s", out, (m<12?" ":"\n");
|
||||
}
|
||||
}
|
||||
printf "\nLegend: ... = 0 ░░░ = 1–9 ▒▒▒ = 10–19 ▓▓▓ = 20+ commits\n";
|
||||
}
|
||||
'
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# HELPER AND MENU FUNCTIONS
|
||||
|
||||
@@ -176,6 +118,24 @@ function optionPicked() {
|
||||
echo -e "${msg}\n"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# DESC: Format date string
|
||||
# ARGS: $* (required): String
|
||||
# OUTS: String
|
||||
################################################################################
|
||||
function format_date() {
|
||||
# NOTE: While this works where it's implemented within the changelogs()
|
||||
# function the first time, it then bombs out when it reaches the -d flag
|
||||
# in the second half of that same code as BSD date cannot handle -d, nor
|
||||
# can it handle a string such as DATE - 1 day.
|
||||
local date="${1}"
|
||||
local outf="${2}"
|
||||
local datef="${3:-"%b %d %H:%M:%S %Y %Z"}" # Tue Oct 24 13:34:22 2023 +0300
|
||||
local resp="$(date -d "${date}" "+${outf}")"
|
||||
|
||||
printf "%s" "${resp}"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# DESC: Help information printed to stdout during non-interactive mode
|
||||
# ARGS: None
|
||||
@@ -267,9 +227,7 @@ ADDITIONAL USAGE
|
||||
You can set _MENU_THEME to display the legacy color scheme
|
||||
ex: export _MENU_THEME=legacy
|
||||
You can set _GIT_BRANCH to set the branch of the stats
|
||||
ex: export _GIT_BRANCH=master
|
||||
You can set _GIT_IGNORE_AUTHORS to filter out specific authors
|
||||
ex: export _GIT_IGNORE_AUTHORS=\"(author1|author2)\""
|
||||
ex: export _GIT_BRANCH=master"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -331,21 +289,11 @@ function showMenu() {
|
||||
printf %b "${NUMS} 21)${TEXT} Git commits per timezone by author\\n"
|
||||
printf %b "\\n${TITLES} Suggest:\\n"
|
||||
printf %b "${NUMS} 22)${TEXT} Code reviewers (based on git history)\\n"
|
||||
printf %b "\\n${TITLES} Calendar:\\n"
|
||||
printf %b "${NUMS} 23)${TEXT} Activity calendar by author\\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
|
||||
}
|
||||
|
||||
filter_ignored_authors() {
|
||||
if [[ -n "$_ignore_authors" ]]; then
|
||||
grep -Ev "$_ignore_authors"
|
||||
else
|
||||
cat
|
||||
fi
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# FUNCTIONS FOR GENERATING STATS
|
||||
|
||||
@@ -468,9 +416,8 @@ function detailedGitStats() {
|
||||
# OUTS: None
|
||||
################################################################################
|
||||
function changelogs() {
|
||||
local _author=""
|
||||
local commits=""
|
||||
local author="${1:-}"
|
||||
local _author=""
|
||||
local next=$(date +%F)
|
||||
|
||||
if [[ -z "${author}" ]]; then
|
||||
@@ -488,20 +435,14 @@ function changelogs() {
|
||||
--date=short "${_author}" "$_since" "$_until" $_log_options $_pathspec \
|
||||
| sort -u -r | head -n $_limit \
|
||||
| while read DATE; do
|
||||
commits=$(git -c log.showSignature=false log \
|
||||
--use-mailmap $_merges \
|
||||
--format=" * %s (%aN)" "${_author}" \
|
||||
--since="$DATE 00:00:00" --until="$DATE 23:59:59" \
|
||||
--date-order)
|
||||
|
||||
if [[ -n "$commits" ]]; then
|
||||
echo -e "\n[$DATE]"
|
||||
echo "$commits"
|
||||
else
|
||||
echo "No commits found on $DATE"
|
||||
fi
|
||||
next=$DATE
|
||||
done
|
||||
day=$(format_date "$DATE" "%A" "%Y-%m-%d")
|
||||
echo -e "\n[$DATE - $day]"
|
||||
GIT_PAGER=cat git -c log.showSignature=false log \
|
||||
--use-mailmap $_merges \
|
||||
--format=" * %s (%aN)" "${_author}" \
|
||||
--since==$(date -d "$DATE - 1 day" +"%Y-%m-%d") --until=$next
|
||||
next=$DATE
|
||||
done
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -558,7 +499,7 @@ function csvOutput() {
|
||||
printf "files_per,commits,commits_per,lines_changed,lines_changed_per\n"
|
||||
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 | filter_ignored_authors | LC_ALL=C awk '
|
||||
"$_since" "$_until" $_log_options $_pathspec | LC_ALL=C awk '
|
||||
function printStats(author) {
|
||||
printf "%s,", author
|
||||
if(more["total"] > 0) {
|
||||
@@ -704,7 +645,7 @@ function jsonOutput() {
|
||||
"$propTag"' commit_notes%n%N%n'"$propTag"',%n "author": {%n'\
|
||||
"$propTag"' name%n%aN%n'"$propTag"',%n'\
|
||||
"$propTag"' email%n%aE%n'"$propTag"',%n'\
|
||||
' "date": "%aD"%n },%n "committer": {%n'\
|
||||
' "date": "%aD"%n },%n "commiter": {%n'\
|
||||
"$propTag"' name%n%cN%n'"$propTag"',%n'\
|
||||
"$propTag"' email%n%cE%n'"$propTag"',%n'\
|
||||
' "date": "%cD"%n }%n},' \
|
||||
@@ -752,7 +693,7 @@ function branchesByDate() {
|
||||
function contributors() {
|
||||
optionPicked "All contributors (sorted by name):"
|
||||
git -c log.showSignature=false log --use-mailmap $_merges "$_since" "$_until" \
|
||||
--format='%aN' $_log_options $_pathspec | filter_ignored_authors | sort -u | cat -n
|
||||
--format='%aN' $_log_options $_pathspec | sort -u | cat -n
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -768,7 +709,7 @@ function newContributors() {
|
||||
for c in $contributors; do
|
||||
local firstCommit=$(git -c log.showSignature=false log --author="$c" \
|
||||
--reverse --use-mailmap $_merges "$_since" "$_until" \
|
||||
--format='%at' $_log_options $_pathspec | filter_ignored_authors | head -n 1)
|
||||
--format='%at' $_log_options $_pathspec | head -n 1)
|
||||
if [[ $firstCommit -ge $(date -d "$newDate" +%s) ]]; then
|
||||
echo "$c"
|
||||
fi
|
||||
@@ -785,10 +726,10 @@ function commitsPerAuthor() {
|
||||
optionPicked "Git commits per author:"
|
||||
local authorCommits=$(git -c log.showSignature=false log --use-mailmap \
|
||||
$_merges "$_since" "$_until" $_log_options \
|
||||
| grep -i '^Author:' | cut -c9-)
|
||||
| grep -i Author: | cut -c9-)
|
||||
local coAuthorCommits=$(git -c log.showSignature=false log --use-mailmap \
|
||||
$_merges "$_since" "$_until" $_log_options \
|
||||
| grep -i '^ Co-Authored-by:' | cut -c21-)
|
||||
| grep -i Co-Authored-by: | cut -c21-)
|
||||
|
||||
if [[ -z "${coAuthorCommits}" ]]; then
|
||||
allCommits="${authorCommits}"
|
||||
@@ -820,47 +761,6 @@ function commitsPerDay() {
|
||||
--date=short --format='%ad' $_log_options $_pathspec | sort | uniq -c
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# DESC: Convert a timestamp to a date string to handle git's date formats
|
||||
# ARGS: $1: Timestamp
|
||||
# OUTS: Echoes a four-digit year
|
||||
################################################################################
|
||||
function parse_year() {
|
||||
local date_str="$1"
|
||||
local year
|
||||
local timestamp
|
||||
local default_git_date_regex
|
||||
|
||||
# Handle the raw UNIX timestamp format i.e. 1697375696 +0000
|
||||
if [[ "$date_str" =~ ^[0-9]+(\ [+-][0-9]{4})?$ ]]; then
|
||||
timestamp=$(echo "$date_str" | awk '{print $1}')
|
||||
year=$(date -d "@$timestamp" '+%Y' 2>/dev/null)
|
||||
else
|
||||
# Default case can get funky. We need to create a clever regex to
|
||||
# handle the default case which is like Mon Oct 15 12:34:56 2023 +0000
|
||||
# Let's make this explicit for future devs to follow along.
|
||||
default_git_date_regex='^' # Start from the beginning of the string
|
||||
default_git_date_regex+='[A-Za-z]{3}\ ' # Day abbrev
|
||||
default_git_date_regex+='[A-Za-z]{3}\ ' # Month abbrev
|
||||
default_git_date_regex+='[0-9]{1,2}\ ' # Day of the month
|
||||
default_git_date_regex+='[0-9]{2}:[0-9]{2}:[0-9]{2}\ ' # Time HH:MM:SS
|
||||
default_git_date_regex+='[0-9]{4}\ ' # Year
|
||||
default_git_date_regex+='[+-][0-9]{4}$' # Timezone offset
|
||||
|
||||
if [[ "$date_str" =~ $default_git_date_regex ]]; then
|
||||
# Move the year before the time to match a format that Date can parse
|
||||
date_str=$(echo "$date_str" | awk '{print $1, $2, $3, $5, $4, $6}')
|
||||
elif [[ "$date_str" =~ ^[0-9]{1,2}/[0-9]{1,2}/[0-9]{2,4} ]]; then
|
||||
# Handle DD/MM/YYYY format
|
||||
date_str=$(echo "$date_str" | awk -F'/' '{print $2"/"$1"/"$3}')
|
||||
fi
|
||||
# Extract the final date
|
||||
year=$(date -d "$date_str" '+%Y' 2>/dev/null)
|
||||
fi
|
||||
|
||||
echo "$year"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# DESC: Displays a horizontal bar graph based on total commits per year
|
||||
# ARGS: None
|
||||
@@ -869,38 +769,30 @@ function parse_year() {
|
||||
function commitsByYear() {
|
||||
optionPicked "Git commits by year:"
|
||||
local year startYear endYear __since __until
|
||||
startYear=$(echo "$_since" | sed -E 's/^.* ([0-9]{4})( .*)?$/\1/')
|
||||
endYear=$(echo "$_until" | sed -E 's/^.* ([0-9]{4})( .*)?$/\1/')
|
||||
|
||||
# Extract the date strings from $_since and $_until
|
||||
since_date="${_since#--since=}"
|
||||
until_date="${_until#--until=}"
|
||||
|
||||
# Grab the four digit year from $_since and $_until
|
||||
startYear=$(parse_year "$since_date")
|
||||
endYear=$(parse_year "$until_date")
|
||||
|
||||
echo -e "\tyear\tsum"
|
||||
# Add time strings to make these a touch more robust
|
||||
for year in $(seq "$startYear" "$endYear"); do
|
||||
if [[ "$year" = "$startYear" ]]; then
|
||||
__since=$_since
|
||||
__until="--until=$year-12-31 23:59:59"
|
||||
elif [[ "$year" = "$endYear" ]]; then
|
||||
__since="--since=$year-01-01 00:00:00"
|
||||
__until=$_until
|
||||
for year in $(seq "$startYear" "$endYear")
|
||||
do
|
||||
if [ "$year" = "$startYear" ]
|
||||
then
|
||||
__since=$_since
|
||||
__until="--until=$year-12-31"
|
||||
elif [ "$year" = "$endYear" ]
|
||||
then
|
||||
__since="--since=$year-01-01"
|
||||
__until=$_until
|
||||
else
|
||||
__since="--since=$year-01-01 00:00:00"
|
||||
__until="--until=$year-12-31 23:59:59"
|
||||
__since="--since=$year-01-01"
|
||||
__until="--until=$year-12-31"
|
||||
fi
|
||||
|
||||
# Count commits directly using git rev-list instead of git log
|
||||
commit_count=$(
|
||||
git rev-list --count $_merges \
|
||||
"$__since" "$__until" HEAD $_log_options
|
||||
)
|
||||
echo -e "\t$year\t$commit_count"
|
||||
# TODO: The bar graph can get funky when there are only a handful of
|
||||
# commits. We can set a max length to try to fix this, but this is a
|
||||
# bit of a problem across all the bar graphs.
|
||||
|
||||
echo -en "\t$year\t"
|
||||
git -c log.showSignature=false shortlog -n $_merges --format='%ad %s' \
|
||||
"$__since" "$__until" $_log_options | grep -cE \
|
||||
" \w\w\w [0-9]{1,2} [0-9][0-9]:[0-9][0-9]:[0-9][0-9] $year " \
|
||||
|| continue
|
||||
done | awk '{
|
||||
count[$1] = $2
|
||||
total += $2
|
||||
@@ -1078,7 +970,7 @@ function suggestReviewers() {
|
||||
optionPicked "Suggested code reviewers (based on git history):"
|
||||
git -c log.showSignature=false log --use-mailmap $_merges "$_since" "$_until" \
|
||||
--pretty=%aN $_log_options $_pathspec | head -n 100 | sort | uniq -c \
|
||||
| filter_ignored_authors | sort -nr | LC_ALL=C awk '
|
||||
| sort -nr | LC_ALL=C awk '
|
||||
{ args[NR] = $0; }
|
||||
END {
|
||||
for (i = 1; i <= NR; ++i) {
|
||||
@@ -1094,8 +986,8 @@ function suggestReviewers() {
|
||||
checkUtils
|
||||
|
||||
# Check if we are currently in a git repo.
|
||||
if ! git rev-parse --is-inside-work-tree > /dev/null; then
|
||||
echo "ERROR: You need to be inside a git repo to parse stats!"
|
||||
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
|
||||
echo "Not inside a git repository."
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
@@ -1186,13 +1078,6 @@ if [[ "$#" -eq 1 ]]; then
|
||||
read -r -p "Which author? " author
|
||||
done
|
||||
commitsByTimezone "${author}";;
|
||||
# ACTIVITY OPTIONS
|
||||
-k|--commits-calendar-by-author)
|
||||
author="${_GIT_AUTHOR:-}"
|
||||
while [[ -z "${author}" ]]; do
|
||||
read -r -p "Which author? " author
|
||||
done
|
||||
commitsCalendarByAuthor "${author}";;
|
||||
# SUGGEST OPTIONS
|
||||
-r|--suggest-reviewers) suggestReviewers;;
|
||||
-h|-\?|--help) usage;;
|
||||
@@ -1279,11 +1164,6 @@ while [[ "${opt}" != "" ]]; do
|
||||
done
|
||||
commitsByTimezone "${author}"; showMenu;;
|
||||
22) suggestReviewers; showMenu;;
|
||||
23) author=""
|
||||
while [[ -z "${author}" ]]; do
|
||||
read -r -p "Which author? " author
|
||||
done
|
||||
commitsCalendarByAuthor "${author}"; showMenu;;
|
||||
q|"\n") exit;;
|
||||
*) clear; optionPicked "Pick an option from the menu"; showMenu;;
|
||||
esac
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.TH git-quick-stats "1" "June 2025" "git-quick-stats" "User Commands"
|
||||
.TH git-quick-stats "1" "April 2024" "git-quick-stats" "User Commands"
|
||||
.SH NAME
|
||||
.B git\-quick\-stats
|
||||
\- Simple and efficient way to access various stats in a git repository.
|
||||
@@ -124,11 +124,6 @@ displays a list of commits per timezone
|
||||
.IP
|
||||
displays a list of commits per timezone by author
|
||||
.HP
|
||||
.PP
|
||||
\fB\-\-activity\-calendar\fR
|
||||
.IP
|
||||
displays a calendar-style grid of commit activity per day-of-week and month for a selected author.
|
||||
.HP
|
||||
.SH SUGGEST OPTIONS
|
||||
.PP
|
||||
\fB\-r\fR, \fB\-\-suggest\-reviewers\fR
|
||||
@@ -172,35 +167,5 @@ You can switch to the legacy color scheme, example:
|
||||
You can set _GIT_BRANCH to set the branch of the stats, example:
|
||||
.PP
|
||||
.B export _GIT_BRANCH="master"
|
||||
.PP
|
||||
.SH Calendar activity output
|
||||
.PP
|
||||
\fBactivity-calendar\fR outputs a visual grid of commit activity for a selected author, grouped by day-of-week (rows: Mon..Sun) and month (columns: Jan..Dec). Each cell is 3 characters wide, separated by one space.
|
||||
.PP
|
||||
Sample output:
|
||||
.PP
|
||||
.nf
|
||||
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
|
||||
Mon ▓▓▓ ░░░ ▒▒▒ ░░░ ░░░ ▒▒▒ ▓▓▓ ░░░ ░░░ ▓▓▓ ▒▒▒ ▒▒▒
|
||||
Tue ▒▒▒ ░░░ ▒▒▒ ░░░ ▒▒▒ ░░░ ▒▒▒ ▓▓▓ ▒▒▒ ░░░ ░░░ ░░░
|
||||
Wed ░░░ ▓▓▓ ░░░ ▓▓▓ ▒▒▒ ░░░ ░░░ ▒▒▒ ░░░ ░░░ ▓▓▓ ░░░
|
||||
Thu ░░░ ▒▒▒ ░░░ ░░░ ▒▒▒ ░░░ ▓▓▓ ▒▒▒ ▒▒▒ ░░░ ░░░ ▒▒▒
|
||||
Fri ▒▒▒ ░░░ ▒▒▒ ▓▓▓ ░░░ ▓▓▓ ▒▒▒ ░░░ ▒▒▒ ░░░ ▒▒▒ ░░░
|
||||
Sat ░░░ ░░░ ▒▒▒ ░░░ ░░░ ░░░ ▒▒▒ ░░░ ▒▒▒ ▓▓▓ ▒▒▒ ░░░
|
||||
Sun ▓▓▓ ░░░ ▓▓▓ ░░░ ░░░ ▓▓▓ ░░░ ▒▒▒ ░░░ ░░░ ▓▓▓ ░░░
|
||||
|
||||
Legend: ... = 0 ░░░ = 1–2 ▒▒▒ = 3–5 ▓▓▓ = 6+ commits
|
||||
.PP
|
||||
You can set _GIT_IGNORE_AUTHORS to filter out specific authors, example:
|
||||
.PP
|
||||
.B export _GIT_IGNORE_AUTHORS="(author@examle.com|username)"
|
||||
.
|
||||
.fi
|
||||
|
||||
.PP
|
||||
.SH SEE ALSO
|
||||
.BR git (1)
|
||||
.PP
|
||||
Project homepage:
|
||||
.UR https://github.com/git-quick-stats/git-quick-stats
|
||||
.UE
|
||||
Reference in New Issue
Block a user