Calling Python Functions from Non-hooks
Micah Ransdell
mjr578 at gmail.com
Tue Feb 3 16:42:40 CST 2009
Awesome Matt, thank you! I knew there had to be a way to do it, but I
haven't had that much experience with extensions.
I will give it a shot.
Micah
On Tue, Feb 3, 2009 at 2:30 PM, Matt Mackall <mpm at selenic.com> wrote:
> 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
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://selenic.com/pipermail/mercurial/attachments/20090203/f1577959/attachment.htm
More information about the Mercurial
mailing list