Bazaar:提交时自动修改文件并提交修改
我希望集市在提交时将修订号写入已提交分支中的文件,以便此修改包含在提交中。
我查看了钩子,但 pre_commit 钩子仅在创建变更集后运行,因此它执行的修改不会提交。
我发现了一个相关问题: Bazaar:通过钩子提交之前修改文件内容? 但是,建议的 bzr-keywords 解决方案也不起作用,因为其写入转换未应用于提交:
``bzr commit`` 不会在之后隐式应用写入转换器 提交文件。如果这对于给定的插件有意义,则提供 内容过滤器,插件通常可以通过使用 “start_commit” 或 “post_commit” 钩子。
这让我回到了 pre_commit 挂钩问题。
我这样做的原因是:我的软件在编译时从版本文件中读取其版本。版本号由主号、分支号和修订号组成(如5.3.78)。我希望 bazaar 在提交时自动将实际版本写入版本文件。
I would like bazaar to write revision number on commit to a file in the committed branch so that this modification is included in the commit.
I looked at hooks but the pre_commit hook is only run after the changeset is created, thus the modification performed by it is not committed.
I found a related question:
Bazaar: Modify file content before commit via hook?
, however, the proposed bzr-keywords solution does not work either as its write conversion is not applied on commit:
``bzr commit`` does not implicitly apply write converters after
comitting files. If this makes sense for a given plugin providing
a content filter, the plugin can usually achieve this effect by using a
``start_commit`` or ``post_commit`` hook.
which gets me back to the pre_commit hook problem.
My reason for doing this: my software reads its version from a version file on compilation. The version is composed of main number, branch number and revision number (eg 5.3.78). I want bazaar to write the actual version to the version file automatically on commit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用
start_commit
挂钩,因为这是在提交之前更改文件的唯一方法:http://doc.bazaar.canonical.com/bzr.2.3/en/user-reference/hooks-help.html#start-commitYou should use
start_commit
hook because this is the only way to change file before commit: http://doc.bazaar.canonical.com/bzr.2.3/en/user-reference/hooks-help.html#start-commit我有一个挂接到 start_commit 的插件脚本,名为 start_commit.py。每次提交发生时,这都会从项目树的基础调用名为 .startcommit 的 shell 脚本。我将其与账本数据一起使用,在每次提交之前转储所有余额以进行验证。
我没有写这个插件,我无法通过快速搜索找到它的来源,所以这里是源代码(~/.bazaar/plugins/start_commit.py):
如果有人知道,我会很高兴将此片段归功于原作者。否则我希望它有帮助!
I have a plugin script that hooks into start_commit called start_commit.py. This calls a shell script named .startcommit from the base of the project tree each time a commit occurs. I use this with Ledger data to dump all my balances for verification before each commit.
I didn't write this plugin, and I can't locate where I got it from with a quick search, so here's the source (~/.bazaar/plugins/start_commit.py):
If someone knows, I'd be happy to credit the original author for this snippet. Otherwise I hope it helps!