[BUG] add_again() off-by-one error in custom format
- From
- Michael Giuffrida <michaelpg@chromium.org>
- Date
- Jun 12, 2017, 03:13 UTC
- Message-ID
- <CACi5S_1j46SbP7cQMdUnULmgGD7xBkSUrS2PKbzq8ZydybHE=w@mail.gmail.com>
In a custom pretty format, using the '+' or ' ' combinators to prefix a non-empty expansion with whitespace will erroneously truncate subsequent expansions of the same type.
Normally '%+X' inserts a newline before <X>, IFF the expansion of X is non-empty:
$ git log -n 1 --pretty='format:newline:%+an'
newline:
MyNameFor the abbreviated commit hash placeholder ('h'), pretty.c uses add_again() to cache the result of the expansion, and then uses that result in future expansions. This causes problems when the expansion includes whitespace:
$ git log -n 1 --pretty='format:newline:%+h%nno_newline:%h'
newline:
a0b1c2d
no_newline:
a0b1c2The second expansion of the hash added an unwanted newline and removed the final character. It seemingly used the cached expansion *starting from the inserted newline*.
The expected output is:
$ git log -n 1 --pretty='format:newline:%+h%nno_newline:%h'
newline:
a0b1c2d
no_newline:a0b1c2d/CC René from commit b9c62321 and Junio from 9fa708d