diff options
author | Quang-Minh Nguyen <qmnguyen@gitlab.com> | 2022-10-31 19:58:10 +0300 |
---|---|---|
committer | Quang-Minh Nguyen <qmnguyen@gitlab.com> | 2022-10-31 20:21:08 +0300 |
commit | a238cbfb8fd039b2fed350aa81f0c0154d9a01f5 (patch) | |
tree | 776847ab602d962e43568059ba2b41e166711ba5 /ruby/lib/gitlab/git/popen.rb | |
parent | 4440aae1c028c263b37ee6f149f11179d22147f8 (diff) |
ruby: Remove ruby/lib/gitlab/git/*
Those classes wrap around rugged data and provide some advanced
sugar-coating methods. Both FindLicense and gitaly-linguist use the
underlying gems exclusively. Those wrappers become obsolete now.
Changelog: other
Diffstat (limited to 'ruby/lib/gitlab/git/popen.rb')
-rw-r--r-- | ruby/lib/gitlab/git/popen.rb | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/ruby/lib/gitlab/git/popen.rb b/ruby/lib/gitlab/git/popen.rb deleted file mode 100644 index 5d8218eb1..000000000 --- a/ruby/lib/gitlab/git/popen.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'open3' - -module Gitlab - module Git - module Popen - FAST_GIT_PROCESS_TIMEOUT = 15.seconds - - def popen(cmd, path, vars = {}, include_stderr: true, lazy_block: nil) - raise "System commands must be given as an array of strings" unless cmd.is_a?(Array) - - path ||= Dir.pwd - vars['PWD'] = path - options = { chdir: path } - - cmd_output = "" - cmd_status = 0 - Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr| - stdout.set_encoding(Encoding::ASCII_8BIT) - stderr.set_encoding(Encoding::ASCII_8BIT) - - # stderr and stdout pipes can block if stderr/stdout aren't drained: https://bugs.ruby-lang.org/issues/9082 - # Mimic what Ruby does with capture3: https://github.com/ruby/ruby/blob/1ec544695fa02d714180ef9c34e755027b6a2103/lib/open3.rb#L257-L273 - err_reader = Thread.new { stderr.read } - - begin - yield(stdin) if block_given? - stdin.close - - if lazy_block - cmd_output = lazy_block.call(stdout.lazy) - cmd_status = 0 - break - else - cmd_output << stdout.read - end - - cmd_output << err_reader.value if include_stderr - cmd_status = wait_thr.value.exitstatus - ensure - # When Popen3.open3 returns, the stderr reader gets closed, which causes - # an exception in the err_reader thread. Kill the thread before - # returning from Popen3.open3. - err_reader.kill - end - end - - [cmd_output, cmd_status] - end - end - end -end |