summaryrefslogtreecommitdiff
path: root/gbp/git/repository.py
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2013-09-18 17:20:41 +0300
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>2014-06-05 14:20:02 +0300
commit570c282965df5d1aae7c3f7a6ef42b2705858f76 (patch)
tree6209cd1cee2e6d5fb1ca8badaa25896b4be4604c /gbp/git/repository.py
parentbd4997fa96b66b0639258e38060cabea8e7fd0e0 (diff)
downloadgit-buildpackage-570c282965df5d1aae7c3f7a6ef42b2705858f76.tar.gz
git-buildpackage-570c282965df5d1aae7c3f7a6ef42b2705858f76.tar.bz2
git-buildpackage-570c282965df5d1aae7c3f7a6ef42b2705858f76.zip
GitRepository.__git_inout: prevent blocking of stdin
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'gbp/git/repository.py')
-rw-r--r--gbp/git/repository.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index db9659ba..0522ecbb 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -212,22 +212,28 @@ class GitRepository(object):
cmd = ['git', command] + args
env = cls.__build_env(extra_env)
+ stdin_arg = subprocess.PIPE if stdin else None
stderr_arg = subprocess.PIPE if capture_stderr else None
log.debug(cmd)
popen = subprocess.Popen(cmd,
- stdin=subprocess.PIPE,
+ stdin=stdin_arg,
stdout=subprocess.PIPE,
stderr=stderr_arg,
env=env,
close_fds=True,
cwd=cwd)
- if stdin:
- popen.stdin.write(stdin)
- popen.stdin.close()
out_fds = [popen.stdout] + ([popen.stderr] if capture_stderr else [])
- while out_fds:
- ready = select.select(out_fds, [], [])
+ in_fds = [popen.stdin] if stdin else []
+ w_ind = 0
+ while out_fds or in_fds:
+ ready = select.select(out_fds, in_fds, [])
+ # Write in chunks of 512 bytes
+ if ready[1]:
+ popen.stdin.write(stdin[w_ind:w_ind+512])
+ w_ind += 512
+ if w_ind > len(stdin):
+ rm_polled_fd(popen.stdin, in_fds)
# Read in chunks of 4k
stdout = popen.stdout.read(4096) if popen.stdout in ready[0] else ''
stderr = popen.stderr.read(4096) if popen.stderr in ready[0] else ''