Best way to use a custom ui class in a localrepo?
Steve Borho
steve at borho.org
Thu Apr 30 09:53:35 CDT 2009
On Wed, Apr 29, 2009 at 4:26 PM, David Baum <dbaum at google.com> wrote:
> I'm writing some Python code that is importing various mercurial modules and
> calling them directly (instead of always executing shell commands). I'd
> like to be able to replace ui.prompt() with my own custom code, but I can't
> find a clean way to do this. It feels like the ui class was made just for
> this purpose, but the problem is that localrepository will always create its
> own ui by calling: ui.ui(parentui=parentui), so even if I create my own
> subclass of ui and pass it to hg.repository(), the localrepository object
> will just go ahead and create its own ui.ui() instance. I can think of
> several workarounds...
> 1) Create a subclass of ui and monkey-patch it into the ui module as ui...
> OriginalUi = ui.ui
> class MyUi(OriginalUi):
> ...
> ui.ui = MyUi
> 2) Let localrepository create a ui.ui(), but then go in and replace it
> (repo.ui = MyUi()). The disadvantage to this is that my custom ui won't be
> used during the local repository initialization.
> 3) Don't bother with a subclass and just monkey-patch the ui methods of
> interest (prompt, etc).
> To be honest, all of these feel a bit gross. Anyone have a cleaner way to
> provide custom readconfig and prompt behavior?
It is a bit gross, but it has been recently improved quite a bit on the tip
of (unreleased) hg. It now copies your class instance instead of allocating
another instance of ui.ui()
--
Steve Borho
More information about the Mercurial
mailing list