From 453321f78613f0acc80d08bd6a9cdf6280f0791d Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 18 Apr 2017 02:58:45 +0000 Subject: vcs.rb: env for command * tool/vcs.rb (VCS::SVN::COMMAND, VCS::GIT::COMMAND): customize command paths by environment variables. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58387 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- tool/vcs.rb | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'tool') diff --git a/tool/vcs.rb b/tool/vcs.rb index 296703c1dc..d54094a409 100644 --- a/tool/vcs.rb +++ b/tool/vcs.rb @@ -193,16 +193,17 @@ class VCS class SVN < self register(".svn") + COMMAND = ENV['SVN'] || 'svn' def self.get_revisions(path, srcdir = nil) if srcdir and local_path?(path) path = File.join(srcdir, path) end if srcdir - info_xml = IO.pread(%W"svn info --xml #{srcdir}") + info_xml = IO.pread(%W"#{COMMAND} info --xml #{srcdir}") info_xml = nil unless info_xml[/(.*)<\/url>/, 1] == path.to_s end - info_xml ||= IO.pread(%W"svn info --xml #{path}") + info_xml ||= IO.pread(%W"#{COMMAND} info --xml #{path}") _, last, _, changed, _ = info_xml.split(/revision="(\d+)"/) modified = info_xml[/([^<>]*)/, 1] branch = info_xml[%r'\^/(?:branches/|tags/)?([^<>]+)', 1] @@ -219,7 +220,7 @@ class VCS end def get_info - @info ||= IO.pread(%W"svn info --xml #{@srcdir}") + @info ||= IO.pread(%W"#{COMMAND} info --xml #{@srcdir}") end def url @@ -252,7 +253,7 @@ class VCS end def branch_list(pat) - IO.popen(%W"svn ls #{branch('')}") do |f| + IO.popen(%W"#{COMMAND} ls #{branch('')}") do |f| f.each do |line| line.chomp! line.chomp!('/') @@ -262,7 +263,7 @@ class VCS end def grep(pat, tag, *files, &block) - cmd = %W"svn cat" + cmd = %W"#{COMMAND} cat" files.map! {|n| File.join(tag, n)} if tag set = block.binding.eval("proc {|match| $~ = match}") IO.popen([cmd, *files]) do |f| @@ -282,7 +283,7 @@ class VCS subdir = nil if subdir.empty? FileUtils.mkdir_p(svndir = dir+"/.svn") FileUtils.ln_s(Dir.glob(rootdir+"/.svn/*"), svndir) - system("svn", "-q", "revert", "-R", subdir || ".", :chdir => dir) or return false + system(COMMAND, "-q", "revert", "-R", subdir || ".", :chdir => dir) or return false FileUtils.rm_rf(svndir) unless keep_temp if subdir tmpdir = Dir.mktmpdir("tmp-co.", "#{dir}/#{subdir}") @@ -297,7 +298,7 @@ class VCS return true end end - IO.popen(%W"svn export -r #{revision} #{url} #{dir}") do |pipe| + IO.popen(%W"#{COMMAND} export -r #{revision} #{url} #{dir}") do |pipe| pipe.each {|line| /^A/ =~ line or yield line} end $?.success? @@ -310,7 +311,7 @@ class VCS def export_changelog(url, from, to, path) range = [to, (from+1 if from)].compact.join(':') IO.popen({'TZ' => 'JST-9', 'LANG' => 'C', 'LC_ALL' => 'C'}, - %W"svn log -r#{range} #{url}") do |r| + %W"#{COMMAND} log -r#{range} #{url}") do |r| open(path, 'w') do |w| IO.copy_stream(r, w) end @@ -320,6 +321,7 @@ class VCS class GIT < self register(".git") {|path, dir| File.exist?(File.join(path, dir))} + COMMAND = ENV["GIT"] || 'git' def self.cmd_args(cmds, srcdir = nil) if srcdir and local_path?(srcdir) @@ -338,7 +340,7 @@ class VCS end def self.get_revisions(path, srcdir = nil) - gitcmd = %W[git] + gitcmd = [COMMAND] logcmd = gitcmd + %W[log -n1 --date=iso] logcmd << "--grep=^ *git-svn-id: .*@[0-9][0-9]*" idpat = /git-svn-id: .*?@(\d+) \S+\Z/ @@ -389,12 +391,12 @@ class VCS end def stable - cmd = %W"git for-each-ref --format=\%(refname:short) refs/heads/ruby_[0-9]*" + cmd = %W"#{COMMAND} for-each-ref --format=\%(refname:short) refs/heads/ruby_[0-9]*" branch(cmd_read(cmd)[/.*^(ruby_\d+_\d+)$/m, 1]) end def branch_list(pat) - cmd = %W"git for-each-ref --format=\%(refname:short) refs/heads/#{pat}" + cmd = %W"#{COMMAND} for-each-ref --format=\%(refname:short) refs/heads/#{pat}" cmd_pipe(cmd) {|f| f.each {|line| line.chomp! @@ -404,7 +406,7 @@ class VCS end def grep(pat, tag, *files, &block) - cmd = %W[git grep -h --perl-regexp #{tag} --] + cmd = %W[#{COMMAND} grep -h --perl-regexp #{tag} --] set = block.binding.eval("proc {|match| $~ = match}") cmd_pipe(cmd+files) do |f| f.grep(pat) do |s| @@ -415,7 +417,7 @@ class VCS end def export(revision, url, dir, keep_temp = false) - ret = system("git", "clone", "-s", (@srcdir || '.').to_s, "-b", url, dir) + ret = system(COMMAND, "clone", "-s", (@srcdir || '.').to_s, "-b", url, dir) FileUtils.rm_rf("#{dir}/.git") if ret and !keep_temp ret end @@ -428,12 +430,12 @@ class VCS range = [from, to].map do |rev| rev or next rev = cmd_read({'LANG' => 'C', 'LC_ALL' => 'C'}, - %W"git log -n1 --format=format:%H" << + %W"#{COMMAND} log -n1 --format=format:%H" << "--grep=^ *git-svn-id: .*@#{rev} ") rev unless rev.empty? end.join('..') cmd_pipe({'TZ' => 'JST-9', 'LANG' => 'C', 'LC_ALL' => 'C'}, - %W"git log --date=iso-local --topo-order #{range}") do |r| + %W"#{COMMAND} log --date=iso-local --topo-order #{range}") do |r| open(path, 'w') do |w| sep = "-"*72 w.puts sep -- cgit v1.2.3