[PATCH 3 of 7] procutil: unify platform.explainexit()

Yuya Nishihara yuya at tcha.org
Sat Apr 7 09:39:39 EDT 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1523103256 -32400
#      Sat Apr 07 21:14:16 2018 +0900
# Node ID 7ab4ebc2c6d6b71b540258c0eaeb840b3bc322a5
# Parent  2564c8fbfd8d501efade8cbaf1ecf689f956311e
procutil: unify platform.explainexit()

Since 4368f582c806 "use subprocess instead of os.system", posix.explainexit()
is the superset of Windows implementation.

diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -479,13 +479,6 @@ def testpid(pid):
     except OSError as inst:
         return inst.errno != errno.ESRCH
 
-def explainexit(code):
-    """return a 2-tuple (desc, code) describing a subprocess status
-    (codes from kill are negative - not os.system/wait encoding)"""
-    if code >= 0:
-        return _("exited with status %d") % code, code
-    return _("killed by signal %d") % -code, -code
-
 def isowner(st):
     """Return True if the stat object st is from the current user."""
     return st.st_uid == os.getuid()
diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -52,7 +52,6 @@ if pycompat.iswindows:
 else:
     from .. import posix as platform
 
-explainexit = platform.explainexit
 findexe = platform.findexe
 _gethgcmd = platform.gethgcmd
 getuser = platform.getuser
@@ -79,6 +78,13 @@ except AttributeError:
 
 closefds = pycompat.isposix
 
+def explainexit(code):
+    """return a 2-tuple (desc, code) describing a subprocess status
+    (codes from kill are negative - not os.system/wait encoding)"""
+    if code >= 0:
+        return _("exited with status %d") % code, code
+    return _("killed by signal %d") % -code, -code
+
 class _pfile(object):
     """File-like wrapper for a stream opened by subprocess.Popen()"""
 
diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -311,9 +311,6 @@ def quotecommand(cmd):
         return '"' + cmd + '"'
     return cmd
 
-def explainexit(code):
-    return _("exited with status %d") % code, code
-
 # if you change this stub into a real check, please try to implement the
 # username and groupname functions above, too.
 def isowner(st):


More information about the Mercurial-devel mailing list