i'm trying to porting some git
-depending stuff to libgit2
for my Open Source project.
One of the git
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 X
after H
? I was unable to find X
specifier on official git site :/ And the second question - can libgit2
do this complex formatting, or i should process it myself?
PS 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
hello%world
hello%world
hello%world
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.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.