[PATCH 6 of 6 V3] util.system: rename to rawsystem in favor of ui.system()

Yuya Nishihara yuya at tcha.org
Wed Nov 12 08:38:05 CST 2014


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1415799589 -32400
#      Wed Nov 12 22:39:49 2014 +0900
# Node ID 18c87a673070fbce78849c3beced2b9d14835abe
# Parent  b6944cd4197b1bb1d1fd9e2d6f94453d297c3f03
util.system: rename to rawsystem in favor of ui.system()

This forces third-party extensions to migrate to ui.system(). util.rawsystem()
is unsafe in command server.

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -830,8 +830,8 @@ class ui(object):
         '''execute shell command with appropriate output stream. command
         output will be redirected if fout is not stdout.
         '''
-        return util.system(cmd, environ=environ, cwd=cwd, onerr=onerr,
-                           errprefix=errprefix, out=self.fout)
+        return util.rawsystem(cmd, environ=environ, cwd=cwd, onerr=onerr,
+                              errprefix=errprefix, out=self.fout)
 
     def traceback(self, exc=None, force=False):
         '''print exception traceback if traceback printing enabled or forced.
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -615,7 +615,7 @@ def _sethgexecutable(path):
     global _hgexecutable
     _hgexecutable = path
 
-def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None, out=None):
+def rawsystem(cmd, environ={}, cwd=None, onerr=None, errprefix=None, out=None):
     '''enhanced shell command execution.
     run with environment maybe modified, maybe in different dir.
 
@@ -623,7 +623,10 @@ def system(cmd, environ={}, cwd=None, on
     object as exception.
 
     if out is specified, it is assumed to be a file-like object that has a
-    write() method. stdout and stderr will be redirected to out.'''
+    write() method. stdout and stderr will be redirected to out.
+
+    use ui.system() unless you want to redirect output to the specified file.
+    '''
     try:
         sys.stdout.flush()
     except Exception:
diff --git a/tests/test-demandimport.py b/tests/test-demandimport.py
--- a/tests/test-demandimport.py
+++ b/tests/test-demandimport.py
@@ -20,9 +20,9 @@ print "os =", f(os)
 from mercurial import util
 
 print "util =", f(util)
-print "util.system =", f(util.system)
+print "util.rawsystem =", f(util.rawsystem)
 print "util =", f(util)
-print "util.system =", f(util.system)
+print "util.rawsystem =", f(util.rawsystem)
 
 import re as fred
 print "fred =", f(fred)
diff --git a/tests/test-demandimport.py.out b/tests/test-demandimport.py.out
--- a/tests/test-demandimport.py.out
+++ b/tests/test-demandimport.py.out
@@ -2,9 +2,9 @@ os = <unloaded module 'os'>
 os.system = <built-in function system>
 os = <module 'os' from '?'>
 util = <unloaded module 'util'>
-util.system = <function system at 0x?>
+util.rawsystem = <function rawsystem at 0x?>
 util = <module 'mercurial.util' from '?'>
-util.system = <function system at 0x?>
+util.rawsystem = <function rawsystem at 0x?>
 fred = <unloaded module 're'>
 re = <unloaded module 'sys'>
 fred = <unloaded module 're'>


More information about the Mercurial-devel mailing list