Skip to content

Commit

Permalink
Support '}' characters in commit messages
Browse files Browse the repository at this point in the history
.githelpers:pretty_git_log() used a close-curly-brace '}'
as a column separator, however this breaks when the commit
message contains that character.

Change it to use a rare control character to avoid this problem.
  • Loading branch information
nmagedman committed Feb 12, 2013
1 parent b6a78e5 commit b7e4a41
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions .githelpers
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
# 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.

HASH="%C(yellow)%h%Creset"
RELATIVE_TIME="%Cgreen(%ar)%Creset"
AUTHOR="%C(bold blue)<%an>%Creset"
REFS="%C(red)%d%Creset"
SUBJECT="%s"

FORMAT="$HASH}$RELATIVE_TIME}$AUTHOR}$REFS $SUBJECT"
colsep=$'\c_' # i.e. ^_ (ASCII Unit Separator)
# colsep can be any single char that will never appear in the
# commit subject or any other field.

FORMAT="$HASH$colsep$RELATIVE_TIME$colsep$AUTHOR$colsep$REFS $SUBJECT"

show_git_head() {
pretty_git_log -1
Expand All @@ -32,8 +33,8 @@ pretty_git_log() {
sed -Ee 's/(^[^<]*) ago\)/\1)/' |
# Replace (2 years, 5 months) with (2 years)
sed -Ee 's/(^[^<]*), [[:digit:]]+ .*months?\)/\1)/' |
# Line columns up based on } delimiter
column -s '}' -t |
# Line columns up based on $colsep delimiter
column -s "$colsep" -t |
# Page only if we need to
less -FXRS
}
Expand Down

0 comments on commit b7e4a41

Please sign in to comment.