开发者

In mercurial, is there a way to disable ALL configurations (system, user, repo)?

On any non-trivial hg installation, the hgrc's tend to contain significant stuff.

Is there a way to completely ignore/bypass ALL configurations, from system, user, to repo-level?

The use case is to use some hg core functionalities in some automation scripts. Currently, if anything is misconfigured (and I mess with my ~/.hgrc a lot), the scripts will abort f开发者_Python百科or something it doesn't use at all.

It'd be perfect is I can just hg <whatever> --config:none.


You can do it by setting your HGRCPATH environment variable to something with no configuration in it.

ry4an@hail [~/hg/crew] % hg showconfig | grep Ry4an
ui.username=Ry4an Brase <ry4an@msi.umn.edu>
ry4an@hail [~/hg/crew] % HGRCPATH=/dev/null hg showconfig | grep Ry4an
ry4an@hail [~/hg/crew] % 

Also if you're invoking from a script consider HGPLAIN too.

Both found here: https://www.mercurial-scm.org/repo/hg/file/e3b87fb34d00/mercurial/help/environment.txt

Which says:

    41 HGRCPATH
    42     A list of files or directories to search for configuration
    43     files. Item separator is ":" on Unix, ";" on Windows. If HGRCPATH
    44     is not set, platform default search path is used. If empty, only
    45     the .hg/hgrc from the current repository is read.
    46 
    47     For each element in HGRCPATH:
    48 
    49     - if it's a directory, all files ending with .rc are added
    50     - otherwise, the file itself will be added
    51 
    52 HGPLAIN
    53     When set, this disables any configuration settings that might
    54     change Mercurial's default output. This includes encoding,
    55     defaults, verbose mode, debug mode, quiet mode, tracebacks, and
    56     localization. This can be useful when scripting against Mercurial
    57     in the face of existing user configuration.
    58 
    59     Equivalent options set via command line flags or environment
    60     variables are not overridden.


There doesn't seem to have any option to perform want you want. But since the documentation states that

(Unix, Windows) /.hg/hgrc

Per-repository configuration options that only apply in a particular repository. This file is not version-controlled, and will not get transferred during a "clone" operation. Options in this file override options in all other configuration files. On Unix, most of this file will be ignored if it doesn't belong to a trusted user or to a trusted group. See the documentation for the trusted section below for more details.

The following script will read the stdin and convert the output of hg -showconfig to an override config that could be written at <repo>/.hg/hgrc. Effectively it overrides all the current config found by hg. The script might have to be tweaked but it seems to work so far.

# File override.py

import sys

config = dict()
for l in sys.stdin.readlines():
    section, sep, value = l.partition('.')
    if not section in config:
        config[section] = []
    config[section].append(value.split("=")[0])

for k in iter(config):
    print "[{0}]".format(k)
    for v in config[k]:
        print v + "="

It can then be used as such:

> rm -f .hg/hgrc
> hg -showconfig | python override.py > .hg/hgrc
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