Mercurial 中的版本控制扩展配置

发布于 2024-07-20 16:12:04 字数 393 浏览 4 评论 0原文

通常,我会通过将以下内容添加到 .hg/hgrc 来启用扩展:

[extensions]
hgext.win32text=
[encode]
** = cleverencode:
[decode]
** = cleverdecode:

但是,我希望此配置进行版本控制,即存储库的一部分,以便其他任何人(同事,构建机器)克隆存储库。 请注意,克隆存储库的任何人都不需要执行任何操作来启用这些扩展。

文档 看来这是不可能的,但是有人知道任何巧妙的技巧吗?可以帮我吗?

Normally, I would enable extensions by adding the following to .hg/hgrc:

[extensions]
hgext.win32text=
[encode]
** = cleverencode:
[decode]
** = cleverdecode:

However, I want this configuration to be versioned, i.e. part of the repository, so that it is enabled for anyone else (coworkers, build machines) cloning the repository. Note that whomsoever clones the repository should not be required to do anything to enable these extensions.

It appears it is not possible from the documentation, but does anyone know any neat tricks that can help me here?

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

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

发布评论

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

评论(4

被你宠の有点坏 2024-07-27 16:12:04

您希望 Mercurial 在克隆存储库时自动执行某些操作(更新挂钩或配置)。 文档说这是不可能的,并给出了一些很好的理由:

Hooks do not propagate

In Mercurial, hooks are not revision controlled, and do not propagate when you clone,
or pull from, a repository. The reason for this is simple: a hook is a completely    
arbitrary piece of executable code. It runs under your user identity, with your 
privilege level, on your machine. No comments

It would be extremely reckless for any distributed revision control system to 
implement revision-controlled hooks, as this would offer an easily exploitable way to 
subvert the accounts of users of the revision control system. No comments

很明显,mercurial 本身并不能解决你的问题。 您明确表示您只想用善变来解决您的问题,所以答案是:您所要求的是不可能的。

解决问题的唯一方法是,所有用户都必须至少运行/安装一次给定脚本来执行您想要的操作,例如安装正确的挂钩。

如果您想聪明一点:

  • 创建一个要运行的一次性脚本,该脚本将安装一个挂钩以将正确的配置复制到 .hg 中,或者用户
  • 确保该挂钩一旦安装,就可以更新脚本以分发配置对用户的更新
  • 使钩子添加一些特殊标记以提交消息
  • 拒绝中央存储库提交不携带特殊消息

有点复杂,但这是我能想象到的最接近您的要求:

  • 用户运行一次脚本,然后他们忘记了
  • 您可以确保如果没有运行它,他们就无法提交到您的中央存储库

You want mercurial to do something automatically when you clone a repo (update the hooks or config). Documentation says it is not possible and gives some very good reasons:

Hooks do not propagate

In Mercurial, hooks are not revision controlled, and do not propagate when you clone,
or pull from, a repository. The reason for this is simple: a hook is a completely    
arbitrary piece of executable code. It runs under your user identity, with your 
privilege level, on your machine. No comments

It would be extremely reckless for any distributed revision control system to 
implement revision-controlled hooks, as this would offer an easily exploitable way to 
subvert the accounts of users of the revision control system. No comments

So clearly, mercurial itself won't solve your problem. You clearly state that you want nothing but mercurial to solve your problem, so the answer is: what you are asking is not possible.

The only way to solve your problem is that all your users will have to run/install at least once a given script that perform the actions you want, something like installing the right hooks.

If you want to be clever about this:

  • create a one-time script to run that will install a hook to copy the right config into the .hg or the user
  • make sure that the hook, once installed, can update the script to distribute config updates to the users
  • make the hook add some special marking to commit messages
  • refuse on the central repository commit that do not carry the special message

A bit complicated, but that's the closest I can imagine to your requirements:

  • user run a script once and they forget
  • you can make sure that if the did not run it, they can not commit to your central repo
淡笑忘祈一世凡恋 2024-07-27 16:12:04

Mercurial 的当前开发版本(将于 7 月 1 日作为 Mercurial 1.3 发布)在其配置文件中支持 %include 指令。

这意味着您可以要求人们将其放入

%include ../common-hgrc

.hg/hgrc 中。 完成此操作后,您可以通过向 common-hgrc 提交更改来有效控制其 Mercurial 设置。 当他们拉取更改时,新设置将生效。

请注意,这很危险:任何可以让您将更改拉入存储库的人现在都可以将任意挂钩插入到 common-hgrc 中,并且您将在下一个 Mercurial 命令上执行它们(甚至是“安全”命令) “命令行hg status)。

The current development version of Mercurial (to be released as Mercurial 1.3 on July 1st) supports a %include directive in its configuration files.

That means that you can ask people to put

%include ../common-hgrc

into .hg/hgrc. Having done that, you can then effectively control their Mercurial settings by committing changes to common-hgrc. When they pull the change, the new settings will take effect.

Do note, that this is dangerous: anybody who can get you to pull changes into your repository can now insert arbitrary hooks into common-hgrc and you will execute them on the next Mercurial command (even a "safe" command line hg status).

小苏打饼 2024-07-27 16:12:04

您也许可以通过 ProjRC 扩展 解决该问题。

“此扩展使 Mercurial 查找并解析 .hg/projrc 以获取其他配置设置。 文件在克隆和拉取时传输(但从不在推送时传输)”

You might be able to solve that problem via the ProjRC extension.

“This extension makes Mercurial look for and parse .hg/projrc for additional configuration settings. The file is transferred on clone and on pull (but never on push)”

心意如水 2024-07-27 16:12:04

创建一个从 .hg/hgrccustomhg/hgrc 的链接,以便对其进行版本控制怎么样? 然后您需要创建一些钩子将其复制回 .hg/hgrc - 例如在每次更新后。

What about creating a link from .hg/hgrc to e.g. customhg/hgrc so that it gets versioned. Then you need to create some hook that copies it back to .hg/hgrc - e.g. after each update.

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