Skip to content

Commit ffd2c5a

Browse files
committed
vcs.rb: Pass environment variables at IO.popen
The required BASERUBY is new enough already.
1 parent 34c94b3 commit ffd2c5a

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

tool/lib/vcs.rb

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,20 @@ def cmd_args(cmds, srcdir = nil)
283283
opts[:chdir] ||= srcdir
284284
end
285285
VCS.dump(cmds, "cmds: ") if debug? and !$DEBUG
286+
if cmds.first.kind_of?(Hash)
287+
cmds[0] = env_without_gitconfig.merge(cmds.first)
288+
else
289+
cmds.unshift(env_without_gitconfig)
290+
end
286291
cmds
287292
end
288293

289294
def cmd_pipe_at(srcdir, cmds, &block)
290-
without_gitconfig { IO.popen(*cmd_args(cmds, srcdir), &block) }
295+
IO.popen(*cmd_args(cmds, srcdir), &block)
291296
end
292297

293298
def cmd_read_at(srcdir, cmds)
294-
result = without_gitconfig { IO.pread(*cmd_args(cmds, srcdir)) }
299+
result = IO.pread(*cmd_args(cmds, srcdir))
295300
VCS.dump(result, "result: ") if debug?
296301
result
297302
end
@@ -377,27 +382,35 @@ def self.short_revision(rev)
377382
rev[0, 10]
378383
end
379384

380-
def without_gitconfig
381-
envs = (%w'HOME XDG_CONFIG_HOME' + ENV.keys.grep(/\AGIT_/)).each_with_object({}) do |v, h|
382-
h[v] = ENV.delete(v)
385+
def revision_handler(rev)
386+
case rev
387+
when Integer
388+
SVN
389+
else
390+
super
383391
end
384-
ENV['GIT_CONFIG_SYSTEM'] = NullDevice
385-
ENV['GIT_CONFIG_GLOBAL'] = global_config
386-
yield
387-
ensure
388-
ENV.update(envs)
392+
end
393+
394+
def env_without_gitconfig
395+
@env_without_gitconfig ||=
396+
begin
397+
envs = (%w'HOME XDG_CONFIG_HOME' + ENV.keys.grep(/\AGIT_/)).to_h {|v| [v, nil]}
398+
envs['GIT_CONFIG_SYSTEM'] = NullDevice
399+
envs['GIT_CONFIG_GLOBAL'] = global_config.freeze
400+
envs.freeze
401+
end
389402
end
390403

391404
def global_config
392405
return NullDevice if SAFE_DIRECTORIES.empty?
393406
unless @gitconfig
394407
@gitconfig = Tempfile.new(%w"vcs_ .gitconfig")
395408
@gitconfig.close
396-
ENV['GIT_CONFIG_GLOBAL'] = @gitconfig.path
409+
env = {'GIT_CONFIG_GLOBAL' => @gitconfig.path}
397410
SAFE_DIRECTORIES.each do |dir|
398-
system(*%W[#{COMMAND} config --global --add safe.directory #{dir}])
411+
system(env, *%W[#{COMMAND} config --global --add safe.directory #{dir}])
399412
end
400-
VCS.dump(`#{COMMAND} config --global --get-all safe.directory`, "safe.directory: ") if debug?
413+
VCS.dump(IO.popen(env, "#{COMMAND} config --global --get-all safe.directory", &:read), "safe.directory: ") if debug?
401414
end
402415
@gitconfig.path
403416
end

0 commit comments

Comments
 (0)