[PATCH V2] posix: update os.popen with subprocess (issue4746)

Rishabh Madan rishabhmadan96 at gmail.com
Fri Mar 3 07:50:53 UTC 2017


# HG changeset patch
# User Rishabh Madan <rishabhmadan96 at gmail.com>
# Date 1488526994 -19800
#      Fri Mar 03 13:13:14 2017 +0530
# Node ID a134680eec2421b86d7f240b0b06947c1d777502
# Parent  71f692f1f678d86ffb4f95a3621aacfdaeb96b05
posix: update os.popen with subprocess (issue4746)

While importing a patch, we use a patch tool, say 'patch --merge', and the
patch doesn't merge cleanly, 'patch --merge' will return with exit status 1,
but 'hg import' displays 'abort: patch command failed: exited with status 256'.
The previous version of this patch replaced deprecated os.popen with
subprocess.Popen for mode='r'. But as discussed it would break popen for mode='w'.
This patch implements conditional popen for both read/write mode.

diff -r 71f692f1f678 -r a134680eec24 mercurial/posix.py
--- a/mercurial/posix.py	Wed Mar 01 20:22:04 2017 +0100
+++ b/mercurial/posix.py	Fri Mar 03 13:13:14 2017 +0530
@@ -16,6 +16,7 @@
 import re
 import select
 import stat
+import subprocess
 import sys
 import tempfile
 import unicodedata
@@ -419,7 +420,12 @@
     return cmd
 
 def popen(command, mode='r'):
-    return os.popen(command, mode)
+    if mode == 'r':
+        return subprocess.Popen(command, shell=True,
+            stdout=subprocess.PIPE).stdout
+    else:
+        return subprocess.Popen(command, shell=True,
+            stdin=subprocess.PIPE).stdin
 
 def testpid(pid):
     '''return False if pid dead, True if running or not sure'''


More information about the Mercurial-devel mailing list