RFC: Patch ui.__init__ and handling differences of versions of hg in extensions

Peter Arrenbrecht peter.arrenbrecht at gmail.com
Tue Feb 19 06:04:35 CST 2008


Hi all

I am working on an extension that needs to capture the output of
specific hg commands. To make this work properly with ui.pushbuffer(),
I suggest the following patch, which makes child uis properly feed
their output to the parentui's active buffer:

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -60,6 +60,7 @@ class ui(object):
                 self.ucdata = dupconfig(self.parentui.ucdata)
             if self.parentui.overlay:
                 self.overlay = dupconfig(self.parentui.overlay)
+            self.buffers = parentui.buffers

     def __getattr__(self, key):
         return getattr(self.parentui, key)

However, to make my extension work with older versions of hg, I did
the following:

# monkey patch ui.__init__ to properly apply parentui's buffers
# otherwise internally created uis will not write to our buffer
def ui_init(ui, verbose=False, debug=False, quiet=False,
            interactive=True, traceback=False, report_untrusted=True,
            parentui=None):
    old_ui_init(ui,verbose,debug,quiet,interactive,traceback,report_untrusted,parentui)
    if parentui is not None:
        ui.buffers = parentui.buffers
old_ui_init = _ui.ui.__init__
_ui.ui.__init__ = ui_init

If the above patch is accepted, then this would not be necessary. Is
there a good way to find out whether such a monkey patch is needed or
not? Or is there another suggested way to handle this situation?

Thanks,
-peo


More information about the Mercurial-devel mailing list