[PATCH 0 of 1] ui.environ property, take 2

Sune Foldager cryo at cyanite.org
Wed Nov 18 04:09:54 CST 2009


We add an environ property to ui, which usually just accesses os.environ;
when a WSGI request is in progress, however, they are not the same.


In WSGI (and FastCGI) processing, the request information is provided in
an os.environ-like map, which is not copied to os.environ for various reasons
most of you likely already know. Most of the hgweb processing works correctly
as it doesn't use os.environ (but instead req.environ), but hooks called from
mercurial, including in particular the pretxnchangegroup hook, don't have
access to the request object's environment.

Some information is already provided to hooks in a somewhat ad-hoc fashion,
such as the request url provided via addchangegroup. Using the request
environment map, such things can be tranfered via ui.environ in the future,
which will also be much easier to expand.


We have a branch-auth pretxnchangegroup hook that needs to inspect HTTP auth
headers, since we do custom authorization. With CGI, we can use os.environ, but
with WSGI/FastCGI this is not possible. Also, the passed in 'url' doesn't contain
the necessary information.

The patch is simple and unintrusive; for obvious reasons it doesn't change
anything for existing users of ui objects. True, the first access to os.environ
will copy the process environment, but this will almost always have been done
several times by the time this code can be reached. If people agree with this,
I plan on adding tests (to the extent possible) and push to crew in the near

More information about the Mercurial-devel mailing list