Check whether a configuration key is set globally, rather than on the current repository

Angel Ezquerra angel.ezquerra at
Fri Feb 24 02:59:24 CST 2012

On Thu, Feb 23, 2012 at 7:25 PM, Matt Mackall <mpm at> wrote:
> On Thu, 2012-02-23 at 17:23 +0100, Angel Ezquerra Moreu wrote:
>> Hi,
>> I am working on an extension and I need to tell if a given
>> configuration key is set globally, but is not set on the current
>> repository's configuration file.
>> The reason is that I want to use the global configuration as a
>> fallback, and I want the extension to behave differently depending on
>> whether the setting that is being used is the fallback, versus the
>> case in which the setting has been explicitly set on the current
>> repository.
> Sounds like too much magic.

It is a bit magic indeed but I think it makes sense in my case.

What I am trying to do is to mimic github's and bitbucket's "readme"
feature in TortoiseHg (although this may be useful for bare mercurial
as well).

What they do is that they look for "README files" in your repository.
"README files", are those that match a set of names such as "README",
"", "README.txt", etc. If such a file is found on a repository,
they show it to you as the project documentation.

I want to do a similar thing, but I also want to let the user modify
the default behavior by setting the readme configuration key on a
given repository. I also want to let the user set a default readme
file that should only be used when the repository readme key has not
been set and no "README file" has been found on the repo.

So I want to check for a repository readme setting first, then for a
repository readme file and if everything fails for a global config
readme setting.

>> As far as I know, there is no way to read the "current repo"
>> configuration only using the mercurial ui API. The "config" methods of
>> the repo.ui object try to read from the current repo config, and if
>> they fail they seamlessly read from the global configuration (which is
>> what you'd want 99.9...% of the time).
>> Yet in my very particular case this is not what I need. The only way
>> that I've come up with is to read both from the current repo.ui object
>> and from the global ui object, and if both configuration values match
>> assume that the configuration key is set globally. However this would
>> not detect the case in which the same configuration value is set both
>> globally and on the current repo.
> You can check the path information in the config key (see hg showconfig
> --debug).

OK, I see that there is an ui.configpath() function that I can use for this.



More information about the Mercurial-devel mailing list