Skip to content

Commit 25dca42

Browse files
committed
git.cmd: using communicate in the main branch of execution, which might not make a big difference, but perhaps its smarter about broken pipes.
Adjusted code to selectively strip terminating newline, only if they are there. The previous code would effectively duplicate the string and strip whitespace from both ends even though there was no need for it. Its a bit faster now as the tests proclaim
1 parent e79999c commit 25dca42

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

lib/git/cmd.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ def execute(self, command,
184184
See also: Git.max_chunk_size
185185
186186
``**subprocess_kwargs``
187-
Keyword arguments to be passed to subprocess.Popen. Please note that
188-
some of the valid kwargs are already set by this method, the ones you
189-
specify may not be the same ones.
190-
187+
Keyword arguments to be passed to subprocess.Popen. Please note that
188+
some of the valid kwargs are already set by this method, the ones you
189+
specify may not be the same ones.
190+
191191
Returns::
192192
193193
str(output) # extended_output = False (Default)
@@ -231,7 +231,13 @@ def execute(self, command,
231231
stderr_value = ''
232232
try:
233233
if output_stream is None:
234-
stdout_value = proc.stdout.read().rstrip() # strip trailing "\n"
234+
stdout_value, stderr_value = proc.communicate()
235+
# strip trailing "\n"
236+
if stdout_value.endswith("\n"):
237+
stdout_value = stdout_value[:-1]
238+
if stderr_value.endswith("\n"):
239+
stderr_value = stderr_value[:-1]
240+
status = proc.returncode
235241
else:
236242
max_chunk_size = self.max_chunk_size
237243
while True:
@@ -241,11 +247,12 @@ def execute(self, command,
241247
break
242248
# END reading output stream
243249
stdout_value = output_stream
250+
stderr_value = proc.stderr.read()
251+
# strip trailing "\n"
252+
if stderr_value.endswith("\n"):
253+
stderr_value = stderr_value[:-1]
254+
status = proc.wait()
244255
# END stdout handling
245-
stderr_value = proc.stderr.read().rstrip() # strip trailing "\n"
246-
247-
# waiting here should do nothing as we have finished stream reading
248-
status = proc.wait()
249256
finally:
250257
proc.stdout.close()
251258
proc.stderr.close()

0 commit comments

Comments
 (0)