Mercurial 关键字扩展可在每次提交时扩展
我需要使用 hg 关键字扩展将构建日期和修订版本嵌入到源文件中。撇开“你真的不想这样做”的争论不谈,我该怎么做呢?
这是我的源文件 (lib/foo/version.rb
) 的样子(恰好是 Ruby,但这只是从我没有“编译”步骤的角度来看相关的)在我的构建中,我可以执行 -DREVISION="$(hg id)" in):
module Foo
VERSION = {
:date => "$Date$",
:changeset => "$Revision$"
}
end
问题是 $Revision$ 和 $Date$ 使用该文件的变更集和提交日期进行扩展 ,而我需要的是整个存储库的提示变更集和提交日期。
我没有看到可以在 hg help templates
中使用的明显模板,关键字扩展也没有提及任何具有全局范围的内容。我想做的事情可能吗?
I need to use the hg keyword extension to embed the build date and revision into a source file. Leaving aside the whole "you really don't want to be doing that" argument, how can I do this?
Here's what my source file (lib/foo/version.rb
) looks like (which happens to be Ruby, but that's only relevant from the point of view that I don't have a "compile" step in my build which I could do a -DREVISION="$(hg id)" in):
module Foo
VERSION = {
:date => "$Date$",
:changeset => "$Revision$"
}
end
The problem is that $Revision$ and $Date$ are expanded with the changeset and commit date of that file, whereas what I need is the tip changeset and commit date of the whole repository.
I don't see an obvious template I can use in hg help templates
, nor does the keyword extension mention anything with global scope. Is what I'm trying to do possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以安装更新文件的
post-commit
挂钩:然后您应该将版本文件添加到
.hgignore
文件中 - 每次提交后它都会更改,因此总是很脏。您还可以添加一个编码过滤器来清理版本文件:此脚本将使 Mercurial 将文件视为干净的 - 无论它实际包含什么日期和变更集,Mercurial 都会将其视为包含未扩展的
$Date$
和$Version$
关键字:You can install a
post-commit
hook that updates the file:You should then probably add the version file to the
.hgignore
file -- it will change after every commit and thus always be dirty. You could also add a encode filter that will clean up the version file:This script will make Mercurial see the file as clean -- no matter what date and changeset has it really contains, Mercurial will see it as containing un-expanded
$Date$
and$Version$
keywords:如果您从结帐运行代码,则可以直接调用 hg 并缓存该值。类似于:
如果您没有在安装了 Mercurial 的系统上从结帐内部运行代码,那么您的部署脚本可以轻松获取/使用该值 - 也许可以通过使用
hg archive
来获取要发送的 tarball,然后自动包含.hg_archive.txt
。我向您保证,无论您的设置是什么,都有比关键字扩展更漂亮的方法。
If you're running your code from a checkout you can invoke hg directly and cache the value. Something like:
and if you're not running the code from inside a checkout on a system with Mercurial installed, then your deploy script can easily get/use the value -- perhaps by using
hg archive
to get the tarball to send which then automatically includes a.hg_archive.txt
.I guarantee you there's a prettier way to do this than the keywords extension no matter what your setup is.