Compare commits

...

27 Commits

Author SHA1 Message Date
arzzen
c467a9694b merge 2025-06-14 14:48:39 +02:00
arzzen
88e369503e link correction 2025-06-14 14:38:28 +02:00
arzzen
afd61ce9c2 Ignore authors #141 2025-06-14 14:30:56 +02:00
arzzen
d1641f7bf3 Merge pull request #181 from jwilk-forks/anchor-regexps
Anchor regexps in commitsPerAuthor()
2025-06-08 19:33:43 +02:00
arzzen
8de8c43212 Merge pull request #182 from jwilk-forks/json-spelling 2025-02-27 17:49:37 +01:00
Jakub Wilk
f4ec72073d Fix typo in JSON output 2025-02-24 08:40:54 +01:00
Jakub Wilk
b0003bef49 Anchor regexps in commitsPerAuthor()
Fixes:

    $ git clone -q https://github.com/util-linux/util-linux.git
    $ git -C util-linux quick-stats -a | grep -w uthor
            23    uthor                                    Karel Zak              0.1%
            3     uthor                                    Ondrej Oprala          0.0%
            2     uthor                                    Samuel Thibault        0.0%
            ...
2025-02-24 08:32:23 +01:00
arzzen
a833a5f431 Update .mailmap 2025-01-14 13:49:39 +01:00
arzzen
886f64f086 Merge pull request #180 from reitzig/patch-1
fix(docker): tell Git that the workdir is safe
2025-01-05 17:43:46 +01:00
Raphael
115b21a48d fix(docker): tell Git that the workdir is safe
When bind-mounting a Git repository to the workdir, Git would complain about 'dubious ownership'.

We add an exception to the global Git config, in the way Git tells us to.
This should be safe since
- we run in a container, and
- the user can set the mount to read-only.

refs: issue #179
2025-01-03 14:00:30 +01:00
arzzen
4d515b88b3 Update LICENSE 2024-10-27 14:07:49 +01:00
arzzen
9b3c0e5db1 Merge pull request #176 from tomice/bugfix/161-changelogs-wrong-output
Address inconsistency in changelogs
2024-10-25 20:26:54 +02:00
arzzen
86ad0af8bb Update FUNDING.yml 2024-10-25 20:18:35 +02:00
Tom Ice
fb488abe3e Address inconsistency in changelogs
* Original function lacked explicit sorting by time.
  Adding sorting by time within the same day to help make
  changelogs consistent.
2024-10-12 17:16:21 -04:00
arzzen
3cce04ddad Merge pull request #174 from tomice/master 2024-10-06 16:04:25 +02:00
Tom Ice
d4e56cf557 Adjust commitsByYear() to support multiple dates
* commitsByYear() previously could only support Default-style
  dates for git log. However, a user can use a variety of different
  date formats such as relative, default, iso, rfc, short, and raw.

  This change modifies commitsByYear() to handle multiple different
  date strings

Fixes #172
2024-10-01 20:43:39 -04:00
Tom Ice
cf239e5523 Update README.md
* Update README.md's screenshots to show new features added since last screenshots were taken
2024-09-19 20:45:36 -04:00
Tom Ice
a0f495894b Merge pull request #173 from laxdog/master
Fix stats for situation where there are no inserts / deletes
2024-09-19 16:20:32 -04:00
Tom Ice
4faf233ad1 Merge pull request #170 from funnelfiasco/issue169-add_new_contributors
Add a list of new contributors
2024-09-19 16:20:00 -04:00
Ben Cotton
7d5087795e Address more feedback
* Add date examples to prompts
* Update tests

Signed-off-by: Ben Cotton <bcotton@funnelfiasco.com>
2024-09-19 14:28:41 -04:00
Ben Cotton
fe2df31c36 Address review feedback
* Indicate how we're sorting new contributors
* Don't fork for `date` checks
* Include reference in the manpage

Signed-off-by: Ben Cotton <bcotton@funnelfiasco.com>
2024-09-19 11:57:38 -04:00
Michael Robinson
615563459f Fix stats for situation where there are no inserts / deletes 2024-09-17 15:39:48 +01:00
Ben Cotton
8c1d81a29d Add a list of new contributors
This reports generates a list of all contributors whose first commit was
after a specified date.

Fixes #169

