summaryrefslogtreecommitdiff
path: root/lib/git/cmd.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2010-06-03 09:35:24 +0200
committerSebastian Thiel <byronimo@gmail.com>2010-06-03 09:37:50 +0200
commit25dca42bac17d511b7e2ebdd9d1d679e7626db5f (patch)
tree57ce6ef7b284ef3993019f275c38194bffc0134a /lib/git/cmd.py
parente79999c956e2260c37449139080d351db4aa3627 (diff)
downloadgitpython-25dca42bac17d511b7e2ebdd9d1d679e7626db5f.tar.gz
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
Diffstat (limited to 'lib/git/cmd.py')
-rw-r--r--lib/git/cmd.py25
1 files changed, 16 insertions, 9 deletions
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()