ruby-changes:44576
From: nobu <ko1@a...>
Date: Mon, 7 Nov 2016 09:04:26 +0900 (JST)
Subject: [ruby-changes:44576] nobu:r56649 (trunk): vcs.rb: popen with env
nobu 2016-11-07 09:04:20 +0900 (Mon, 07 Nov 2016) New Revision: 56649 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56649 Log: vcs.rb: popen with env * tool/vcs.rb (IO.popen): support passing environment variables. Modified files: trunk/tool/vcs.rb Index: tool/vcs.rb =================================================================== --- tool/vcs.rb (revision 56648) +++ tool/vcs.rb (revision 56649) @@ -24,6 +24,10 @@ if RUBY_VERSION < "2.0" https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L24 if defined?(fork) def self.popen(command, *rest, &block) + if command.kind_of?(Hash) + env = command + command = rest.shift + end opts = rest.last if opts.kind_of?(Hash) dir = opts.delete(:chdir) @@ -36,6 +40,7 @@ if RUBY_VERSION < "2.0" https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L40 yield(f) else Dir.chdir(dir) if dir + ENV.replace(env) if env exec(*command) end end @@ -43,6 +48,7 @@ if RUBY_VERSION < "2.0" https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L48 f = @orig_popen.call("-", *rest) unless f Dir.chdir(dir) if dir + ENV.replace(env) if env exec(*command) end f @@ -51,6 +57,11 @@ if RUBY_VERSION < "2.0" https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L57 else require 'shellwords' def self.popen(command, *rest, &block) + if command.kind_of?(Hash) + env = command + oldenv = ENV.to_hash + command = rest.shift + end opts = rest.last if opts.kind_of?(Hash) dir = opts.delete(:chdir) @@ -59,7 +70,9 @@ if RUBY_VERSION < "2.0" https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L70 command = command.shelljoin if Array === command Dir.chdir(dir || ".") do + ENV.replace(env) if env @orig_popen.call(command, *rest, &block) + ENV.replace(oldenv) if oldenv end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/