pager extension on windows - please review
Eduard STEFAN
alexandrul.ct at gmail.com
Wed Mar 10 14:22:06 CST 2010
Hi,
I'm playing with the pager extension,
trying to make it work on windows.
In the current state, the output is blank.
The "Works on My Machine" version is shown below:
-----------------------------------------
# HG changeset patch
# User Eduard STEFAN <alexandrul.ct at gmail.com>
# Date 1268251665 -7200
# Node ID ed5f82002a2f84fb9534b809d476dcfe4c3fe79c
# Parent d3f27d15c9cb7333a0cd8b3a1f141a3e5743787e
win32 pager
diff --git a/hgext/pager.py b/hgext/pager.py
--- a/hgext/pager.py
+++ b/hgext/pager.py
@@ -49,7 +49,7 @@
specify them in the global .hgrc
'''
-import sys, os, signal
+import sys, os, signal, tempfile, subprocess
from mercurial import dispatch, util, extensions
def uisetup(ui):
@@ -60,10 +60,25 @@
if (cmd in attend or
(cmd not in ui.configlist('pager', 'ignore') and not attend)):
ui.setconfig('ui', 'interactive', False)
- sys.stderr = sys.stdout = util.popen(p, "wb")
- if ui.configbool('pager', 'quiet'):
- signal.signal(signal.SIGPIPE, signal.SIG_DFL)
- return orig(ui, options, cmd, cmdfunc)
+
+ ui.pushbuffer()
+ _returncode = orig(ui, options, cmd, cmdfunc)
+ _tobepaged = ui.popbuffer()
+ _filepath = tempfile.NamedTemporaryFile().name
+
+ _file = open(_filepath,"w")
+ _file.writelines(_tobepaged)
+ _file.flush()
+ _file.close()
+
+ subprocess.call(p + " " + _filepath)
+
+ os.remove(_filepath)
+
+ else:
+ _returncode = orig(ui, options, cmd, cmdfunc)
+
+ return _returncode
extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
-----------------------------------------
However, I'm missing a lot of information regarding Mercurial internals
(the hooks are pretty well documented, but for this kind on extensions
I still don't master the details). Is there another source of information
regarding the Mercurial internals besides Mercurial API and
Mercurial: The Definitive Guide?
Please review the changes and kindly explain what I did wrong
and the possible improvements.
What I'm currently search for is how to treat the possible exceptions
and errors in the hg commands that are paged (like what should be done
in case of errors on loading other extensions).
Also, what is the recommended way to respect the HGPLAIN environment variable?
Have a nice day,
Eduard
More information about the Mercurial-devel
mailing list