mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
The output of `git log` is not exactly in chronological order. The
default sort option (--date-order) is described in the man page as
follows:
Show no parents before all of its children are shown, but otherwise
show commits in the commit timestamp order.
The `uniq` program will only remove duplicate lines if they follow each
other. In order for this to work correctly, we need to ensure that the
list of dates is exactly in chronological order. There doesn't seem to
be a `git log` option to achieve this, but we can use the `sort`
program. I used reverse sort (`sort -r`) since the output will be roughly
reverse-sorted already.
It's also worth noting that the default --date-order option sorts by
commit date, but git-summary uses *author* date (%ai). Passing
--author-date-order doesn't fix this issue, though, so I didn't change
that.
At the time of writing, this change reduces the number of 'active days'
for git-extras.git from 367 to 331.
89 lines
1.3 KiB
Bash
Executable file
89 lines
1.3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
SUBDIRECTORY_OK=Yes
|
|
source "$(git --exec-path)/git-sh-setup"
|
|
cd_to_toplevel
|
|
|
|
commit=""
|
|
test $# -ne 0 && commit=$@
|
|
project=${PWD##*/}
|
|
|
|
#
|
|
# get date for the given <commit>
|
|
#
|
|
|
|
date() {
|
|
git log --pretty='format: %ai' $1 | cut -d ' ' -f 2
|
|
}
|
|
|
|
#
|
|
# get active days for the given <commit>
|
|
#
|
|
|
|
active_days() {
|
|
date $1 | sort -r | uniq | awk '
|
|
{ sum += 1 }
|
|
END { print sum }
|
|
'
|
|
}
|
|
|
|
#
|
|
# get the commit total
|
|
#
|
|
|
|
commit_count() {
|
|
git log --oneline $commit | wc -l | tr -d ' '
|
|
}
|
|
|
|
#
|
|
# total file count
|
|
#
|
|
|
|
file_count() {
|
|
git ls-files | wc -l | tr -d ' '
|
|
}
|
|
|
|
#
|
|
# list authors
|
|
#
|
|
|
|
authors() {
|
|
git shortlog -n -s $commit | awk '
|
|
{ args[NR] = $0; sum += $0 }
|
|
END {
|
|
for (i = 1; i <= NR; ++i) {
|
|
printf "%s,%2.1f%%\n", args[i], 100 * args[i] / sum
|
|
}
|
|
}
|
|
' | column -t -s,
|
|
}
|
|
|
|
#
|
|
# fetch repository age from oldest commit
|
|
#
|
|
|
|
repository_age() {
|
|
git log --reverse --pretty=oneline --format="%ar" | head -n 1 | sed 's/ago//'
|
|
}
|
|
|
|
# summary
|
|
|
|
if test "$1" = "--line"; then
|
|
git line-summary
|
|
echo
|
|
else
|
|
|
|
echo
|
|
echo " project : $project"
|
|
echo " repo age :" $(repository_age)
|
|
echo " active :" $(active_days) days
|
|
echo " commits :" $(commit_count)
|
|
if test "$commit" = ""; then
|
|
echo " files :" $(file_count)
|
|
fi
|
|
echo " authors : "
|
|
authors
|
|
echo
|
|
|
|
fi
|