如何在Mercurial的“汞日志”上显示当前的有效修订?

sla*_*foo 5 version-control mercurial logging

我希望我的“ hg h”(hg日志别名的输出)显示历史记录/日志中当前正在运行的修订版本。

在我的.hgrc上,我有以下内容:

[alias]
h = log --template "{rev} {node|short} {date|shortdate} | [{author|user}] {desc|strip|firstline} :: {tags}\n"
Run Code Online (Sandbox Code Playgroud)

这是一个示例输出:

$ hg h
1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit ::
Run Code Online (Sandbox Code Playgroud)

但是,如果我更新到修订版0,输出仍然相同:

$ hg up 0
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

$ hg h
1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit ::
Run Code Online (Sandbox Code Playgroud)

所需的输出示例为:

$ hg h
1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit :: [working]
Run Code Online (Sandbox Code Playgroud)

注意:[working]不是标签,只是我的工作修订版,即我更新到的版本。

另一个示例可能是:

$ hg h
1 f130b4194c90 2011-07-21 | | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 |X| [slashfoo] initial commit ::
Run Code Online (Sandbox Code Playgroud)

我使用hgbook在“自定义Mercurial的输出”上的条目自定义了“ hg h”的输出http://hgbook.red-bean.com/read/customizing-the-output-of-mercurial.html

我想做的替代方法可能是:

  1. 使用graphlog扩展名,并hg h -G使用@表示当前工作版本
  2. 使用hg id要知道我是什么版本
  3. hg parents一些额外的信息知道我是什么版本

但是只有备选方案1向我显示了上下文,但是hg log -G和别名比我期望的输出要少“紧凑”。

这是替代方案#1的输出示例

$ hg h -G
o  1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
|
@  0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit ::
Run Code Online (Sandbox Code Playgroud)

这个问题类似于我如何才能找到我的工作修订,但我希望在上下文中以紧凑的方式(即不使用-G)

Obe*_*nne 1

在类似 bash 的环境中,以下 bash 别名的小怪物可以实现这一目的:

alias hgh='hg log -G --template "{rev} {node|short} {date|shortdate} | [{author|user}] {desc|strip|firstline} :: {tags}\n" | grep -v "^[|/\\ ]*$" | sed -e "s,^[o|/\\ +-]*,," -e "s,^@ *\(.*\),\1 [working]," | less'
Run Code Online (Sandbox Code Playgroud)

它使用-G选项 andgrepsed来去除除标记之外的所有图形内容,标记将被行末尾的标记@替换。[working]

诚然,这是一个有效但丑陋的解决方案。使用纯 Mercurial 命令和选项会好得多,但模板系统似乎无法提供您想要的东西。

作为旁注,您可能想看看我编写的指南针扩展- 不是您正在寻找的具体内容,但它也有助于查看存储库中当前的上下文。