diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2018-06-07 20:05:03 +0300 |
---|---|---|
committer | Francisco Javier López <fjlopez@gitlab.com> | 2018-06-07 20:05:03 +0300 |
commit | fe255758ac08d37497eef4469b92959c94e85328 (patch) | |
tree | 1ada4006dce1e265418b3a988e0ca0f160d74096 | |
parent | 8d1ba9a849401f18c8742f8f70396b648722a3f7 (diff) |
Adding Gitlab::Popenfj-vendoring-ruby-dir
-rwxr-xr-x | _support/vendor-gitlab-git | 1 | ||||
-rw-r--r-- | changelogs/unreleased/fj-vendoring-ruby-dir.yml | 2 | ||||
-rw-r--r-- | ruby/lib/gitlab/git.rb | 7 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/REVISION | 2 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/popen.rb | 48 |
5 files changed, 52 insertions, 8 deletions
diff --git a/_support/vendor-gitlab-git b/_support/vendor-gitlab-git index 124128ef5..389766557 100755 --- a/_support/vendor-gitlab-git +++ b/_support/vendor-gitlab-git @@ -7,6 +7,7 @@ FILE_LIST = %w[ lib/gitlab/encoding_helper.rb lib/gitlab/utils/strong_memoize.rb lib/gitlab/version_info.rb + lib/gitlab/popen.rb ].freeze REMOTE = 'https://gitlab.com/gitlab-org/gitlab-ce'.freeze diff --git a/changelogs/unreleased/fj-vendoring-ruby-dir.yml b/changelogs/unreleased/fj-vendoring-ruby-dir.yml index 2d8afe171..ad0ded604 100644 --- a/changelogs/unreleased/fj-vendoring-ruby-dir.yml +++ b/changelogs/unreleased/fj-vendoring-ruby-dir.yml @@ -1,5 +1,5 @@ --- -title: Vendoring ruby dir to 3b3b705ab5ca690459e40a63e101372e34f2701b +title: Vendoring ruby dir to 290ca339adc952bcd939d1782af95f90d3b88716 merge_request: 753 author: type: other diff --git a/ruby/lib/gitlab/git.rb b/ruby/lib/gitlab/git.rb index 62d02e12f..5dbd174e2 100644 --- a/ruby/lib/gitlab/git.rb +++ b/ruby/lib/gitlab/git.rb @@ -29,6 +29,7 @@ vendor_gitlab_git = '../../vendor/gitlab_git/' require_relative File.join(vendor_gitlab_git, 'lib/gitlab/encoding_helper.rb') require_relative File.join(vendor_gitlab_git, 'lib/gitlab/utils/strong_memoize.rb') require_relative File.join(vendor_gitlab_git, 'lib/gitlab/version_info.rb') +require_relative File.join(vendor_gitlab_git, 'lib/gitlab/popen.rb') require_relative File.join(vendor_gitlab_git, 'lib/gitlab/git.rb') require_relative File.join(vendor_gitlab_git, 'lib/gitlab/git/popen.rb') require_relative File.join(vendor_gitlab_git, 'lib/gitlab/git/ref.rb') @@ -76,12 +77,6 @@ module Gitlab raise NotAvailableInGitalyRuby end end - - class << self - def version - Gitlab::VersionInfo.parse(Gitlab::Git.popen(%W(#{Gitlab.config.git.bin_path} --version)).first) - end - end end end diff --git a/ruby/vendor/gitlab_git/REVISION b/ruby/vendor/gitlab_git/REVISION index ec4fa65ec..39e832ccb 100644 --- a/ruby/vendor/gitlab_git/REVISION +++ b/ruby/vendor/gitlab_git/REVISION @@ -1 +1 @@ -3b3b705ab5ca690459e40a63e101372e34f2701b +290ca339adc952bcd939d1782af95f90d3b88716 diff --git a/ruby/vendor/gitlab_git/lib/gitlab/popen.rb b/ruby/vendor/gitlab_git/lib/gitlab/popen.rb new file mode 100644 index 000000000..b9832a724 --- /dev/null +++ b/ruby/vendor/gitlab_git/lib/gitlab/popen.rb @@ -0,0 +1,48 @@ +require 'fileutils' +require 'open3' + +module Gitlab + module Popen + extend self + + Result = Struct.new(:cmd, :stdout, :stderr, :status, :duration) + + # Returns [stdout + stderr, status] + def popen(cmd, path = nil, vars = {}, &block) + result = popen_with_detail(cmd, path, vars, &block) + + [result.stdout << result.stderr, result.status&.exitstatus] + end + + # Returns Result + def popen_with_detail(cmd, path = nil, vars = {}) + unless cmd.is_a?(Array) + raise "System commands must be given as an array of strings" + end + + path ||= Dir.pwd + vars['PWD'] = path + options = { chdir: path } + + unless File.directory?(path) + FileUtils.mkdir_p(path) + end + + cmd_stdout = '' + cmd_stderr = '' + cmd_status = nil + start = Time.now + + Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr| + yield(stdin) if block_given? + stdin.close + + cmd_stdout = stdout.read + cmd_stderr = stderr.read + cmd_status = wait_thr.value + end + + Result.new(cmd, cmd_stdout, cmd_stderr, cmd_status, Time.now - start) + end + end +end |