Compare commits

..

40 Commits
2.3.0 ... 2.5.7

Author SHA1 Message Date
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
Tom Ice
00d13c0b79 Merge pull request #164 from tomice/master
Handle error where BSD date is being used
Create new repo if running tests in non-git area
2024-04-27 13:43:51 -04:00
Tom Ice
b525ed3b5c Create new repo if running tests in non-git area
* When running "make test" in the root directory of this codebase,
  an error will occur as this shell script requires a repo to be
  initialized before it can properly execute.

  This was done in the past, but at some point, it was removed.
  This adds the feature back, tests if we are in a git directory
  by using a built-in git command, and only performs this action
  if a git repo doesn't already exist. All actions are sent to
  /dev/null so the testing should look opaque to the end user.

  Note that tests will still fail if a user is missing a required
  utility to perform the functionality of git-quick-stats.

* Fixed a typo in the man page

Fixes #162
2024-04-20 17:31:12 -04:00
Tom Ice
41a8542aaa Handle error where BSD date is being used
* Users on macOS and other older distributions of Linux and Unix
  cannot fully utilize this application as a handful of date/time
  strings in here are specific to the GNU utility found on most
  modern version of Linux.

  Until every date/time case is handled between the BSD version of
  date and the GNU version of date, let's error out akin to how we
  do it if the user doesn't have every utility installed to run
  this script.

  Users can get around this by using package managers on macOS such
  as homebrew, macports, etc and making sure that 'date' points to
  the GNU version of date instead of the BSD version. Linux and
  Unix users can get around this by installing the GNU version of
  date, as well.

* Removed checking OSTYPE in the format_date() function as checking
  if someone is on a machine that identifies as Darwin is not enough
  to handle other edge cases where an older version of BSD date
  might be present on the system.
2024-04-20 14:15:07 -04:00
arzzen
7b1e0b2a65 Merge pull request #157 from Dica-Developer/41
calculate the day before the given since date
2024-01-10 08:13:40 +01:00
Martin Schaaf
43bc82520e calculate the day before the given since date as it excludes the given daten the inclusion is wanted 2024-01-09 16:40:28 +01:00
arzzen
d33ede9bcc Merge pull request #142 from cam-rod/timezone-format
Update formatting and sort commits by timezone
2023-12-22 16:18:52 +01:00
arzzen
7f24d202b9 Merge pull request #155 from fox-forks/hyperupcall-document-defualt-git-limit
docs: Document default `_GIT_LIMIT` value
2023-12-22 16:17:22 +01:00
Edwin Kofler
62b128a3ce docs: Document default _GIT_LIMIT value 2023-11-18 17:44:29 -08:00
arzzen
8515fe3a94 cleanup 2023-10-24 18:13:00 +02:00
arzzen
37bfde67ed Merge pull request #153 from arzzen/arzzen-patch-1 2023-10-24 15:33:53 +02:00
arzzen
d886facadf fix format date 2023-10-24 14:52:00 +02:00
arzzen
aa6619508a Update git-quick-stats
fix #152
2023-10-24 09:34:29 +02:00
arzzen
a813846c9f Merge pull request #151 from YDX-2147483647/patch-1
fix: Ubuntu does not support `date -j`
2023-10-17 06:26:33 +02:00
Y.D.X
22bf354da4 fix: Ubuntu does not support date -j
This is required for changelogs.

Resolves #147
2023-10-09 17:29:08 +08:00
arzzen
0fea0323a4 Merge pull request #150 from riderius/master 2023-10-04 20:50:24 +02:00
riderius
4fcf8f5fef test: fix a typo in the 1st test
Signed-off-by: riderius <riderius.help@gmail.com>
2023-10-04 18:27:38 +03:00
arzzen
374aa2ef72 Merge pull request #145 from s-okita/master
Add stats by author per weekday functionality
2023-06-23 15:01:04 +02:00
s-okita
33dca7f3ed Update git-quick-stats.1 2023-06-23 17:07:18 +09:00
s-okita
2ecb296442 Merge branch 'arzzen:master' into master 2023-06-07 02:42:22 +09:00
arzzen
428d25d0ef Merge pull request #144 from jgtoriginal/master
add day name to date
2023-06-06 14:58:29 +02:00
s-okita
c3110e985e Add stats by author per weekday functionality
* Added the ability to see git stats both per weekday, as well as
  by author per weekday. It should respect all global options.

