Skip to content

Commit 1f16be8

Browse files
authored
Merge pull request #158 from sergiomb2/0.4.x
(#140) bugfix: Pipes are only done from stdout to stdin
2 parents cbc8305 + 4de5825 commit 1f16be8

1 file changed

Lines changed: 35 additions & 42 deletions

File tree

patchview/patchview-wrapper

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/python3
2-
# SPDX-License-Identifier: GPL-2.0-or-later
32
# -*- coding: utf-8 -*-
43
#
4+
# SPDX-License-Identifier: GPL-2.0-or-later
5+
#
56
# Copyright (C) 2015-2025 Sérgio Basto <sergio@serjux.com>
67
#
78
# This program is free software; you can redistribute it and/or modify it
@@ -54,60 +55,52 @@ parser = argparse.ArgumentParser()
5455
parser.add_argument('-v', '--debug',
5556
help='writes the commands that will be executed',
5657
action='store_true')
57-
parser.add_argument('git_args', nargs='*', default=[])
58+
parser.add_argument('tool_args', nargs='*', default=[])
5859
parser.add_argument('patchview_args', nargs=argparse.REMAINDER)
5960
args, unknown = parser.parse_known_args()
60-
largs = vars(args).get("git_args")
61-
rargs = vars(args).get("patchview_args")
61+
tool_args = args.tool_args
62+
patchview_args = args.patchview_args + unknown
63+
64+
pipetoview = tool_cmd.endswith("view")
65+
if pipetoview:
66+
tool_cmd = tool_cmd[:-4]
67+
patchview_cmd = ["filterdiff"] + patchview_args
68+
else:
69+
patchview_cmd = ["patchview"] + patchview_args
6270

63-
patchview_cmd = ["patchview"] + rargs + unknown
64-
pipetoview = False
65-
if tool_cmd.endswith("view"):
66-
# pipeline: first_pipe | second_pipe | editor
67-
tool_cmd = tool_cmd[:-4] # remove "view"
68-
patchview_cmd = ["filterdiff"] + rargs + unknown
69-
pipetoview = True
70-
git_cmd = [tool, tool_cmd] + largs
71+
vcs_cmd = [tool, tool_cmd] + tool_args
72+
dest_cmd = [editor, "-R", "-"]
7173

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+
if args.debug:
75+
debug_str = "%s | %s" % (" ".join(vcs_cmd), " ".join(patchview_cmd))
76+
if pipetoview:
77+
debug_str += " | %s" % " ".join(dest_cmd)
78+
sys.stderr.buffer.write((debug_str + "\n").encode())
79+
sys.stderr.flush()
80+
81+
p1 = Popen(vcs_cmd, stdout=PIPE, env=enviro, cwd=workdir)
82+
if pipetoview:
83+
p2 = Popen(patchview_cmd, stdin=p1.stdout, stdout=PIPE, env=enviro, cwd=workdir)
84+
else:
85+
p2 = Popen(patchview_cmd, stdin=p1.stdout, env=enviro, cwd=workdir)
7486

7587
p1.wait()
76-
stdout1, stderr1 = p1.communicate()
77-
if p1.returncode != 0:
88+
ret1 = p1.returncode
89+
if ret1 != 0:
90+
stdout1, _ = p1.communicate()
7891
if stdout1:
7992
sys.stdout.buffer.write(stdout1)
80-
if stderr1:
81-
sys.stderr.buffer.write(stderr1)
82-
sys.exit(p1.returncode)
93+
sys.exit(ret1)
8394

8495
p2.wait()
85-
stdout2, stderr2 = p2.communicate()
86-
if p2.returncode != 0:
96+
ret2 = p2.returncode
97+
if ret2 != 0:
98+
stdout2, _ = p2.communicate()
8799
if stdout2:
88100
sys.stdout.buffer.write(stdout2)
89-
if stderr2:
90-
sys.stderr.buffer.write(stderr2)
91-
sys.exit(p2.returncode)
101+
sys.exit(ret2)
92102

93103
if pipetoview:
94-
dest_cmd = [editor, "-R", "-"]
95-
p3 = Popen(dest_cmd, stdin=PIPE)
96-
if args.debug:
97-
debug_str = "%s | %s | %s\n" % (" ".join(git_cmd),
98-
" ".join(patchview_cmd),
99-
" ".join(dest_cmd))
100-
p3.stdin.write(debug_str.encode())
101-
p3.stdin.flush()
102-
103-
p3.stdin.write(stdout2)
104-
p3.stdin.close()
104+
p3 = Popen(dest_cmd, stdin=p2.stdout, env=enviro, cwd=workdir)
105105
p3.wait()
106-
else:
107-
# debug print
108-
if args.debug:
109-
print("%s | %s" % (" ".join(git_cmd), " ".join(patchview_cmd)))
110-
sys.stdout.flush()
111-
112-
sys.stdout.buffer.write(stdout2)
113106

0 commit comments

Comments
 (0)