用 Mercurial 替换关键字
我对具有关键字扩展扩展的 Mercurial 有一个问题:是否可以使用关键字扩展实际提交消息,以便它出现在源中以便快速参考源中的内容?
编辑:这似乎有效:
在 repo 的 hgrc 中
Log={desc}
,但它不堆叠,正如据称 CVS 对应物那样。
使用源代码,卢克:
跨越多行的扩展和增量扩展, 像 CVS 的 $Log$ 一样,不支持。关键字模板图“Log = {desc}”扩展到变更集描述的第一行。
I would have a question on Mercurial with keyword expansion extension: is it possible to expand actual commit message with a keyword, so that it appears in sources for quick reference what's in the sources?
Edit: this seems to work:
in repo's hgrc
Log={desc}
But it doesn't stack, as it CVS counterpart allegedly does.
Use the Source, Luke:
Expansions spanning more than one line and incremental expansions,
like CVS' $Log$, are not supported. A keyword template map "Log =
{desc}" expands to the first line of the changeset description.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关键字只能在单行上展开,因此您无法获得类似于 CVS 的行为,其中日志消息不断累积。启用扩展后,这会记录在
hg help keywords
中。可以使用
{desc}
模板关键字 访问提交消息Mercurial,因此您可以在所有
.c
文件中添加$Log$
扩展行。请注意,关键字扩展以基于每个文件的操作方式提供了类似于 CVS 的世界视图。 Mercurial 通常在存储库范围内工作。如果您
这样做,那么
foo.c
最后一次更改是在修订版 10 中,这是正确的,但说修订版 11 仅包含bar.c
是错误的。foo.c
文件也是修订版 11 的一部分 — 对bar.c
的更改完全有可能取决于之前对foo.c< 的更改/code> 因此修订版 11 中的快照捕获了
foo.c
和bar.c
的状态。关键字扩展在扩展关键字时以每个文件为基础工作:它将写入
$Log:已修复错误123 $
到foo.c
和$Log:每当您更新到变更集 2e85d7f2f93e 时,修复
。bar.c
中的错误 234 $如果您想了解最后一次触摸每个文件的原因和时间,那么这将满足您的要求。如果您想了解存储库的全局状态 - 例如将其用作版本字符串! ——那么这是错误的。问题是,您的
version.h
文件在您开发时将长期保持不变,因此该文件中的关键字也将保持不变。在这种情况下,您实际上应该将
hg id
作为Makefile
的一部分运行。您可以使用类似以下内容使其更加奇特:它将输出类似
2.1+117-eed1e5bba9a8
的字符串。这意味着您当前的版本 (eed1e5bba9a8) 在最后一个标签 (2.1) 之后有 117 次提交。这使用户可以轻松比较从同一中央存储库生成的构建,并且如果需要,您仍然可以唯一地重现构建。Keywords can only expand on a single line, so you cannot get CVS-like behavior where the log messages keep accumulating. This is documented in
hg help keyword
after enabling the extension.The commit messages are accessible with the
{desc}
template keyword in Mercurial, so you can addto have
$Log$
expanded line this in all.c
files.Note that the keyword extension gives a CVS-like view of the world in the way it operates on a per-file basis. Mercurial normally works on a repository-wide basis. If you do
then it's correct that
foo.c
was last changed in revision 10, but it's wrong to say that revision 11 only containbar.c
. Thefoo.c
file is also part of revision 11 — it is entirely plausible that the change tobar.c
depends on the previous change tofoo.c
and so the snapshot in revision 11 captures the state of bothfoo.c
andbar.c
.The keyword extension works on a per-file basis when it expands keywords: it will write
$Log: Fixed bug 123 $
intofoo.c
and$Log: Fixed bug 234 $
intobar.c
whenever you update to changeset 2e85d7f2f93e.If you want to see why and when each file was last touched, then this will do what you want. If you want to know the global state of your repository — for example to use it as a version string! — then this is wrong. The problem is that your
version.h
file will be unchanged for long periods when you develop, and so the keywords in that file will remain unchanged too.In that case you should really just run
hg id
as part of yourMakefile
. You can make it more fancy with something like:which will output a string like
2.1+117-eed1e5bba9a8
. This means that your current version (eed1e5bba9a8), is 117 commits after the last tag (2.1). That makes it easy for users to compare builds made from the same central repository and you can still uniquely reproduce a build if you need to.