Signed-off-by: Ben Cotton <bcotton@funnelfiasco.com>
2024-06-26 09:59:46 -04:00
Tom Ice
9f96cecf42 Merge pull request #167 from tomice/master
Update documentation for clarity
2024-05-17 22:05:55 -04:00
Tom Ice
5b01b5e055 Update documentation for clarity
* Added additional information to better explain how to use this
  on macOS.

* Updated some of the deps used

* Minor adjustments in the README.md

Addresses Issue #166
2024-05-16 15:23:16 -04:00
arzzen
32a84903ff Merge pull request #165 from chenrui333/patch-1
improve macos error message wrt gnu date
2024-04-29 15:46:11 +02:00
Rui Chen
cd6d67df06 improve macos error message wrt gnu date 2024-04-28 11:17:22 -04:00
9 changed files with 291 additions and 141 deletions

5
.github/FUNDING.yml vendored
View File

@@ -1,6 +1 @@
# These are supported funding model platforms
github: [arzzen]
open_collective: git-quick-stats
ko_fi: lukasmestan
custom: ['https://lukasmestan.com/thanks/']

View File

@@ -1,3 +1,3 @@
Lukas Mestan <lukas.mestan@gmail.com> Lukáš Mešťan <arzzen@users.noreply.github.com>
Lukas Mestan <lukas.mestan@gmail.com> arzzen
Lukas <test@gmail.com> Lukáš <arzzen@users.noreply.github.com>
Lukas <lukas@gmail.com> arzzen

View File

@@ -23,5 +23,6 @@ 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" ]

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021 Lukáš Mešťan
Copyright (c) 2024 git-quick-stats.sh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -30,8 +30,8 @@ uninstall:
@$(TASK_DONE)
reinstall:
@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
@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
$(MAKE) install
@$(TASK_DONE)

122
README.md
View File

