4

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.)

4

1 回答 1

4

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

如果一个人用 python 编写,那么钩子和扩展之间几乎没有区别:

  • 两者都可以深入研究多变的内部结构
  • 两者都要求用户修改它们.hgrc以启用它们
  • 两者都可以包装/拦截命令

pre-log我认为除了作为扩展完成之外,您的日志命令参数修改还可以通过钩子完成。

TL;DR:如果你用 python 编写,那差别不大,如果你不是钩子,那是你唯一的选择。

于 2010-10-04T19:03:24.117 回答