Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2017-11-03 17:31:18 +0300
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2017-11-06 13:20:13 +0300
commit95640413e64c4a857bcfcf7a4dcf0ce79189f894 (patch)
tree7367c047c57d1e93229039cbc28f39b4fcc08a43 /lib/gitlab/git/popen.rb
parentdfe6c5390d73aff7b20876c3864524d49be74940 (diff)
Gitlab::Git::Popen can lazily hand output to a block
This allows input to start processing immediately without waiting for the process to complete. This also allows long or infinite inputs to be partially processed, which will termiate the process when reading stops with SIGPIPE.
Diffstat (limited to 'lib/gitlab/git/popen.rb')
-rw-r--r--lib/gitlab/git/popen.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/gitlab/git/popen.rb b/lib/gitlab/git/popen.rb
index b45da6020ee..d41fe78daa1 100644
--- a/lib/gitlab/git/popen.rb
+++ b/lib/gitlab/git/popen.rb
@@ -7,7 +7,7 @@ module Gitlab
module Popen
FAST_GIT_PROCESS_TIMEOUT = 15.seconds
- def popen(cmd, path, vars = {})
+ def popen(cmd, path, vars = {}, lazy_block: nil)
unless cmd.is_a?(Array)
raise "System commands must be given as an array of strings"
end
@@ -22,7 +22,12 @@ module Gitlab
yield(stdin) if block_given?
stdin.close
- @cmd_output << stdout.read
+ if lazy_block
+ return lazy_block.call(stdout.lazy)
+ else
+ @cmd_output << stdout.read
+ end
+
@cmd_output << stderr.read
@cmd_status = wait_thr.value.exitstatus
end