简体   繁体   English

Mercurial内置模板样式说明

[英]Mercurial built-in template style description

I am trying to tune the output of hg log by defining my own style. 我试图通过定义自己的样式来调整hg log的输出。 In fact, just adding information to the default style would be perfect. 实际上,仅将信息添加到默认样式将是完美的。 Is there a place where I can get the description of the default styles (default, compact, ...) to write my own? 在哪里可以得到默认样式的描述(默认,紧凑,...)以编写自己的样式?

From other comments elsewhere you can find out where the styles location is by: 从其他地方的其他评论中,您可以找到样式位置在哪里:

hg debuginstall --config ui.editor=cat

Or using a bug if you choose a directory under the template it complains and tells you where they are (probably should for non matching styles), well it does for 1.9.2: 或者,如果您在模板下选择一个目录会抱怨并告诉您它们在哪里(如果样式不匹配,则可能会出现错误),如果您在1.9.2版中做得很好,也可以使用bug:

hg in --style paper

If you want to colour the output you could use the color extension now. 如果要为输出着色,可以立即使用颜色扩展名。 add to .hgrc: 添加到.hgrc:

[extensions]
color=

If you know how to use the various keywords that Mercurial templating feature understands (see hg help templating for a very complete usage doc), then you can either: 如果您知道如何使用Mercurial 模板功能理解的各种关键字(请参阅hg help templating以获取非常完整的用法文档),则可以:

  • specify your choices by giving a template on the command line, eg, 通过在命令行上提供模板来指定您的选择,例如,

    $ hg tip --template "{rev} at {date|isodate}"\\n $ hg tip --template“ {rev} at {date | isodate}” \\ n
    882 at 2014-12-17 08:50 +0100 882在2014-12-17 08:50 +0100

  • or edit an ascii file with the same format and use it with the style option, eg, 或编辑具有相同格式的ascii文件,并将其与样式选项一起使用,例如,

    $ cat ~/mystyle.txt $猫〜/ mystyle.txt
    changeset = "{rev} at {date|isodate}\\n" changeset =“ {rev} at {date | isodate} \\ n”
    $ hg tip --style ~/mystyle.txt $ hg tip --style〜/ mystyle.txt
    882 at 2014-12-17 08:50 +0100 882在2014-12-17 08:50 +0100

After some research, I finally found the location of the default styles for hg log , located on my ubuntu 14.04 at 经过研究,我终于找到了hg log默认样式的位置,位于我的ubuntu 14.04上,

/usr/share/mercurial/templates/

You can find there the following files: 您可以在其中找到以下文件:

map-cmdline.bisect
map-cmdline.changelog
map-cmdline.compact
map-cmdline.default
map-cmdline.phases
map-cmdline.xml        

They do not contain any color scheme, but they are allowed me to build my 'patched' version of default. 它们不包含任何配色方案,但允许我构建默认的“修补”版本。

It's strange, but the default templates are hardcoded in mercurial code. 这很奇怪,但是默认模板是在商品代码中硬编码的。

The file map-cmdline.default is never read at runtime, but can be used to exactly replicate mercurial output (and thus to extend it). map-cmdline.default文件在运行时从不会读取,但可用于精确复制汞输出(从而进行扩展)。

Example of how to extend hg log output to include the git commit hash of a git repository cloned via hg-git . 如何扩展hg log输出以包括通过hg-git克隆的git存储库的git commit哈希的示例。

Look for the location of map-cmdline.default : 查找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)

Edit /etc/mercurial/hgrc , pasting a slightly modified version of 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...

Example output: 输出示例:

~/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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM