[英]Decoding git log complex pretty format
i'm trying to porting some git
-depending stuff to libgit2
for my Open Source project. 我正在尝试为我的开源项目向libgit2
移植一些与git
有关的东西。
One of the git
calls is very weird: git
调用之一很奇怪:
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
? H
之后的X
是什么意思? 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? 我在官方git站点上找不到X
说明符:/第二个问题libgit2
可以执行这种复杂的格式设置,还是我自己处理?
PS However, i'm pretty sure it cannot :) PS但是,我很确定它不能:)
The X
is not a format specifier. X
不是格式说明符。
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: --pretty=format:
或--pretty=tformat:
(大多数用户需要tformat
,但是此代码使用-z
,它在每次提交后添加一个NUL字符)同时包含%m
和%H
类的指令和文字简单抄写的文字 :
$ 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. 在这里, hello
和world
字符串只是通过复制而完成,而%x25
被解释了。 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
. 由于它表示“打印字符,十六进制代码为25”(即百分号%
,并且-n 3
告诉git log
在记录了3次提交后停止,所以我们得到了3个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. 文字X
之所以起作用,是因为%m
打印的字符不是X
, %H
和%P
打印的哈希不包含X
,而%n
打印的换行符-因此,读取此输出的内容可以确保每次提交均以标记字符, X
,提交哈希,另一个X
以及每个父哈希,每个哈希之间有一个空格,然后是换行符。
The %s%n%b
sequence is not entirely necessary (one could simply use %B
instead). %s%n%b
序列不是完全必要的(一个人可以简单地使用%B
代替)。 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.) (我对libgit2一无所知。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.