* Updated tests, README.md, and man page to reflect the new changes
2023-06-06 19:36:47 +09:00
jgtoriginal
ebbeb34837 add day name to date
when grouping by author -L, I found it hard to read YYYY-MM-DD, so added day name to that.
2023-05-25 01:14:05 +01:00
Cameron Rodriguez
6cdca7c7c7 Sort, use more stable formatting for commits by timezone
Switch to `git log` for formatting commits sorted by timezone, to avoid
odd formatting cases. Also sorts timezones from negative to positive.
2023-04-04 22:30:35 -04:00
Tom Ice
71d414eb4a Merge pull request #137 from pyxide/fix/json-format-output
fix: json format output with multiline content
2022-07-11 16:09:01 -04:00
pyxide
d8346210a4 fix: json format output with multiline content 2022-07-11 19:15:07 +02:00
Tom Ice
b85760e8b9 Merge pull request #136 from dotmpe/master
Misc. fixes on filtering, added commits-by-year
2022-02-26 21:01:26 -05:00
B. van Berkum
07ad3b57a7 Updated screenshot URLs after PR#136 changes 2022-02-24 04:54:27 +01:00
B. van Berkum
dec1c4e103 Add --commits-by-year; put 'since' at first commit
- Added commits-by-year graph/statistics.
- Made 'since' use first reachable commit, instead of GIT epoch (May
  2005). To avoid empty bars in the new 'Commits by years' graph.

