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

ruby-changes:36759

From: nobu <ko1@a...>
Date: Mon, 15 Dec 2014 10:02:59 +0900 (JST)
Subject: [ruby-changes:36759] nobu:r48840 (trunk): vcs.rb: abstract

nobu	2014-12-15 10:02:52 +0900 (Mon, 15 Dec 2014)

  New Revision: 48840

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

  Log:
    vcs.rb: abstract
    
    * tool/vcs.rb: abstract VCS interfaces from make-snapshot.

  Modified files:
    trunk/tool/make-snapshot
    trunk/tool/vcs.rb
Index: tool/vcs.rb
===================================================================
--- tool/vcs.rb	(revision 48839)
+++ tool/vcs.rb	(revision 48840)
@@ -134,6 +134,54 @@ class VCS https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L134
       modified = info_xml[/<date>([^<>]*)/, 1]
       [last, changed, modified]
     end
+
+    def url
+      unless defined?(@url)
+        url = IO.pread(%W"svn info --xml #{@srcdir}")[/<url>(.*)<\/url>/, 1]
+        @url = URI.parse(url+"/") if url
+      end
+      @url
+    end
+
+    def branch(name)
+      url + "branches/#{name}"
+    end
+
+    def tag(name)
+      url + "tags/#{name}"
+    end
+
+    def trunk
+      url + "trunk"
+    end
+
+    def branch_list(pat)
+      IO.popen(%W"svn ls #{branch('')}") do |f|
+        f.each do |line|
+          line.chomp!('/')
+          yield(line) if File.fnmatch?(pat, line)
+        end
+      end
+    end
+
+    def grep(pat, tag, *files, &block)
+      cmd = %W"svn cat"
+      files.map! {|n| File.join(tag, n)} if tag
+      set = block.binding.eval("proc {|match| $~ = match}")
+      IO.popen([cmd, *files]) do |f|
+        f.grep(pat) do |s|
+          set[$~]
+          yield s
+        end
+      end
+    end
+
+    def export(revision, url, dir)
+      IO.popen(%W"svn export -r #{revision} #{url} #{dir}") do |pipe|
+        pipe.each {|line| /^A/ =~ line or yield line}
+      end
+      $?.success?
+    end
   end
 
   class GIT < self
@@ -154,5 +202,45 @@ class VCS https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L202
       modified = log[/^Date:\s+(.*)/, 1]
       [last, changed, modified]
     end
+
+    def branch(name)
+      name
+    end
+
+    alias tag branch
+
+    def trunk
+      branch("trunk")
+    end
+
+    def stable
+      cmd = %W"git for-each-ref --format=\%(refname:short) refs/heads/ruby_[0-9]*"
+      cmd[1, 0] = ["-C", @srcdir] if @srcdir
+      branch(IO.pread(cmd)[/.*^(ruby_\d+_\d+)$/m, 1])
+    end
+
+    def branch_list(pat, &block)
+      cmd = %W"git for-each-ref --format=\%(refname:short) refs/heads/#{pat}"
+      cmd[1, 0] = ["-C", @srcdir] if @srcdir
+      IO.popen(cmd, &block)
+    end
+
+    def grep(pat, tag, *files, &block)
+      cmd = %W[git grep -h --perl-regexp #{tag} --]
+      cmd[1, 0] = ["-C", @srcdir] if @srcdir
+      set = block.binding.eval("proc {|match| $~ = match}")
+      IO.popen([cmd, *files]) do |f|
+        f.grep(pat) do |s|
+          set[$~]
+          yield s
+        end
+      end
+    end
+
+    def export(revision, url, dir)
+      ret = system("git", "clone", "-s", (@srcdir || '.'), "-b", url, dir)
+      FileUtils.rm_rf("#{dir}/.git") if ret
+      ret
+    end
   end
 end
Index: tool/make-snapshot
===================================================================
--- tool/make-snapshot	(revision 48839)
+++ tool/make-snapshot	(revision 48840)
@@ -5,6 +5,7 @@ require 'digest/md5' https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L5
 require 'digest/sha2'
 require 'fileutils'
 require 'tmpdir'
+require File.expand_path("../vcs", __FILE__)
 STDOUT.sync = true
 
 $exported = nil if ($exported ||= nil) == ""
@@ -121,50 +122,53 @@ unless tmp = $exported https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L122
     FileUtils.rm_rf(tmp)
   } unless $keep_temp
 end
