Relative Path Names for extensions in hgrc

A. S. Budden abudden at gmail.com
Sun Apr 8 13:18:19 CDT 2012


All,

It would be really useful (for me) if I could use relative path names
when loading extensions in hgrc.  I'll give a bit more information on
my use case below, but I thought I'd start by asking the questions
first so you don't have to read everything to get to the point!

>From my point of view, this could be implemented in one of two ways,
either of which would work for me.  One would be to add some sort of
automatic variable (e.g. "{CURRENTDIR}") that is automatically
replaced with os.path.abspath(os.path.dirname(src)) in parse() in
config.py (this looks like it would be trivial to implement).  The
other would be to change the way extensions are referenced so that
they can be referred to without a leading slash or {DRIVE}: and are
then taken as being relative to the hgrc in which they are mentioned.
This would probably be more difficult (I'd guess), but I'm not sure:
I'd have to investigate the way extensions are loaded first.  Of
course, there may be many better ways of doing this as well, but I
thought I'd start somewhere.

So, my questions are:

1. Is this something worth pursuing from the point of view of the core
developers?
2. Am I missing some obvious way in which this can already be done
(%include seems to work with relative paths, but extension loading
doesn't from what I can tell)?
3. If it is something that you think is worth pursuing, which approach
would be preferred (one of the above or something else)?  In the case
of the {CURRENTDIR} (or whatever you want it to be called) option, I
could probably submit a patch (something like
http://paste.pocoo.org/show/578087/) very quickly.  In the case of
extension paths being relative, it would probably take me a bit
longer, but I'd be happy to do some digging...

A bit more background for those who are interested:

My ~/.hgrc or %USERPROFILE%/mercurial.ini contain a single entry,
something like %include /path/to/hg_config/hgrc.  The /path/to bit is
different on each computer (mainly because of operating system
differences but also occasionally because of different 'whims' at the
time I set things up.  The hg_config folder is common across every
single computer I use (currently about 6) and hence I keep this under
version control for ease of synchronisation.  In hg_config/hgrc I have
a lot of 'standard' settings and then a line that says %include
$HOSTNAME.hgrc to allow customisation on a per-computer basis where
things need to be different.

As an aside, one thing that irritates me about mercurial is that if I
forget to "export HOSTNAME" in bashrc, Mercurial tries to load .hgrc
rather than name.hgrc and fails WITHOUT giving me a warning: every
(rare) time I start up on a new computer, I go through the same
process of getting confused by "why is it ignoring my settings???".  I
should have learned by now I guess, and maybe I should create a .hgrc
with an error in it so that I at least get some sort of warning, but
it would be nice if it just said "cannot load .hgrc" or something like
that.  But I digress...

Most of the extensions I load are simple (e.g. schemes =) so I don't
have to worry about them.  Two (reposettings and hg-git, not that it
matters) are non-standard and hence need to be included with an
explicit path.  To simplify this, my hg_config repository has two
subrepos: reposettings and hg-git.  When I'm setting up a new machine,
these get automatically cloned at the same time as hg_config.
However, I have to load the extension in the $HOSTNAME.hgrc file as it
is in a different location on each PC and I can't simply do "hg-git =
./hg-git" or "hg-git = {CURRENTDIR}/hg-git".  To make things worse, on
Windows I use Cygwin and occasionally TortoiseHG, so I have to do
"hg-git = $HG_CONFIG_DIR/hg-git" and set the HG_CONFIG_DIR environment
variable to /mnt/c/al/config/hg_config in Cygwin and
C:/al/config/hg_config in Windows generally.  Of course, I could set
$HG_CONFIG_DIR on every machine and use this as a standard set-up
method, but that means more .bashrc messing about that I'd like.  If I
could do "hg-git = ./hg-git" then this would work across
Mercurial-variants and across computers without any customisation (and
that would be a very good thing!).

Many thanks in advance for your thoughts.

Al


More information about the Mercurial-devel mailing list