- Removed start-/end-year filter: on -by-weekday, -hour and -month. Instead
  made each `grep` look for its date tag fixed in a more specific sequence
  so as to not match commit message.

  Was giving problems if a since/until date-span larger than one year was given
  (ie. #135, #130, #123).

  Maybe should look at removing commit message from log listing entirely.
  Not sure why `grep -E "($startYear|$endYear)"` was ever introduced yet.

- Made tests run properly, updated test with usage output.
  Added a test-case with LC_TIME=POSIX.
2022-02-19 00:01:07 +01:00
Lukáš Mešťan
2a0294941f Update README.md 2021-08-19 09:16:37 +02:00
8 changed files with 390 additions and 67 deletions

5
.gitignore vendored
View File

@@ -7,4 +7,7 @@
.Spotlight*
.Trash*
**/*~
nbproject/*
nbproject/*
/tests/test-git/.git/
#/tests/test-git/*
!/tests/test-git/resetgit

View File

@@ -3,6 +3,7 @@ _INSTDIR ?= $(DESTDIR)$(PREFIX)
BINDIR ?= $(_INSTDIR)/bin
MANDIR ?= $(_INSTDIR)/share/man
TASK_DONE = echo -e "\n✓ $@ done\n"
SHELL := $(shell which bash)
.PHONY: test

View File

@@ -1,11 +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)
# GIT quick statistics [![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) [![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) [![Travis](https://api.travis-ci.org/arzzen/git-quick-stats.svg?branch=master)](https://travis-ci.org/arzzen/git-quick-stats) [![Homebrew package](https://repology.org/badge/version-for-repo/homebrew/git-quick-stats.svg)](https://formulae.brew.sh/formula/git-quick-stats#default) [![Linuxbrew package](https://repology.org/badge/version-for-repo/linuxbrew/git-quick-stats.svg)](https://repology.org/metapackage/git-quick-stats/packages)
[![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)
> `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 :).
> 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://user-images.githubusercontent.com/8818630/121750502-8223d600-cada-11eb-94bc-470be4e22ba4.png)
![mainMenuScreenshot](https://github.com/user-attachments/assets/05a20ff1-44f6-4e44-9d62-c2c089f9ff4e)
## Table of Contents
@@ -53,9 +54,9 @@
## Screenshots
![commitsByWeekdayScreenshot](https://user-images.githubusercontent.com/8818630/121750517-8819b700-cada-11eb-99a0-a72942822da5.png)
![commitsByWeekdayScreenshot](https://github.com/user-attachments/assets/3a55f3ac-8801-4bbf-9b3a-92b53a64631e)
![commitsByHourScreenshot](https://user-images.githubusercontent.com/8818630/121750525-8c45d480-cada-11eb-8054-78716ce6623c.png)
![commitsByHourScreenshot](https://github.com/user-attachments/assets/d7de5280-8bb9-4391-9c6c-7e688f2df171)
## Usage
@@ -115,14 +116,20 @@ 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
displays a list of commits per day
-Y, --commits-by-year
displays a list of commits per year
-m, --commits-by-month
displays a list of commits per month
-w, --commits-by-weekday
displays a list of commits per weekday
-W, --commits-by-author-by-weekday
displays a list of commits per weekday by author
-o, --commits-by-hour
displays a list of commits per hour
-A, --commits-by-author-by-hour
@@ -152,7 +159,7 @@ Once set, run `git quick-stats` as normal. Note that this affects all stats that
### Git log limit
You can set variable `_GIT_LIMIT` for limited output. It will affect the "changelogs" and "branch tree" options.
You can set variable `_GIT_LIMIT` for limited output. It will affect the "changelogs" and "branch tree" options. The default limit is `10`.
```bash
export _GIT_LIMIT=20
@@ -205,7 +212,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/121750530-8f40c500-cada-11eb-808c-5f5fb81801d2.png)
![legacyThemeScreenshot](https://github.com/user-attachments/assets/3b319c1a-827f-47b8-bbfa-b8b59a39deef)
## Installation
@@ -238,12 +245,28 @@ 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:
@@ -271,6 +294,7 @@ awk
basename
cat
column
date
echo
git
grep
@@ -281,12 +305,15 @@ sort
tput
tr
uniq
wc
```
### 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

View File

@@ -11,13 +11,13 @@ set -o nounset
set -o errexit
# Beginning git log date. Respects all git datetime formats
# If $_GIT_SINCE is never set, choose epoch time as that is
# as far back as git will allow you to go
# If $_GIT_SINCE is never set, look at the repository to find the first date.
# NOTE: previously this put the date at the fixed GIT epoch (May 2005)
_since=${_GIT_SINCE:-}
if [[ -n "${_since}" ]]; then
_since="--since=$_since"
else
_since="--since=2005-04-07"
_since="--since=$(git log --reverse --format='%ad' | head -n1)"
fi
# End of git log date. Respects all git datetime formats
@@ -27,7 +27,7 @@ _until=${_GIT_UNTIL:-}
if [[ -n "${_until}" ]]; then
_until="--until=$_until"
else
_until="--until=$(date)"
_until="--until=$(date '+%a, %d %b %Y %H:%M:%S %Z')"
fi
# Set files or directories to be excluded in stats
@@ -82,13 +82,29 @@ _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 wc"
readonly UTILS="awk basename cat column date echo git grep head printf seq \
sort tput tr uniq"
for u in $UTILS
do
command -v "$u" >/dev/null 2>&1 || { echo >&2 "$u ${MSG}"; exit 1; }
done
# NOTE: The --version flag is only available in GNU date which is required
# for how the current date/time strings are used in this shell script.
# To fully support the legacy BSD date found in a default install within
# macOS and older distributions of Linux and Unix, a handful of helper
# functions can probably be created to handle every case of incompatibility
# between the two. Until that's implemented, it is probably best to warn
# 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: 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
}
################################################################################
@@ -102,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
@@ -148,14 +182,20 @@ 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
displays a list of commits per day
-m, --commits-by-month
displays a list of commits per month
-Y, --commits-by-year
displays a list of commits per year
-w, --commits-by-weekday
displays a list of commits per weekday
-W, --commits-by-author-by-weekday
displays a list of commits per weekday by author
-o, --commits-by-hour
displays a list of commits per hour
-A, --commits-by-author-by-hour
@@ -236,16 +276,19 @@ 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 weekday\\n"
printf %b "${NUMS} 15)${TEXT} Git commits per hour\\n"
printf %b "${NUMS} 16)${TEXT} Git commits per hour by author\\n"
printf %b "${NUMS} 17)${TEXT} Git commits per timezone\\n"
printf %b "${NUMS} 18)${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} 19)${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
@@ -297,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) {
@@ -388,11 +435,12 @@ function changelogs() {
--date=short "${_author}" "$_since" "$_until" $_log_options $_pathspec \
| sort -u -r | head -n $_limit \
| while read DATE; do
echo -e "\n[$DATE]"
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 --until=$next
--since==$(date -d "$DATE - 1 day" +"%Y-%m-%d") --until=$next
next=$DATE
done
}
@@ -416,7 +464,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 -E "commit [a-f0-9]{40}" | wc -l) "commits"
| grep -cE "commit [a-f0-9]{40}") "commits"
}
################################################################################
@@ -457,11 +505,15 @@ function csvOutput() {
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) {
@@ -516,6 +568,67 @@ function csvOutput() {
}'
}
################################################################################
# DESC: Transforms special multiline string sequence to a JSON string property.
# {propTag}{optional white space indentation}{property}
# {line1}
# {line2}
# ...
# {propTag}, (the final comma is optional)
# Generates: "{property}": "{line1}\n{line2}\n...",
# The final comma is added if present after the ending tag.
# Caveat: the content should not contain {propTag} at the
# beginning of a line.
# ARGS: $propTag (optional) : tag at the beginning of the line to mark the
# beginning and the end of a special sequence. It must not contain
# regular expression special characters, i.e. use [a-zA-Z0-9_]+.
# This tag should be sufficiently random to avoid collision with
# the actual content. Defaults to __JSONPROP__.
# OUTS: content with JSON string properties
################################################################################
function toJsonProp() {
local propTag="${1:-__JSONPROP__}"
sed -n -E '
# transforms the special sequence.
/^'"$propTag"'[^\r]/ {
# remove the special prefix, keep the property name followed by :
s/^'"$propTag"'([^\r]+)\r?$/\1:/g;
# hold in buffer, get the next line.
h;n
# loop
b eos
:eos {
# add in hold buffer and loop while the string is not finished.
/^'"$propTag"',?\r?$/ ! { H; n; b eos; }
# end of the string, flip buffer to current pattern.
# keeps the comma if any, or a space as an empty placeholder.
/,\r?$/ ! { x; s/\r?$/ / }
/,\r?$/ { x; s/\r?$/,/ }
}
# replace special JSON string chars.
s/["\\]/\\&/g;
# replace control chars, carriage returns, line feeds, tabulations, etc.
s/\x00/\\u0000/g; s/\x01/\\u0001/g; s/\x02/\\u0002/g; s/\x03/\\u0003/g;
s/\x04/\\u0004/g; s/\x05/\\u0005/g; s/\x06/\\u0006/g; s/\x07/\\u0007/g;
s/\x08/\\b/g; s/\x09/\\t/g; s/\x0a/\\n/g; s/\x0b/\\u000b/g;
s/\x0c/\\f/g; s/\x0d/\\r/g; s/\x0e/\\u000e/g; s/\x0f/\\u000f/g;
s/\x10/\\u0010/g; s/\x11/\\u0011/g; s/\x12/\\u0012/g; s/\x13/\\u0013/g;
s/\x14/\\u0014/g; s/\x15/\\u0015/g; s/\x16/\\u0016/g; s/\x17/\\u0017/g;
s/\x18/\\u0018/g; s/\x19/\\u0019/g; s/\x1a/\\u001a/g; s/\x1b/\\u001b/g;
s/\x1c/\\u001c/g; s/\x1d/\\u001d/g; s/\x1e/\\u001e/g; s/\x1f/\\u001f/g;
s/\x7f/\\u007f/g;
# format the JSON property name, optionally indented, open quote for value.
s/^(\s*)([^:]+):\\n/\1"\2": "/g;
# handle the final comma if present, and close the quote for value.
/,$/ { s/,$/",/g; }
# otherwise remove final space placeholder and close the quote for value.
/,$/ ! { s/ $/"/g; }
}
# print lines.
p'
}
################################################################################
# DESC: Saves the git log output in a JSON format
# ARGS: $json_path (required): Path to where the file is saved
@@ -523,10 +636,20 @@ function csvOutput() {
################################################################################
function jsonOutput() {
optionPicked "Output log saved to file at: ${json_path}/output.json"
# TODO: Can we shorten this pretty format line? Quick experiment shows that
# it does not properly respect \ and interprets them literally.
local propTag="__JSONPROP${RANDOM}__"
git -c log.showSignature=false log --use-mailmap $_merges "$_since" "$_until" $_log_options \
--pretty=format:'{%n "commit": "%H",%n "abbreviated_commit": "%h",%n "tree": "%T",%n "abbreviated_tree": "%t",%n "parent": "%P",%n "abbreviated_parent": "%p",%n "refs": "%D",%n "encoding": "%e",%n "subject": "%s",%n "sanitized_subject_line": "%f",%n "body": "%b",%n "commit_notes": "%N",%n "author": {%n "name": "%aN",%n "email": "%aE",%n "date": "%aD"%n },%n "commiter": {%n "name": "%cN",%n "email": "%cE",%n "date": "%cD"%n }%n},' \
--pretty=format:'{%n "commit": "%H",%n "abbreviated_commit": "%h",%n "tree": "%T",%n'\
' "abbreviated_tree": "%t",%n "parent": "%P",%n "abbreviated_parent": "%p",%n "refs": "%D",%n "encoding": "%e",%n'\
"$propTag"' subject%n%s%n'"$propTag"',%n "sanitized_subject_line": "%f",%n'\
"$propTag"' body%n%b%n'"$propTag"',%n'\
"$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'\
"$propTag"' name%n%cN%n'"$propTag"',%n'\
"$propTag"' email%n%cE%n'"$propTag"',%n'\
' "date": "%cD"%n }%n},' \
| toJsonProp "$propTag" \
| sed "$ s/,$//" \
| sed ':a;N;$!ba;s/\r\n\([^{]\)/\\n\1/g' \
| awk 'BEGIN { print("[") } { print($0) } END { print("]") }' \
@@ -573,6 +696,26 @@ function contributors() {
--format='%aN' $_log_options $_pathspec | 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 | head -n 1)
if [[ $firstCommit -ge $(date -d "$newDate" +%s) ]]; then
echo "$c"
fi
done
}
################################################################################
# DESC: Displays the number of commits and percentage contributed to the repo
# per author and sorts them by contribution percentage
@@ -618,6 +761,56 @@ function commitsPerDay() {
--date=short --format='%ad' $_log_options $_pathspec | sort | uniq -c
}
################################################################################
# DESC: Displays a horizontal bar graph based on total commits per year
# ARGS: None
# OUTS: None
################################################################################
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/')
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
else
__since="--since=$year-01-01"
__until="--until=$year-12-31"
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
done | awk '{
count[$1] = $2
total += $2
}
END{
for (year in count) {
s="|";
if (total > 0) {
percent = ((count[year] / total) * 100) / 1.25;
for (i = 1; i <= percent; ++i) {
s=s"█"
}
printf( "\t%s\t%-0s\t%s\n", year, count[year], s );
}
}
}' | sort
}
################################################################################
# DESC: Displays a horizontal bar graph based on total commits per month
# ARGS: None
@@ -626,14 +819,13 @@ function commitsPerDay() {
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}")
local i
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 -E "($startYear|$endYear)" \
| grep " $i " | wc -l
"$_since" "$_until" $_log_options |
grep -cE " \w\w\w $i [0-9]{1,2} " || continue
done | awk '{
count[$1] = $2
total += $2
@@ -658,17 +850,25 @@ function commitsByMonth() {
# OUTS: None
################################################################################
function commitsByWeekday() {
optionPicked "Git commits by weekday:"
local author="${1:-}"
local _author=""
if [[ -z "${author}" ]]; then
optionPicked "Git commits by weekday:"
_author="--author=**"
else
optionPicked "Git commits by weekday for author '${author}':"
_author="--author=${author}"
fi
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
local i 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 -E "($startYear|$endYear)" \
| grep "$i " | wc -l
"${_author}" "$_since" "$_until" $_log_options |
grep -cE "^ * $i \w\w\w [0-9]{1,2} " || continue
counter=$((counter+1))
done | awk '{
}
@@ -710,14 +910,13 @@ function commitsByHour() {
fi
echo -e "\thour\tsum"
local startYear=$(echo "$_since" | grep -Eo "[0-9]{4}")
local endYear=$(echo "$_until" | grep -Eo "[0-9]{4}")
local i
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 -E "($startYear|$endYear)" | grep ' '$i: | wc -l
git -c log.showSignature=false shortlog -n $_merges --format='%ad %s' \
"${_author}" "$_since" "$_until" $_log_options |
grep -cE '[0-9] '$i':[0-9]' || continue
done | awk '{
count[$1] = $2
total += $2
@@ -754,9 +953,9 @@ function commitsByTimezone() {
fi
echo -e "Commits\tTimeZone"
git -c log.showSignature=false shortlog -n $_merges --format='%ad %s' \
git -c log.showSignature=false log $_merges --format='%ad %s' \
"${_author}" "$_since" "$_until" --date=iso $_log_options $_pathspec \
| cut -d " " -f 12 | grep -v -e '^[[:space:]]*$' | sort | uniq -c
| cut -d " " -f 3 | grep -v -e '^[[:space:]]*$' | sort -n | uniq -c
}
################################################################################
@@ -836,10 +1035,31 @@ 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;;
-m|--commits-by-month) commitsByMonth;;
-w|--commits-by-weekday) commitsByWeekday;;
-W|--commits-by-author-by-weekday)
author="${_GIT_AUTHOR:-}"
while [[ -z "${author}" ]]; do
read -r -p "Which author? " author
done
commitsByWeekday "${author}";;
-o|--commits-by-hour) commitsByHour;;
-A|--commits-by-author-by-hour)
author="${_GIT_AUTHOR:-}"
@@ -848,7 +1068,7 @@ if [[ "$#" -eq 1 ]]; then
done
commitsByHour "${author}";;
-z|--commits-by-timezone) commitsByTimezone;;
-Z|--commits-by-author-by-timezone)
-Z|--commits-by-author-by-timezone)
author="${_GIT_AUTHOR:-}"
while [[ -z "${author}" ]]; do
read -r -p "Which author? " author
@@ -908,23 +1128,38 @@ while [[ "${opt}" != "" ]]; do
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=""
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;;
18) commitsByHour; showMenu;;
19) author=""
while [[ -z "${author}" ]]; do
read -r -p "Which author? " author
done
commitsByHour "${author}"; showMenu;;
17) commitsByTimezone; showMenu;;
18) author=""
20) commitsByTimezone; showMenu;;
21) author=""
while [[ -z "${author}" ]]; do
read -r -p "Which author? " author
done
commitsByTimezone "${author}"; showMenu;;
19) suggestReviewers; showMenu;;
22) suggestReviewers; showMenu;;
q|"\n") exit;;
*) clear; optionPicked "Pick an option from the menu"; showMenu;;
esac

View File

@@ -1,4 +1,4 @@
.TH git-quick-stats "1" "June 2021" "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.
@@ -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
@@ -85,11 +90,21 @@ displays a list of commits per day
displays a list of commits per month
.HP
.PP
\fB\-Y\fR, \fB\-\-commits\-by\-year\fR
.IP
displays a list of commits per year
.HP
.PP
\fB\-w\fR, \fB\-\-commits\-by\-weekday\fR
.IP
displays a list of commits per weekday
.HP
.PP
\fB\-W\fR, \fB\-\-commits\-by\-author\-by\-weekday\fR
.IP
displays a list of commits per weekday by author
.HP
.PP
\fB\-o\fR, \fB\-\-commits\-by\-hour\fR
.IP
displays a list of commits per hour

View File

@@ -79,7 +79,7 @@ assert_end() {
tests_endtime="$(date +%s%N)"
# required visible decimal place for seconds (leading zeros if needed)
local tests_time="$( \
printf "%010d" "$(( ${tests_endtime/%N/000000000}
printf "%010d" "$(( ${tests_endtime/%N/000000000}
- ${tests_starttime/%N/000000000} ))")" # in ns
tests="$tests_ran ${*:+$* }tests"
[[ -n "$DISCOVERONLY" ]] && echo "collected $tests." && _assert_reset && return
@@ -105,7 +105,7 @@ assert_end() {
assert() {
# assert <command> <expected stdout> [stdin]
(( tests_ran++ )) || :
[[ -z "$DISCOVERONLY" ]] || return
[[ -z "$DISCOVERONLY" ]] || return 0
expected=$(echo -ne "${2:-}")
result="$(eval 2>/dev/null $1 <<< ${3:-})" || true
if [[ "$result" == "$expected" ]]; then
@@ -115,13 +115,13 @@ assert() {
result="$(sed -e :a -e '$!N;s/\n/\\n/;ta' <<< "$result")"
[[ -z "$result" ]] && result="nothing" || result="\"$result\""
[[ -z "$2" ]] && expected="nothing" || expected="\"$2\""
_assert_fail "expected $expected${_indent}got $result" "$1" "$3"
_assert_fail "expected $expected${_indent}got $result" "$1" "${3:-}"
}
assert_raises() {
# assert_raises <command> <expected code> [stdin]
(( tests_ran++ )) || :
[[ -z "$DISCOVERONLY" ]] || return
[[ -z "$DISCOVERONLY" ]] || return 0
status=0
(eval $1 <<< ${3:-}) > /dev/null 2>&1 || status=$?
expected=${2:-0}
@@ -129,7 +129,12 @@ assert_raises() {
[[ -z "$DEBUG" ]] || echo -n .
return
fi
_assert_fail "program terminated with code $status instead of $expected" "$1" "$3"
_assert_fail "program terminated with code $status instead of $expected" "$1" "${3:-}"
}
assert_success() {
# assert_success <command>
assert_raises "$1" 0
}
# _assert_with_grep <grep modifiers> <command> <expected output...>

View File

@@ -1,5 +1,13 @@
#!/bin/bash
# Verify we are in a git repo. Create one if not
# FIXME: All the paths are hardcoded currently and will break if anything
# in this chain moves or gets executed elsewhere. Adjust all of these so
# pathing does not matter as much such as creating a TOP variable that
# does something like TOP=$(cd "$(dirname "$0")" || exit ; pwd -P)
# or maybe leverages Make to handle these as test targets
./tests/test-git/resetgit
. tests/assert.sh -v
src="./git-quick-stats"
@@ -42,14 +50,20 @@ 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
displays a list of commits per day
-m, --commits-by-month
displays a list of commits per month
-Y, --commits-by-year
displays a list of commits per year
-w, --commits-by-weekday
displays a list of commits per weekday
-W, --commits-by-author-by-weekday
displays a list of commits per weekday by author
-o, --commits-by-hour
displays a list of commits per hour
-A, --commits-by-author-by-hour
@@ -86,12 +100,19 @@ ADDITIONAL USAGE
assert_raises "$src fail" 1
assert_contains "$src --suggest-reviewers" "Suggested code reviewers (based on git history)"
assert_raises "$src --suggest-reviewers" 0
assert_success "$src --suggest-reviewers"
assert_contains "$src --detailed-git-stats" "Contribution stats"
assert_raises "$src --detailed-git-stats" 0
assert_success "$src --detailed-git-stats"
assert_contains "$src --commits-per-day" "Git commits per date"
assert_raises "$src --commits-per-day" 0
assert_success "$src --commits-per-day"
assert_startswith "$src --commits-by-year" "Git commits by year"
assert_success "$src --commits-by-year"
export LC_TIME=POSIX
assert_startswith "$src --commits-by-year" "Git commits by year"
assert_success "$src --commits-by-year"
assert_end

16
tests/test-git/resetgit Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/sh
# Initialises a new local Git repo for test purpose if one does not exist already
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
{
git init
git config user.name "$(printf %s 'Test Git,\nfor test purpose')"
git config user.email "TestGit\o/@example.org"
printf 'test-git\n========\n' > README.md
git add README.md
git commit -m 'added readme (o\w/o)' -m 'in markdown, no \r\n, only \n' -m 'a very "simple" readme'
testChars="$(printf 'tab [%b] form feed [%b] line feed [%b] carriage return [%b]' '\x09' '\x0C' '\x0A' '\x0D')"
git notes add -m 'Some notes' -m 'out of ascii: été au cœur' -m "$testChars"
git log
} >/dev/null 2>&1
fi