1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

vcs.rb: abstract

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-12-15 01:02:52 +00:00
parent 81ac745846
commit fff1128281
2 changed files with 112 additions and 19 deletions

View file

@ -134,6 +134,54 @@ class VCS
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
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