在 Mercurial 中使用钩子与包装命令

发布于 2024-09-26 01:09:25 字数 968 浏览 5 评论 0原文

使用钩子与使用包装特定任务命令的扩展的相对优点和缺点是什么?

换句话说,决定使用钩子还是包装命令的标准是什么?

另请列出一种方法是唯一选择的情况。我能想到的一种情况是为现有命令添加新参数。您还可以更改/删除参数,例如我将 log 默认为 log -ggraphlog 在存在一些“不兼容”参数时中止(请参阅graphlog.check_unsupported_flags),因此我添加了一个log包装器来删除这些情况下的-g,因为强迫堕胎是反人类罪。

感觉钩子更加干净利落。 Python 挂钩在 hg 进程中运行,因此不存在性能问题。虽然使用extensions.wrapcommand创建命令包装器很容易,但创建/禁用钩子以及调整它们的应用顺序却很简单(它们首先应该是独立的) )。

这是 hgrc doc 的引用,建议使用标准钩子而不是前/后命令钩子,但它也适用于包装器上的钩子:

...像“commit”这样的钩子将在生成提交(例如标记)的所有上下文中调用,而不仅仅是提交命令。

另外,我猜钩子不受 GPL 约束(或者是?),而 扩展名是

(我希望超过 1.5k 的用户可以创建一个 mercurialhooks 标签。Git 粉丝们已经用 githooks 击败了我们。)

What are the relative pros and cons for using hooks vs. using an extension that wraps a command for a particular task?

In other words, what are the criteria for deciding whether to use hooks or wrap a command?

Please also list the cases where one approach is the only option. One case I can think of is to add new arguments for existing commands. You could also change/remove arguments, for example I default log to log -g but graphlog aborts in the presence of some "incompatible" arguments (see graphlog.check_unsupported_flags), so I added a log wrapper to remove -g in those cases, because forced abortion is a crime against humanity.

It feels like hooks are more clean-cut. Python hooks run in the hg process so there's no performance issue. And while it's easy to use extensions.wrapcommand to create command wrappers, it's trivial to create/disable hooks, and to adjust the order in which they are applied (they should be self-contained in the first place).

And here's a quote from hgrc doc that recommends standard hooks over pre/post command hooks, but it also applies to hooks over wrapper:

... hooks like "commit" will be called in all contexts that generate a commit (e.g. tag) and not just the commit command.

Also I guess that hooks are not subjected to GPL (or are they?), whereas command wrappers in extensions are.

(I hope a 1.5k+ user can create a mercurialhooks tag. Git fan boys have beaten us with githooks.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春花秋月 2024-10-03 01:09:25

我不能谈论许可问题,但钩子和扩展之间最大的区别是钩子可以用任何语言编写,而扩展始终是Python。

如果用 python 编写,那么钩子和扩展之间没有什么区别:

  • 两者都可以深入研究 Mercurial 内部结构,
  • 都需要用户修改他们的 .hgrc 以使它们
  • 都可以包装/拦截命令

我认为你的日志除了作为扩展完成之外,还可以使用 pre-log 挂钩来完成命令参数修改。

TL;DR:如果您使用 python 编写,则几乎没有什么区别,如果您不使用 hooks,那么 hooks 是您唯一的选择。

I can't speak to licensing issues, but the biggest difference between a hook and an extension is that a hook can be written in any language whereas extensions are always python.

If one's writing in python then there's little difference between a hook and an extension:

  • either can delve deeply into mercurial internals
  • both require users modify their .hgrc to enable them
  • both can wrap/intercept commands

I think your log command argument modification could be done with a pre-log hook in addition to being done as an extension.

TL;DR: If you're writing in python there's little difference, and if you're not hooks are your only option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文