Calling Python Functions from Non-hooks

Matt Mackall mpm at selenic.com
Tue Feb 3 16:30:51 CST 2009


On Tue, 2009-02-03 at 13:47 -0800, Micah Ransdell wrote:
> Is it possible to call a python function from a non-hook in a hgrc
> file? For example, I am wanting to return a list of users that are
> allowed to read a repository (under allow_read), but I want to do that
> dynamically. Is it possible to call a python function in much the same
> way that we can call them for hooks? Obviously I could periodically go
> through and update the hgrc file with the users who are allowed to
> read the repo through an automated process, but I would prefer the
> check to happen when someone accesses the repository. Any suggestions?

This is a great place to use an extension. Look at how
hgext/zeroconf/__init__.py adds to [paths] dynamically, starting at line
43:

def config(orig, self, section, key, default=None, untrusted=False):
    if section == "paths" and key.startswith("zc-"):
        for n, p in getzcpaths():
            if n == key:
                return p
    return orig(self, section, key, default, untrusted)

def configitems(orig, self, section, untrusted=False):
    r = orig(self, section, untrusted)
    if section == "paths":
        r += getzcpaths()
    return r

extensions.wrapfunction(ui.ui, 'config', config)
extensions.wrapfunction(ui.ui, 'configitems', configitems)

-- 
http://selenic.com : development and support for Mercurial and Linux




More information about the Mercurial mailing list