From 25dca42bac17d511b7e2ebdd9d1d679e7626db5f Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 3 Jun 2010 09:35:24 +0200 Subject: 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 --- lib/git/cmd.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'lib/git/cmd.py') diff --git a/lib/git/cmd.py b/lib/git/cmd.py index 3da46d5e..82daf551 100644 --- a/lib/git/cmd.py +++ b/lib/git/cmd.py @@ -184,10 +184,10 @@ class Git(object): See also: Git.max_chunk_size ``**subprocess_kwargs`` - Keyword arguments to be passed to subprocess.Popen. Please note that - some of the valid kwargs are already set by this method, the ones you - specify may not be the same ones. - + Keyword arguments to be passed to subprocess.Popen. Please note that + some of the valid kwargs are already set by this method, the ones you + specify may not be the same ones. + Returns:: str(output) # extended_output = False (Default) @@ -231,7 +231,13 @@ class Git(object): stderr_value = '' try: if output_stream is None: - stdout_value = proc.stdout.read().rstrip() # strip trailing "\n" + stdout_value, stderr_value = proc.communicate() + # strip trailing "\n" + if stdout_value.endswith("\n"): + stdout_value = stdout_value[:-1] + if stderr_value.endswith("\n"): + stderr_value = stderr_value[:-1] + status = proc.returncode else: max_chunk_size = self.max_chunk_size while True: @@ -241,11 +247,12 @@ class Git(object): break # END reading output stream stdout_value = output_stream + stderr_value = proc.stderr.read() + # strip trailing "\n" + if stderr_value.endswith("\n"): + stderr_value = stderr_value[:-1] + status = proc.wait() # END stdout handling - stderr_value = proc.stderr.read().rstrip() # strip trailing "\n" - - # waiting here should do nothing as we have finished stream reading - status = proc.wait() finally: proc.stdout.close() proc.stderr.close() -- cgit v1.2.1