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

ruby-changes:37233

From: nobu <ko1@a...>
Date: Sun, 18 Jan 2015 11:23:05 +0900 (JST)
Subject: [ruby-changes:37233] nobu:r49314 (trunk): vcs.rb: export without remote svn

nobu	2015-01-18 11:22:50 +0900 (Sun, 18 Jan 2015)

  New Revision: 49314

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

  Log:
    vcs.rb: export without remote svn
    
    * tool/vcs.rb (VCS::SVN#export): export without access to the
      remote server.

  Modified files:
    trunk/tool/vcs.rb
Index: tool/vcs.rb
===================================================================
--- tool/vcs.rb	(revision 49313)
+++ tool/vcs.rb	(revision 49314)
@@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L1
 # vcs
+require 'fileutils'
 
 ENV.delete('PWD')
 
@@ -132,21 +133,33 @@ class VCS https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L133
       if srcdir and (String === path or path.respond_to?(:to_path))
         path = File.join(srcdir, path)
       end
-      info_xml = IO.pread(%W"svn info --xml #{path}")
+      if srcdir
+        info_xml = IO.pread(%W"svn 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}")
       _, last, _, changed, _ = info_xml.split(/revision="(\d+)"/)
       modified = info_xml[/<date>([^<>]*)/, 1]
       branch = info_xml[%r'<relative-url>\^/(?:branches/|tags/)?([^<>]+)', 1]
       [last, changed, modified, branch]
     end
 
+    def get_info
+      @info ||= IO.pread(%W"svn info --xml #{@srcdir}")
+    end
+
     def url
-      unless defined?(@url)
-        url = IO.pread(%W"svn info --xml #{@srcdir}")[/<root>(.*)<\/root>/, 1]
+      unless @url
+        url = get_info[/<root>(.*)<\/root>/, 1]
         @url = URI.parse(url+"/") if url
       end
       @url
     end
 
+    def wcroot
+      @wcroot ||= get_info[/<wcroot-abspath>(.*)<\/wcroot-abspath>/, 1]
+    end
+
     def branch(name)
       url + "branches/#{name}"
     end
@@ -182,6 +195,29 @@ class VCS https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L195
     end
 
     def export(revision, url, dir)
+      if @srcdir
+        srcdir = File.realpath(@srcdir)
+        rootdir = wcroot+"/"
+        if srcdir.start_with?(rootdir)
+          subdir = srcdir[rootdir.size..-1]
+          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
+          FileUtils.rm_rf(svndir)
+          if subdir
+            tmpdir = Dir.mktmpdir("tmp-co.", "#{dir}/#{subdir}")
+            File.rename(tmpdir, tmpdir = "#{dir}/#{File.basename(tmpdir)}")
+            FileUtils.mv(Dir.glob("#{dir}/#{subdir}/{.[^.]*,..?*,*}"), tmpdir)
+            begin
+              Dir.rmdir("#{dir}/#{subdir}")
+            end until (subdir = File.dirname(subdir)) == '.'
+            FileUtils.mv(Dir.glob("#{tmpdir}/#{subdir}/{.[^.]*,..?*,*}"), dir)
+            Dir.rmdir(tmpdir)
+          end
+          return true
+        end
+      end
       IO.popen(%W"svn export -r #{revision} #{url} #{dir}") do |pipe|
         pipe.each {|line| /^A/ =~ line or yield line}
       end

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

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