【问题标题】:Mercurial built-in template style descriptionMercurial 内置模板样式说明
【发布时间】:2014-12-19 13:16:06
【问题描述】:

我正在尝试通过定义自己的风格来调整hg log 的输出。事实上,只需在默认样式中添加信息就可以了。有没有地方可以让我自己编写默认样式(default、compact、...)的描述?

【问题讨论】:

  • Here 和 here 应该非常有用,尽管我没有看到默认的明确声明。

标签: mercurial hgrc


【解决方案1】:

经过一番研究,我终于找到了hg log默认样式的位置,位于我的ubuntu 14.04 at

/usr/share/mercurial/templates/

您可以在那里找到以下文件:

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

它们不包含任何配色方案,但允许我构建我的“修补”版本的默认值。

【讨论】:

    【解决方案2】:

    从其他地方的其他 cmets,您可以通过以下方式找到样式位置:

    hg debuginstall --config ui.editor=cat
    

    如果您在模板下选择一个目录,它会抱怨并告诉您它们在哪里(对于不匹配的样式可能应该),或者使用错误,它适用于 1.9.2:

    hg in --style paper
    

    如果您想为输出着色,您现在可以使用颜色扩展。 添加到.hgrc:

    [extensions]
    color=
    

    【讨论】:

      【解决方案3】:

      如果您知道如何使用 Mercurial 模板化 功能可以理解的各种关键字(请参阅 hg help templating 以获得非常完整的使用文档),那么您可以:

      • 通过在命令行上提供模板来指定您的选择,例如,

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

      • 或编辑一个相同格式的ascii文件,并与样式选项一起使用,例如,

        $ cat ~/mystyle.txt
        变更集 =“{rev} 在 {date|isodate}\n”
        $ hg 提示 --style ~/mystyle.txt
        882 2014-12-17 08:50 +0100

      【讨论】:

      • 感谢您的文档,我会阅读它并尝试模仿默认模板,这样我就可以添加自己的风格。但我仍然很想知道这种内置样式的模板描述是否在某处可用。
      【解决方案4】:

      这很奇怪,但默认模板是用 mercurial 代码硬编码的。

      文件map-cmdline.default 在运行时永远不会被读取,但可用于精确复制 mercurial 输出(并因此对其进行扩展)。

      如何扩展 hg log 输出以包含通过 hg-git 克隆的 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
      

      【讨论】:

        猜你喜欢
        • 2012-11-30
        • 1970-01-01
        • 2012-07-31
        • 2021-10-30
        • 2019-09-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多