[PATCH] prevent console windows popping up on windows while updating svn subrepos

Adrian Buehlmann adrian at cadifra.com
Wed May 25 06:04:49 CDT 2011

On 2011-05-25 12:03, Adrian Buehlmann wrote:
> On 2011-05-25 10:16, dmitry.yakimenko at nokia.com wrote:
>>>> +            startupinfo = subprocess.STARTUPINFO()
>>>> +            startupinfo.dwFlags |= _STARTF_USESHOWWINDOW
>>>> +            startupinfo.wShowWindow = _SW_HIDE
>>> Why don't you use Python's subprocess.STARTF_USESHOWWINDOW and
>>> subprocess.SW_HIDE
>> That was my original implementation, but it behaves differently on different versions of Python.  Sometimes it's  subprocess.SW_HIDE and sometimes it's subprocess._ subprocess .SW_HIDE (http://stackoverflow.com/questions/4703983/).  I had to pollute the code with compatibility workarounds first.  Then I noticed that Mercurial already has these constants defined, so I used them.
> Ah, Yes. The Python folks privatized that stuff in Python 2.7, so we
> shouldn't use it. I forgot about that (I think I ran into that as well
> in the past).
>> As Mads Kiilerich suggested it would make more sense to move that into util.py.  I noticed there're two functions popen2 and popen3 which do something similar.  I'm not familiar enough with the Mercurial codebase to make a well evaluated decision if it would be safe to add that extra parameter to popen2 and popen3.
> I think we could add that parameter to popen3 and probably provide an an
> override implementation of popen3 for windows in mercurial.win32 using
> ctypes.
>> Maybe you could use this patch just as an example and modify the code in the way that seems the most appropriate to you.  I could create a ticket in the bug database and describe how this could be fixed.
> My problem is, I don't use neither subversion nor mercurial subrepos
> (doh!), so I'm not really an expert for your high level use case.
> But I think I might be able to provide a suitable implementation of
> popen3 in win32.py using ctypes (I'm used to hacking there), so you
> could then use that and test it.
> Mads?

This might even be as simple as (untested):

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -63,7 +63,7 @@
     return p.stdin, p.stdout

-def popen3(cmd, env=None, newlines=False):
+def popen3(cmd, env=None, newlines=False, hidewindow=True):
     p = subprocess.Popen(cmd, shell=True, bufsize=-1,
                          stdin=subprocess.PIPE, stdout=subprocess.PIPE,
diff --git a/mercurial/win32.py b/mercurial/win32.py
--- a/mercurial/win32.py
+++ b/mercurial/win32.py
@@ -447,3 +447,17 @@
     if notindexed:
         _kernel32.SetFileAttributesA(path, _FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)
+def popen3(cmd, env=None, newlines=False, hidewindow=True):
+    si = None
+    if hidewindow:
+        si = subprocess.STARTUPINFO()
+        si.dwFlags |= _STARTF_USESHOWWINDOW
+        si.wShowWindow = _SW_HIDE
+    p = subprocess.Popen(cmd, shell=True, bufsize=-1,
+                         close_fds=closefds,
+                         stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+                         stderr=subprocess.PIPE,
+                         universal_newlines=newlines, env=env,
+                         startupinfo=si)
+    return p.stdin, p.stdout, p.stderr

which then can be used as util.popen3 on all platforms.

More information about the Mercurial-devel mailing list