0

Here is what I mean:

[paths]
default = some/path/to/something
another_path = [paths.default]/something/else

Can it be done somehow?

Thanks ;)

hollov
  • 25
  • 5

1 Answers1

1

No, the Mercurial config format has no concept of variables or re-use.

See the hgrc documentation:

The values are either free-form text strings, lists of text strings, or Boolean values. Boolean values can be set to true using any of "1", "yes", "true", or "on" and to false using "0", "no", "false", or "off" (all case insensitive).

Individual settings may support some form of variable parsing, but this does not apply to values in the configuration file in general. Variable support (environment or otherwise) is the exception, not the norm. For example, %include (to include another configuration file) does support environment variables via the Python os.path.expandvars() function, but this does not apply to any other syntax.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Config files are handling environment variables. Aren't these config items stored in env vars? 'Cause then it can be done like this: `another_path = %HG_PATHS_DEFAULT%/something/else` – hollov Jun 23 '16 at 09:30
  • @hollov: sorry, not even environment variables can be used. And no, Mercurial configuration is not stored in environment variables. – Martijn Pieters Jun 23 '16 at 09:30
  • Thanks for the answers. But for the record: you do can use env vars in config. I use `%user%` for example :) – hollov Jun 23 '16 at 09:36
  • @hollov: I verified the documentation again and looked at the [source code](https://selenic.com/hg/file/tip/mercurial/config.py) once more, and the answer is still no. `%user%` is not supported in the config file syntax. The `%include` syntax does expand environment variables via [`os.path.expandvars()`](https://docs.python.org/2/library/os.path.html#os.path.expandvars) but that's an exception, not the norm. – Martijn Pieters Jun 23 '16 at 09:52
  • Wow. Thanks for putting so much effort into this :) But I am using this under [ui] section and it is working just fine: `[ui] username = %username%`. It gets the username correctly from windows login – hollov Jun 23 '16 at 10:00
  • @hollov: yes, `ui.username` uses expansion, it is [explicitly documented](https://www.selenic.com/mercurial/hgrc.5.html#ui): *Environment variables in the username are expanded*. This is one of those exceptions. – Martijn Pieters Jun 23 '16 at 10:03