@@ -60,16 +60,37 @@ args, unknown = parser.parse_known_args()
6060largs = vars (args ).get ("git_args" )
6161rargs = vars (args ).get ("patchview_args" )
6262
63+ patchview_cmd = ["patchview" ] + rargs + unknown
64+ pipetoview = False
6365if tool_cmd .endswith ("view" ):
6466 # pipeline: first_pipe | second_pipe | editor
6567 tool_cmd = tool_cmd [:- 4 ] # remove "view"
66- git_cmd = [tool , tool_cmd ] + largs
6768 patchview_cmd = ["filterdiff" ] + rargs + unknown
68-
69- p1 = Popen (git_cmd , stdout = PIPE , env = enviro , cwd = '.' )
70- p2 = Popen (patchview_cmd , stdin = p1 .stdout , stdout = PIPE , env = enviro , cwd = workdir )
71- p1 .stdout .close ()
72-
69+ pipetoview = True
70+ git_cmd = [tool , tool_cmd ] + largs
71+
72+ p1 = Popen (git_cmd , stdout = PIPE , env = enviro , cwd = workdir )
73+ p2 = Popen (patchview_cmd , stdin = p1 .stdout , stdout = PIPE , env = enviro , cwd = workdir )
74+
75+ p1 .wait ()
76+ stdout1 , stderr1 = p1 .communicate ()
77+ if p1 .returncode != 0 :
78+ if stdout1 :
79+ sys .stdout .buffer .write (stdout1 )
80+ if stderr1 :
81+ sys .stderr .buffer .write (stderr1 )
82+ sys .exit (p1 .returncode )
83+
84+ p2 .wait ()
85+ stdout2 , stderr2 = p2 .communicate ()
86+ if p2 .returncode != 0 :
87+ if stdout2 :
88+ sys .stdout .buffer .write (stdout2 )
89+ if stderr2 :
90+ sys .stderr .buffer .write (stderr2 )
91+ sys .exit (p2 .returncode )
92+
93+ if pipetoview :
7394 dest_cmd = [editor , "-R" , "-" ]
7495 p3 = Popen (dest_cmd , stdin = PIPE )
7596 if args .debug :
@@ -79,26 +100,14 @@ if tool_cmd.endswith("view"):
79100 p3 .stdin .write (debug_str .encode ())
80101 p3 .stdin .flush ()
81102
82- for chunk in iter (lambda : p2 .stdout .read (4096 ), b'' ):
83- p3 .stdin .write (chunk )
84- p3 .stdin .flush ()
85-
86- p2 .stdout .close ()
103+ p3 .stdin .write (stdout2 )
87104 p3 .stdin .close ()
88105 p3 .wait ()
89106else :
90- # pipeline normal: tool cmd | patchview
91- git_cmd = [tool , tool_cmd ] + largs
92- patchview_cmd = ["patchview" ] + rargs + unknown
93-
94- p1 = Popen (git_cmd , stdout = PIPE , env = os .environ , cwd = '.' )
95- p2 = Popen (patchview_cmd , stdin = p1 .stdout , stdout = PIPE , env = enviro , cwd = workdir )
96- p1 .stdout .close ()
97-
98107 # debug print
99108 if args .debug :
100109 print ("%s | %s" % (" " .join (git_cmd ), " " .join (patchview_cmd )))
101110 sys .stdout .flush ()
102111
103- sys .stdout .buffer .write (p2 . communicate ()[ 0 ] )
112+ sys .stdout .buffer .write (stdout2 )
104113
0 commit comments