@@ -1,13 +1,12 @@
# GIT quick statistics [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](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)
[![Backers on Open Collective](https://opencollective.com/git-quick-stats/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/git-quick-stats/sponsors/badge.svg)](#sponsors) [![Homebrew package](https://repology.org/badge/version-for-repo/homebrew/git-quick-stats.svg)](https://formulae.brew.sh/formula/git-quick-stats#default)
[![Homebrew package](https://repology.org/badge/version-for-repo/homebrew/git-quick-stats.svg)](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.
>
> 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/154823670-f42a111b-45f4-47fc-aea7-80059827c8e6.png)
> 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 :).
![mainMenuScreenshot](https://github.com/user-attachments/assets/05a20ff1-44f6-4e44-9d62-c2c089f9ff4e)
## Table of Contents
@@ -15,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)
@@ -50,14 +49,14 @@
[**Contributors**](#contributors)
* [**Backers**](#backers)
* [**Sponsors**](#sponsors)
- [**Backers**](#backers)
- [**Sponsors**](#sponsors)
## Screenshots
![commitsByWeekdayScreenshot](https://user-images.githubusercontent.com/8818630/154823677-e34ca867-ae61-4755-bf89-c877f809c591.png)
![commitsByWeekdayScreenshot](https://github.com/user-attachments/assets/3a55f3ac-8801-4bbf-9b3a-92b53a64631e)
![commitsByHourScreenshot](https://user-images.githubusercontent.com/8818630/154823679-bdadc26c-c644-4a01-b625-85e330f85d41.png)
![commitsByHourScreenshot](https://github.com/user-attachments/assets/d7de5280-8bb9-4391-9c6c-7e688f2df171)
## Usage
@@ -117,6 +116,8 @@ LIST OPTIONS
show branches by date
-C, --contributors
see a list of everyone who contributed to the repo
-n, --new-contributors
list everyone who made their first contribution since a specified date
-a, --commits-per-author
displays a list of commits per author
-d, --commits-per-day
@@ -203,6 +204,12 @@ 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`
@@ -211,7 +218,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/154823711-3dd0c268-f3cb-42e5-9094-0eb8e45d1761.png)
![legacyThemeScreenshot](https://github.com/user-attachments/assets/3b319c1a-827f-47b8-bbfa-b8b59a39deef)
## Installation
@@ -226,7 +233,7 @@ apt install git-quick-stats
### UNIX and Linux
```bash
git clone https://github.com/arzzen/git-quick-stats.git && cd git-quick-stats
git clone https://github.com/git-quick-stats/git-quick-stats.git && cd git-quick-stats
sudo make install
```
@@ -244,18 +251,34 @@ sudo make reinstall
### macOS (homebrew)
macOS requires GNU coreutils to be installed and for the non "g" aliased
versions to be exported to your path. The following is an example of how to
perform this if you are using Homebrew as your package manager.
```bash
brew install coreutils
export PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH"
```
From there, you can install via Homebrew as follows:
```bash
brew install git-quick-stats
```
Or you can follow the UNIX and Linux instructions if you wish.
If you would like to default to using the GNU coreutils (recommended), then you
can add `export PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH"` to
your applicable `~/.bash_profile`, `~/.zprofile`, or other relevant profile
based on the shell of your choice.
### Windows
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.
@@ -263,20 +286,21 @@ 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
basename
cat
column
date
echo
git
grep
@@ -291,17 +315,21 @@ uniq
### Dependencies
* [`bsdmainutils`](https://packages.debian.org/sid/bsdmainutils) `apt install bsdmainutils`
- [`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
@@ -315,13 +343,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
@@ -343,15 +371,15 @@ make test
MIT see [LICENSE][] for the full license text.
[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
[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
## Contributors
This project exists thanks to all the people who contribute.
[![contributors](https://opencollective.com/git-quick-stats/contributors.svg?width=890&button=false)](https://github.com/arzzen/git-quick-stats/graphs/contributors)
[![contributors](https://opencollective.com/git-quick-stats/contributors.svg?width=890&button=false)](https://github.com/git-quick-stats/git-quick-stats/graphs/contributors)
### Backers

View File

@@ -17,7 +17,7 @@ _since=${_GIT_SINCE:-}
if [[ -n "${_since}" ]]; then
_since="--since=$_since"
else
_since="--since=$(git log --reverse --format='%ad' | head -n1)"
_since="--since=$(git log --reverse --format='%ad' --date=iso | head -n1)"
fi
# End of git log date. Respects all git datetime formats
@@ -68,6 +68,14 @@ 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}"
@@ -82,8 +90,8 @@ _theme="${_MENU_THEME:=default}"
################################################################################
function checkUtils() {
readonly MSG="not found. Please make sure this is installed and in PATH."
readonly UTILS="awk basename cat column echo git grep head printf seq sort \
tput tr uniq"
readonly UTILS="awk basename cat column date echo git grep head printf seq \
sort tput tr uniq"
for u in $UTILS
do
@@ -99,9 +107,10 @@ function checkUtils() {
# the user that this will not work rather than having it silently bomb out
# during runtime.
if ! date --version >/dev/null 2>&1; then
echo "ERROR: You must have GNU date installed."
echo "If you're on macOS, please use brew to install this utility."
echo "Make sure the GNU version of date is symlinked to 'date', too."
echo "ERROR: GNU date is required."
echo "If you're on macOS, please install it using 'brew install coreutils'."
echo "Ensure that your PATH is configured to use GNU date as well."
echo "See the README.md for further details."
exit 1
fi
}
@@ -117,24 +126,6 @@ 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
@@ -181,6 +172,8 @@ LIST OPTIONS
show branches by date
-C, --contributors
see a list of everyone who contributed to the repo
-n, --new-contributors
list everyone who made their first contribution since a specified date
-a, --commits-per-author
displays a list of commits per author
-d, --commits-per-day
@@ -224,7 +217,9 @@ 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"
ex: export _GIT_BRANCH=master
You can set _GIT_IGNORE_AUTHORS to filter out specific authors
ex: export _GIT_IGNORE_AUTHORS=\"(author1|author2)\""
}
################################################################################
@@ -273,23 +268,32 @@ function showMenu() {
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 year\\n"
printf %b "${NUMS} 15)${TEXT} Git commits per weekday\\n"
printf %b "${NUMS} 16)${TEXT} Git commits per weekday by author\\n"
printf %b "${NUMS} 17)${TEXT} Git commits per hour\\n"
printf %b "${NUMS} 18)${TEXT} Git commits per hour by author\\n"
printf %b "${NUMS} 19)${TEXT} Git commits per timezone\\n"
printf %b "${NUMS} 20)${TEXT} Git commits per timezone by author\\n"
printf %b "${NUMS} 11)${TEXT} New contributors (sorted by email)\\n"
printf %b "${NUMS} 12)${TEXT} Git commits per author\\n"
printf %b "${NUMS} 13)${TEXT} Git commits per date\\n"
printf %b "${NUMS} 14)${TEXT} Git commits per month\\n"
printf %b "${NUMS} 15)${TEXT} Git commits per year\\n"
printf %b "${NUMS} 16)${TEXT} Git commits per weekday\\n"
printf %b "${NUMS} 17)${TEXT} Git commits per weekday by author\\n"
printf %b "${NUMS} 18)${TEXT} Git commits per hour\\n"
printf %b "${NUMS} 19)${TEXT} Git commits per hour by author\\n"
printf %b "${NUMS} 20)${TEXT} Git commits per timezone\\n"
printf %b "${NUMS} 21)${TEXT} Git commits per timezone by author\\n"
printf %b "\\n${TITLES} Suggest:\\n"
printf %b "${NUMS} 21)${TEXT} Code reviewers (based on git history)\\n"
printf %b "${NUMS} 22)${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
}
filter_ignored_authors() {
if [[ -n "$_ignore_authors" ]]; then
grep -Ev "$_ignore_authors"
else
cat
fi
}
################################################################################
# FUNCTIONS FOR GENERATING STATS
@@ -336,11 +340,15 @@ function detailedGitStats() {
if(more["total"] > 0) {
printf "\t insertions: %d\t(%.0f%%)\n", more[author], \
(more[author] / more["total"] * 100)
} else {
printf "\t insertions: %d\t(%.0f%%)\n", 0, 0
}
if(less["total"] > 0) {
printf "\t deletions: %d\t(%.0f%%)\n", less[author], \
(less[author] / less["total"] * 100)
} else {
printf "\t deletions: %d\t(%.0f%%)\n", 0, 0
}
if(file["total"] > 0) {
@@ -408,8 +416,9 @@ function detailedGitStats() {
# OUTS: None
################################################################################
function changelogs() {
local author="${1:-}"
local _author=""
local commits=""
local author="${1:-}"
local next=$(date +%F)
if [[ -z "${author}" ]]; then
@@ -427,14 +436,20 @@ function changelogs() {
--date=short "${_author}" "$_since" "$_until" $_log_options $_pathspec \
| sort -u -r | head -n $_limit \
| while read DATE; do
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
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
}
################################################################################
@@ -491,17 +506,21 @@ 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 | LC_ALL=C awk '
"$_since" "$_until" $_log_options $_pathspec | filter_ignored_authors | LC_ALL=C awk '
function printStats(author) {
printf "%s,", author
if(more["total"] > 0) {
printf "%d,%.0f%%,", more[author], \
(more[author] / more["total"] * 100)
} else {
printf "0,0%%,"
}
if(less["total"] > 0) {
printf "%d,%.0f%%,", less[author], \
(less[author] / less["total"] * 100)
} else {
printf "0,0%%,"
}
if(file["total"] > 0) {
@@ -633,7 +652,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 "commiter": {%n'\
' "date": "%aD"%n },%n "committer": {%n'\
"$propTag"' name%n%cN%n'"$propTag"',%n'\
"$propTag"' email%n%cE%n'"$propTag"',%n'\
' "date": "%cD"%n }%n},' \
@@ -681,7 +700,27 @@ 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 | sort -u | cat -n
--format='%aN' $_log_options $_pathspec | filter_ignored_authors | sort -u | cat -n
}
################################################################################
# DESC: Lists all new contributors to a repo since the specified time
# ARGS: $newDate (required): Cutoff date for being considered "new"
# OUTS: None
################################################################################
function newContributors() {
optionPicked "New contributors since $newDate:"
local contributors=$(git -c log.showSignature=false log --use-mailmap $_merges \
"$_since" "$_until" --format='%aE' $_log_options \
$_pathspec | sort -u)
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)
if [[ $firstCommit -ge $(date -d "$newDate" +%s) ]]; then
echo "$c"
fi
done
}
################################################################################
@@ -694,10 +733,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}"
@@ -729,6 +768,47 @@ 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
@@ -737,30 +817,38 @@ function commitsPerDay() {
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"
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
# 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
else
__since="--since=$year-01-01"
__until="--until=$year-12-31"
__since="--since=$year-01-01 00:00:00"
__until="--until=$year-12-31 23:59:59"
fi
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
# 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.
done | awk '{
count[$1] = $2
total += $2
@@ -938,7 +1026,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 \
| sort -nr | LC_ALL=C awk '
| filter_ignored_authors | sort -nr | LC_ALL=C awk '
{ args[NR] = $0; }
END {
for (i = 1; i <= NR; ++i) {
@@ -954,7 +1042,11 @@ function suggestReviewers() {
checkUtils
# Check if we are currently in a git repo.
git rev-parse --is-inside-work-tree > /dev/null
if ! git rev-parse --is-inside-work-tree > /dev/null; then
echo "ERROR: You need to be inside a git repo to parse stats!"
usage
exit 1
fi
# Parse non-interative commands
if [[ "$#" -eq 1 ]]; then
@@ -1003,6 +1095,20 @@ if [[ "$#" -eq 1 ]]; then
-b|--branch-tree) branchTree;;
-D|--branches-by-date) branchesByDate;;
-C|--contributors) contributors;;
-n|--new-contributors)
newDate=""
while [[ -z "${newDate}" ]]; do
read -r -p "Since what date? (e.g. '2023-04-13', '13 April 2023', 'last Thursday') " newDate
# Test if the date provide is valid and try again if it isn't.
# date(1) is pretty accepting of time stamps but you never know
# what people may try. This script doesn't provide any additional
# output for a bad date since `date`'s STDERR already contains
# useful information.
if ! date -d "${newDate}" +%s > /dev/null 2>&1; then
newDate=""
fi
done
newContributors "${newDate}";;
-a|--commits-per-author) commitsPerAuthor;;
-d|--commits-per-day) commitsPerDay;;
-Y|--commits-by-year ) commitsByYear;;
@@ -1082,29 +1188,38 @@ while [[ "${opt}" != "" ]]; do
8) branchTree; showMenu;;
9) branchesByDate; showMenu;;
10) contributors; showMenu;;
11) commitsPerAuthor; showMenu;;
12) commitsPerDay; showMenu;;
13) commitsByMonth; showMenu;;
14) commitsByYear; showMenu;;
15) commitsByWeekday; showMenu;;
16) author=""
11) newDate=""
while [[ -z "${newDate}" ]]; do
read -r -p "Since what date? (e.g. '2023-04-13', '13 April 2023', 'last Thursday') " newDate
# Test if the date provide is valid and try again if it isn't.
if ! date -d "${newDate}" +%s > /dev/null 2>&1; then
newDate=""
fi
done
newContributors "${newDate}"; showMenu;;
12) commitsPerAuthor; showMenu;;
13) commitsPerDay; showMenu;;
14) commitsByMonth; showMenu;;
15) commitsByYear; showMenu;;
16) commitsByWeekday; showMenu;;
17) author=""
while [[ -z "${author}" ]]; do
read -r -p "Which author? " author
done
commitsByWeekday "${author}"; showMenu;;
17) commitsByHour; showMenu;;
18) author=""
18) commitsByHour; showMenu;;
19) author=""
while [[ -z "${author}" ]]; do
read -r -p "Which author? " author
done
commitsByHour "${author}"; showMenu;;
19) commitsByTimezone; showMenu;;
20) author=""
20) commitsByTimezone; showMenu;;
21) author=""
while [[ -z "${author}" ]]; do
read -r -p "Which author? " author
done
commitsByTimezone "${author}"; showMenu;;
21) suggestReviewers; showMenu;;
22) suggestReviewers; showMenu;;
q|"\n") exit;;
*) clear; optionPicked "Pick an option from the menu"; showMenu;;
esac

View File

@@ -70,6 +70,11 @@ show branches by date
see a list of everyone who contributed to the repo
.HP
.PP
\fB\-n\fR, \fB\-\-new\-contributors\fR
.IP
list everyone who made their first contribution since a specified date
.HP
.PP
\fB\-a\fR, \fB\-\-commits\-per\-author\fR
.IP
displays a list of commits per author
@@ -162,5 +167,9 @@ 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
You can set _GIT_IGNORE_AUTHORS to filter out specific authors, example:
.PP
.B export _GIT_IGNORE_AUTHORS="(author@examle.com|username)"
.
.fi

View File

@@ -50,6 +50,8 @@ LIST OPTIONS
show branches by date
-C, --contributors
see a list of everyone who contributed to the repo
-n, --new-contributors
list everyone who made their first contribution since a specified date
-a, --commits-per-author
displays a list of commits per author
-d, --commits-per-day