-Dir.chdir tmp
 
-def package(rev, destdir)
+def package(vcs, rev, destdir, tmp = nil)
   patchlevel = false
   prerelease = false
   if revision = rev[/@(\d+)\z/, 1]
     rev = $`
   end
   case rev
-  when /\Atrunk\z/, /\Abranches\//, /\Atags\//
-    url = SVNURL + rev
+  when /\Atrunk\z/
+    url = vcs.trunk
+  when /\Abranches\//
+    url = vcs.branch($')
+  when /\Atags\//
+    url = vcs.tag($')
   when /\Astable\z/
-    url = SVNURL + "branches/"
-    url = url + `svn ls #{url}`[/.*^(ruby_\d+_\d+)\//m, 1]
+    vcs.branch_list(/ruby_[0-9]*/) {|n| url = /\Aruby_\d+_\d+\z/ =~ n}
+    url &&= vcs.branch(url)
   when /\A(.*)\.(.*)\.(.*)-(preview|rc)(\d+)/
     prerelease = true
     tag = "#{$4}#{$5}"
-    url = SVNURL + "tags/v#{$1}_#{$2}_#{$3}_#{$4}#{$5}"
+    url = vcs.tag("v#{$1}_#{$2}_#{$3}_#{$4}#{$5}")
   when /\A(.*)\.(.*)\.(.*)-p(\d+)/
     patchlevel = true
     tag = "p#{$4}"
-    url = SVNURL + "tags/v#{$1}_#{$2}_#{$3}_#{$4}"
+    url = vcs.tag("v#{$1}_#{$2}_#{$3}_#{$4}")
   when /\A(\d+)\.(\d+)(?:\.(\d+))?\z/
     if $3 && ($1 > "2" || $1 == "2" && $2 >= "1")
       patchlevel = true
       tag = ""
-      url = SVNURL + "tags/v#{$1}_#{$2}_#{$3}"
+      url = vcs.tag("v#{$1}_#{$2}_#{$3}")
     else
-      url = SVNURL + "branches/ruby_#{rev.tr('.', '_')}"
+      url = vcs.branch("ruby_#{rev.tr('.', '_')}")
     end
   else
     warn "#{$0}: unknown version - #{rev}"
     return
   end
-  revision ||= `svn info #{url} 2>&1`[/Last Changed Rev: (\d+)/, 1]
+  revision ||= vcs.get_revisions(url)[1]
   version = nil
   unless revision
-    url = SVNURL + "trunk"
-    version = `svn cat #{url + "version.h"}`[RUBY_VERSION_PATTERN, 1]
+    url = vcs.trunk
+    vcs.grep(RUBY_VERSION_PATTERN, url, "version.h") {version = $1}
     unless rev == version
       warn "#{$0}: #{rev} not found"
       return
     end
-    revision = `svn info #{url}`[/Last Changed Rev: (\d+)/, 1]
+    revision = vcs.get_revisions(url)[1]
   end
   v = nil
   if $exported
@@ -174,15 +178,14 @@ def package(rev, destdir) https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L178
   else
     v = "ruby"
     puts "Exporting #{rev}@#{revision}"
-    IO.popen(%W"svn export -r #{revision} #{url} #{v}") do |pipe|
-      pipe.each {|line| /^A/ =~ line or print line}
-    end
-    unless $?.success?
+    unless vcs.export(revision, url, tmp ? File.join(tmp, v) : v) {|line| print line}
       warn("Export failed")
       return
     end
   end
 
+  Dir.chdir(tmp) if tmp
+
   if !File.directory?(v)
     v = Dir.glob("ruby-*").select(&File.method(:directory?))
     v.size == 1 or abort "not exported"
@@ -338,8 +341,10 @@ ensure https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L341
   FileUtils.rm_rf(v) if v and !$exported and !$keep_temp
 end
 
+vcs = VCS::SVN.new(SVNURL)
+
 success = true
-revisions.collect {|rev| package(rev, destdir)}.flatten.each do |name|
+revisions.collect {|rev| package(vcs, rev, destdir, tmp)}.flatten.each do |name|
   if !name
     success = false
     next

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

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