Skip to content

Commit 55c6d71

Browse files
committed
enhanced gitlog as gitlogp
1 parent ee5db1f commit 55c6d71

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

src/alias.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ alias gcm='git commit'
2828
__git_complete gco _git_checkout
2929
alias gco='git checkout'
3030
alias gl='gitlog'
31+
alias glp='gitlogp'
3132

3233
alias gsl='git stash list --date=local'
3334
alias gst='git status'

src/functions.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,80 @@ gitlog() {
9191
}
9292
' | column -ts '|'
9393
}
94+
95+
96+
gitlogp() {
97+
entries=$1
98+
branch="$2"
99+
[ -n "$entries" ] && entries="-${entries#-}"
100+
101+
fmt='%h|%p|%cd|%an|%(describe:tags)|%s'
102+
datearg="--date=format:%m-%d-%y %H:%M"
103+
104+
if [ -n "$branch" ]; then
105+
git log "$branch" --format="$fmt" "$datearg" $entries
106+
else
107+
git log --format="$fmt" "$datearg" $entries
108+
fi | awk -F'|' '
109+
{
110+
commit=$1
111+
parents=$2
112+
date=$3
113+
author=$4
114+
tag=$5
115+
subject=$6
116+
117+
order[NR]=commit
118+
parentsOf[commit]=parents
119+
dateOf[commit]=date
120+
authorOf[commit]=author
121+
tagOf[commit]=tag
122+
subjectOf[commit]=subject
123+
124+
n=split(parents, arr, " ")
125+
parentCount[commit]=n
126+
127+
for (i=1; i<=n; i++) {
128+
if (arr[i] != "") parentOf[commit]=parentOf[commit] " " arr[i]
129+
}
130+
131+
# mark the *second parent* of merges
132+
if (n > 1) {
133+
markBranch[arr[2]]=1
134+
}
135+
}
136+
END {
137+
# propagate [side] marks backwards
138+
changed=1
139+
while (changed) {
140+
changed=0
141+
for (c in parentOf) {
142+
split(parentOf[c], arr, " ")
143+
for (i=1;i<=length(arr);i++) {
144+
p=arr[i]
145+
if (p in markBranch && !(c in markBranch)) {
146+
markBranch[c]=1
147+
changed=1
148+
}
149+
}
150+
}
151+
}
152+
153+
for (i=1; i<=NR; i++) {
154+
c=order[i]
155+
156+
# decide marker
157+
if (parentCount[c] > 1) {
158+
flag="[merge]"
159+
} else if (c in markBranch) {
160+
flag="[side]"
161+
} else {
162+
flag=" "
163+
}
164+
165+
printf "%-8s %-7s %-20s %-14s %-15s %-25s %s\n", \
166+
c, flag, parentsOf[c], dateOf[c], authorOf[c], tagOf[c], subjectOf[c]
167+
}
168+
}
169+
'
170+
}

0 commit comments

Comments
 (0)