Skip to content

Commit ee5db1f

Browse files
committed
include merge indicator in gitlog
Refactors `gitlog` to improve formatting and readability. It normalizes entry count, uses a more concise format string, and leverages `awk` to trim whitespace and correctly handle commit parents, which are then passed to `column` for final formatting.
1 parent e1eedea commit ee5db1f

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/functions.sh

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,27 @@ gref() {
6767
gitlog() {
6868
entries=$1
6969
branch="$2"
70-
if [ -n "$entries" ]; then
71-
entries="-${entries#-}"
72-
if [ -n "$branch" ]; then
73-
git log "$branch" --format="%h %cd | %an | %(describe:tags) | %s" --date=format:"%m-%d-%y %H:%M" $entries | column -ts '|' -T 4
74-
else
75-
git log --format="%h %cd | %an | %(describe:tags) | %s" --date=format:"%m-%d-%y %H:%M" $entries | column -ts '|' -T 4
76-
fi
70+
71+
# normalize entry count like: gitlog 25 or gitlog -25
72+
[ -n "$entries" ] && entries="-${entries#-}"
73+
74+
fmt='%h | %p | %cd | %an | %(describe:tags) | %s'
75+
datearg="--date=format:%m-%d-%y %H:%M"
76+
77+
if [ -n "$branch" ]; then
78+
git log "$branch" --format="$fmt" "$datearg" $entries
7779
else
78-
if [ -n "$branch" ]; then
79-
git log "$branch" --format="%h %cd | %an | %(describe:tags) | %s" --date=format:"%m-%d-%y %H:%M" | column -ts '|' -T 4
80-
else
81-
git log --format="%h %cd | %an | %(describe:tags) | %s" --date=format:"%m-%d-%y %H:%M" | column -ts '|' -T 4
82-
fi
83-
fi
80+
git log --format="$fmt" "$datearg" $entries
81+
fi | awk -F'|' '
82+
{
83+
# trim whitespace
84+
for (i=1;i<=NF;i++) gsub(/^[ \t]+|[ \t]+$/, "", $i)
85+
86+
commit=$1
87+
parents=$2 # all parent hashes (blank if none)
88+
89+
printf "%s | %s | %s | %s | %s | %s\n", \
90+
commit, parents, $3, $4, $5, $6
91+
}
92+
' | column -ts '|'
8493
}

0 commit comments

Comments
 (0)