开发者

Keeping divergent versions of a hg version-controlled file on different machines?

开发者 https://www.devze.com 2023-01-29 10:15 出处:网络
I am working on a project that depends on external programs, and needs to know开发者_开发知识库 the paths to them. I develop and use the project on several machines, using mercurial for version contro

I am working on a project that depends on external programs, and needs to know开发者_开发知识库 the paths to them. I develop and use the project on several machines, using mercurial for version control. The paths are machine-dependent, so I keep them in a machine-specific config file. I would like the config file for each host to be version-controlled, but I need to ensure that the config file from one host would never overwrite the config file for another host when pushing or pulling between hosts. Is there any way to accomplish this?


In principle, Wim is right: machine specific configurations shouldn't be part of the project's source control. As long as you walk alone, this isn't a real problem, but once you want to provide generic releases of your project, you have to get rid of them. In that case you might not be happy about the fact, that the change history contains files with machine specific data.

Nevertheless, it may make sense to have machine specific data in version controlled files (personally I do this for my dot-rc files and shell scripts). In that case I would suggest to separate generic and specific configurations into different files and include/utilize the specific one at build- or runtime, depending on the currently used machine.

If it is not possible to detect the current machine automatically, you could still create an unversioned symbolic link on each machine, pointing to the appropriate specific configuration file. For instance, on the machine foo the file layout could look like this:

  • generic.conf version-controlled
  • specific-foo.conf version-controlled
  • specific-bar.conf version-controlled
  • specific.confspecific-foo.conf unversioned symbolic link

An alternative to symbolic links is to use a hook which automatically creates specific.conf, e.g. on each invocation of hg update. As hooks are set in a repository's hgrc file, it can be defined individually on each machine. Here's an example of a corresponding hooks section in the .hg/hgrc file of a repository clone on the machine foo:

[hooks]
update = cp specific-foo.conf specific.conf


Machine specific configuration settings should not be version controlled in the same repository as the project code.

However, it is still a good idea to put an inactive sample configuration file in your code repository. And this sample could show a bunch of typical locations for the external program paths you mentioned as lines that are commented out. That way you make it easier to get your project running on new machines.

0

精彩评论

暂无评论...
验证码 换一张
取 消