eraxillan eraxillan - 1 month ago 7x
Git Question

Decoding git log complex pretty format

i'm trying to porting some

-depending stuff to
for my Open Source project.

One of the
calls is very weird:

git log --topo-order --no-color --parents --boundary -z --pretty=format:%m%HX%PX%n%cn<%ce>%n%an<%ae>%n%at%n%s%n%b HEAD --all

First of all, i'm interesting in format string.
What means the
? I was unable to find
specifier on official git site :/
And the second question - can
do this complex formatting, or i should process it myself?

P.S. However, i'm pretty sure it cannot :)


The X is not a format specifier.

The argument to --pretty=format: or --pretty=tformat: (most users need tformat, but this code is using -z which adds a NUL character after each commit) contains both directives like %m and %H, and literal text that is simply transcribed:

$ git log -n 3 --pretty=tformat:hello%x25world

Here, the hello and world strings were simply copied through, while %x25 was interpreted. Since it means "print character with hex code 25" which is the percent sign %, and -n 3 told git log to stop after logging three commits, we got three copies of hello%world.

The literal X works because %m prints one character that is not X, %H and %P print hashes that do not contain X, and %n prints a newline—so whatever is reading this output can be sure that each commit begins with the marker character, an X, the commit hash, another X, and each parent hash with a space between each, then a newline.

The %s%n%b sequence is not entirely necessary (one could simply use %B instead). I'm not sure off-hand, though, whether this adjusts the way that "unusually formatted" commits—those that are not a single subject line, followed by a newline, followed by a commit body—come out. It probably does.

(I know nothing of libgit2.)