Templates Mercurial模板:标记和书签的分隔符

Templates Mercurial模板:标记和书签的分隔符,templates,mercurial,Templates,Mercurial,只有当我有标签或书签时,我才能将空格字符作为分隔符吗 例如: hg log --template "{rev} {author} {tags} {bookmarks} {desc|firstline}\n" Output: 3: Author1 TIP BKMRK_NAME Another commit 2: Author1 Third commit 1: Author1 TAG1 Second commit 0: Author1 Initial commit 没有标记或书签的变更

只有当我有标签或书签时,我才能将空格字符作为分隔符吗

例如:

hg log --template "{rev} {author} {tags} {bookmarks} {desc|firstline}\n"

Output:
3: Author1 TIP BKMRK_NAME Another commit
2: Author1   Third commit
1: Author1 TAG1  Second commit
0: Author1   Initial commit
没有标记或书签的变更集打印空格字符。我想抑制这些额外的空格:

3: Author1 TAG_NAME BKMRK_NAME Another commit
2: Author1 Third commit
1: Author1 TAG1 Second commit
0: Author1 Initial commit

我不太了解Mercurial中的模板设置,但是您可以使用
sed

hg log --template "{rev} {author} {tags} {bookmarks} {desc|firstline}\n" | sed "s/  */ /g"

可以创建一种新样式,用于定义集合的开始(即书签)、集合中的元素本身以及集合的最后一个元素的外观

将以下样式定义保存在一个名为“my_style”的文件中:

然后,您可以使用刚刚创建的样式调用hg日志:

> hg log --style /path/to/my_style
6 james [bar, foo, master] b 3
5 james b 2
4 james a 3
这只会在有书签的情况下插入空格和括号(注意{author}和{bookmarks}之间没有空格)

可以找到一些不错的cli模板作为参考。

对于最近的Mercurial(2.5之后),您可以使用
if
模板表达式:

hg log --template '{rev} {author}{if(tags, " {tags}")}{if(bookmarks," {bookmarks}")} {desc|firstline}\n'

不幸的是,这不是我的解决方案,因为我用这样的模板制作了一个样式。我需要在Mercurial中这样做,因为它是“hg log-l 10”、“hg heads”等命令的默认样式。。。同时删除所有的双空格会弄乱glog的图形。是的,就是这样。我想我以前试过类似的东西,但我只包括了“start_bookmarks=…”一行。单靠这条线是不行的。需要“bookmark=…”行。非常感谢。
hg log --template '{rev} {author}{if(tags, " {tags}")}{if(bookmarks," {bookmarks}")} {desc|firstline}\n'