Best way to use a custom ui class in a localrepo?

David Baum dbaum at google.com
Wed Apr 29 16:26:36 CDT 2009


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?

Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://selenic.com/pipermail/mercurial/attachments/20090429/1e7a88e9/attachment.htm 


More information about the Mercurial mailing list