Fix git log by pulling grb latest version

This commit is contained in:
Max Bucknell 2020-03-04 15:20:51 +11:00
parent 33037b4f8f
commit 7f7c881193

View file

@ -1,45 +1,49 @@
#!/bin/bash
# Log output:
#
# * 51c333e (12 days) <Gary Bernhardt> add vim-eunuch
#
# The time massaging regexes start with ^[^<]* because that ensures that they
# only operate before the first "<". That "<" will be the beginning of the
# author name, ensuring that we don't destroy anything in the commit message
# that looks like time.
#
# The log format uses } characters between each field, and `column` is later
# used to split on them. A } in the commit subject or any other field will
# break this.
LOG_HASH="%C(always,yellow)%h%C(always,reset)"
LOG_RELATIVE_TIME="%C(always,green)(%ar)%C(always,reset)"
LOG_AUTHOR="%C(always,blue)<%an>%C(always,reset)"
LOG_SUBJECT="%s"
LOG_REFS="%C(always,red)%d%C(always,reset)"
HASH="%C(yellow)%h%Creset"
RELATIVE_TIME="%Cgreen(%ar)%Creset"
AUTHOR="%C(blue)<%an>%Creset"
REFS="%C(red)%d%Creset"
SUBJECT="%s"
LOG_FORMAT="$LOG_HASH}$LOG_RELATIVE_TIME}$LOG_AUTHOR}$LOG_REFS $LOG_SUBJECT"
FORMAT="$HASH}$RELATIVE_TIME}$AUTHOR}$REFS $SUBJECT"
BRANCH_PREFIX="%(HEAD)"
BRANCH_REF="%(color:red)%(color:bold)%(refname:short)%(color:reset)"
BRANCH_HASH="%(color:yellow)%(objectname:short)%(color:reset)"
BRANCH_DATE="%(color:green)(%(committerdate:relative))%(color:reset)"
BRANCH_AUTHOR="%(color:blue)%(color:bold)<%(authorname)>%(color:reset)"
BRANCH_CONTENTS="%(contents:subject)"
ANSI_BLACK='\033[30m'
ANSI_RED='\033[31m'
ANSI_GREEN='\033[32m'
ANSI_YELLOW='\033[33m'
ANSI_BLUE='\033[34m'
ANSI_MAGENTA='\033[35m'
ANSI_CYAN='\033[36m'
ANSI_WHITE='\033[37m'
ANSI_RESET='\033[0m'
BRANCH_FORMAT="$BRANCH_PREFIX}$BRANCH_REF}$BRANCH_HASH}$BRANCH_DATE}$BRANCH_AUTHOR}$BRANCH_CONTENTS"
git log --color=always --graph --pretty="tformat:${FORMAT}" $* |
show_git_head() {
pretty_git_log -1
git show -p --pretty="tformat:"
}
pretty_git_log() {
git log --graph --pretty="tformat:${LOG_FORMAT}" --no-show-signature $* | pretty_git_format | git_page_maybe
}
pretty_git_branch() {
git branch -v --color=always --format=${BRANCH_FORMAT} $* | pretty_git_format
}
pretty_git_branch_sorted() {
git branch -v --color=always --format=${BRANCH_FORMAT} --sort=-committerdate $* | pretty_git_format
}
pretty_git_format() {
# Replace (2 years ago) with (2 years)
sed -Ee 's/(^[^<]*) ago\)/\1)/' |
# Replace (2 years, 5 months) with (2 years)
sed -Ee 's/(^[^<]*), [[:digit:]]+ .*months?\)/\1)/' |
# Color merge commits specially
sed -Ee "s/(Merge (branch|remote-tracking branch|pull request) .*$)/$(printf $ANSI_RED)\1$(printf $ANSI_RESET)/" |
# Line columns up based on } delimiter
column -s '}' -t |
column -s '}' -t
}
git_page_maybe() {
# Page only if we're asked to.
if [ -n "$GIT_NO_PAGER" ]; then
cat
@ -47,4 +51,6 @@ git log --color=always --graph --pretty="tformat:${FORMAT}" $* |
# Page only if needed.
less --quit-if-one-screen --no-init --RAW-CONTROL-CHARS --chop-long-lines
fi
}
pretty_git_log