[前][次][番号順一覧][スレッド一覧]

ruby-changes:46274

From: nobu <ko1@a...>
Date: Tue, 18 Apr 2017 11:58:50 +0900 (JST)
Subject: [ruby-changes:46274] nobu:r58387 (trunk): vcs.rb: env for command

nobu	2017-04-18 11:58:45 +0900 (Tue, 18 Apr 2017)

  New Revision: 58387

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58387

  Log:
    vcs.rb: env for command
    
    * tool/vcs.rb (VCS::SVN::COMMAND, VCS::GIT::COMMAND): customize
      command paths by environment variables.

  Modified files:
    trunk/tool/vcs.rb
Index: tool/vcs.rb
===================================================================
--- tool/vcs.rb	(revision 58386)
+++ tool/vcs.rb	(revision 58387)
@@ -193,16 +193,17 @@ class VCS https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L193
 
   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>(.*)<\/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[/<date>([^<>]*)/, 1]
       branch = info_xml[%r'<relative-url>\^/(?:branches/|tags/)?([^<>]+)', 1]
@@ -219,7 +220,7 @@ class VCS https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L220
     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 https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L253
     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 https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L263
     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 https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L283
           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 https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L298
           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 https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L311
     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 https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L321
 
   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 https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L340
     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 https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L391
     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 https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L406
     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 https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L417
     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 https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L430
       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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]