我试图hg log
通过定义自己的风格来调整输出。事实上,只需在默认样式中添加信息就可以了。有没有地方可以让我自己编写默认样式(默认,紧凑,...)的描述?
4 回答
经过一番研究,我终于找到了默认样式的位置hg log
,位于我的 ubuntu 14.04 上
/usr/share/mercurial/templates/
您可以在那里找到以下文件:
map-cmdline.bisect
map-cmdline.changelog
map-cmdline.compact
map-cmdline.default
map-cmdline.phases
map-cmdline.xml
它们不包含任何配色方案,但它们允许我构建我的“修补”版本的默认值。
从其他地方的其他评论中,您可以通过以下方式找到样式位置:
hg debuginstall --config ui.editor=cat
或者如果您在它抱怨的模板下选择一个目录并告诉您它们在哪里(可能应该用于不匹配的样式),则使用错误,它适用于 1.9.2:
hg in --style paper
如果要为输出着色,现在可以使用颜色扩展。添加到.hgrc:
[extensions]
color=
如果您知道如何使用 Mercurial模板功能可以理解的各种关键字(请参阅hg help templating
非常完整的使用文档),那么您可以:
通过在命令行上提供模板来指定您的选择,例如,
$ hg tip --template "{rev} at {date|isodate}"\n
882 at 2014-12-17 08:50 +0100或编辑具有相同格式的 ascii 文件并将其与样式选项一起使用,例如,
$ cat ~/mystyle.txt
changeset = "{rev} at {date|isodate}\n"
$ hg tip --style ~/mystyle.txt
882 at 2014-12-17 08:50 +0100
这很奇怪,但默认模板是用 mercurial 代码硬编码的。
该文件map-cmdline.default
永远不会在运行时读取,但可用于精确复制 mercurial 输出(并因此扩展它)。
如何扩展输出以包含通过hg-githg log
克隆的 git 存储库的 git 提交哈希的示例。
寻找位置map-cmdline.default
:
$ hg debuginstall --config ui.editor=cat | grep "default template"
checking default template (/usr/lib/python2.7/dist-packages/mercurial/templates/map-cmdline.default)
编辑/etc/mercurial/hgrc
,粘贴稍作修改的版本map-cmdline.default
:
...first part of your hgrc...
[templates]
# support "git-commit" line in hg log
changeset_git = '{cset}{cset_git}{branches}{bookmarks}{tags}{parents}{user}{ldate}{ltroubles}{lobsfate}{summary}\n'
cset_git = '{if(gitnode, "git-commit: {label("status.unknown", gitnode|short)}\n")}'
...the rest of 'templates' section of map-cmdline.default...
[templatealias]
...the whole 'templatealias' section of map-cmdline.default...
示例输出:
~/git$ hg log --graph
@ changeset: 54881:d420062ce3d6
|\ git-commit: 6326d2e53311 <-- new line, only appears in git clones
| | tag: default/pu
| | tag: tip
| | parent: 54879:31a4c8ccc461
| | parent: 54880:691b9814f119
| | user: Junio C Hamano <gitster@pobox.com>
| | date: Sun Mar 25 10:52:08 2018 -0700
| | summary: Merge branch 'jh/partial-clone' into pu