Patchwork [4,of,7] procutil: fix error message of tempfile filter

login
register
mail settings
Submitter Yuya Nishihara
Date April 7, 2018, 1:39 p.m.
Message ID <91d6e908f4703e421c88.1523108380@mimosa>
Download mbox | patch
Permalink /patch/30545/
State Accepted
Headers show

Comments

Yuya Nishihara - April 7, 2018, 1:39 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1523103470 -32400
#      Sat Apr 07 21:17:50 2018 +0900
# Node ID 91d6e908f4703e421c887f24ae8c23bf98c32202
# Parent  7ab4ebc2c6d6b71b540258c0eaeb840b3bc322a5
procutil: fix error message of tempfile filter

First, we need to use procutil.system() to get an exit code compatible with
explainexit(). Second, explainexit() returns (msg, code) tuple.

Patch

diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -174,12 +174,12 @@  def tempfilter(s, cmd):
         os.close(outfd)
         cmd = cmd.replace('INFILE', inname)
         cmd = cmd.replace('OUTFILE', outname)
-        code = os.system(cmd)
+        code = system(cmd)
         if pycompat.sysplatform == 'OpenVMS' and code & 1:
             code = 0
         if code:
             raise error.Abort(_("command '%s' failed: %s") %
-                              (cmd, explainexit(code)))
+                              (cmd, explainexit(code)[0]))
         with open(outname, 'rb') as fp:
             return fp.read()
     finally:
diff --git a/tests/test-encode.t b/tests/test-encode.t
--- a/tests/test-encode.t
+++ b/tests/test-encode.t
@@ -59,5 +59,14 @@  check hg cat operation
   this is a test
   $ hg -R .. cat --decode ../a.gz | gunzip
   this is a test
+  $ cd ..
+
+check tempfile filter
+
+  $ hg cat a.gz --decode --config 'decode.*.gz=tempfile:gzip -c INFILE > OUTFILE' | gunzip
+  this is a test
+  $ hg cat a.gz --decode --config 'decode.*.gz=tempfile:sh -c "exit 1"'
+  abort: command '*' failed: exited with status 1 (glob)
+  [255]
 
   $ cd ..