merger.rb: Drop SVN support
This commit is contained in:
parent
7873275326
commit
7a860bacee
129
tool/merger.rb
129
tool/merger.rb
@ -2,9 +2,8 @@
|
|||||||
# -*- ruby -*-
|
# -*- ruby -*-
|
||||||
exec "${RUBY-ruby}" "-x" "$0" "$@" && [ ] if false
|
exec "${RUBY-ruby}" "-x" "$0" "$@" && [ ] if false
|
||||||
#!ruby
|
#!ruby
|
||||||
# This needs ruby 2.0, Subversion and Git.
|
# This needs ruby 2.0 and Git.
|
||||||
# As a Ruby committer, run this in an SVN repository
|
# As a Ruby committer, run this in a git repository to commit a change.
|
||||||
# to commit a change.
|
|
||||||
|
|
||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
require 'net/http'
|
require 'net/http'
|
||||||
@ -15,13 +14,7 @@ ENV['LC_ALL'] = 'C'
|
|||||||
ORIGIN = 'git@git.ruby-lang.org:ruby.git'
|
ORIGIN = 'git@git.ruby-lang.org:ruby.git'
|
||||||
GITHUB = 'git@github.com:ruby/ruby.git'
|
GITHUB = 'git@github.com:ruby/ruby.git'
|
||||||
|
|
||||||
module Merger
|
class << Merger = Object.new
|
||||||
REPOS = 'svn+ssh://svn@ci.ruby-lang.org/ruby/'
|
|
||||||
end
|
|
||||||
|
|
||||||
class << Merger
|
|
||||||
include Merger
|
|
||||||
|
|
||||||
def help
|
def help
|
||||||
puts <<-HELP
|
puts <<-HELP
|
||||||
\e[1msimple backport\e[0m
|
\e[1msimple backport\e[0m
|
||||||
@ -69,11 +62,7 @@ class << Merger
|
|||||||
def version_up(teeny: false)
|
def version_up(teeny: false)
|
||||||
now = Time.now
|
now = Time.now
|
||||||
now = now.localtime(9*60*60) # server is Japan Standard Time +09:00
|
now = now.localtime(9*60*60) # server is Japan Standard Time +09:00
|
||||||
if svn_mode?
|
system('git', 'checkout', 'HEAD', 'version.h')
|
||||||
system('svn', 'revert', 'version.h')
|
|
||||||
else
|
|
||||||
system('git', 'checkout', 'HEAD', 'version.h')
|
|
||||||
end
|
|
||||||
v, pl = version
|
v, pl = version
|
||||||
|
|
||||||
if teeny
|
if teeny
|
||||||
@ -129,31 +118,10 @@ class << Merger
|
|||||||
end
|
end
|
||||||
tagname = "v#{v.join('_')}#{("_#{pl}" if v[0] < "2" || (v[0] == "2" && v[1] < "1") || /^(?:preview|rc)/ =~ pl)}"
|
tagname = "v#{v.join('_')}#{("_#{pl}" if v[0] < "2" || (v[0] == "2" && v[1] < "1") || /^(?:preview|rc)/ =~ pl)}"
|
||||||
|
|
||||||
if svn_mode?
|
unless execute('git', 'tag', tagname)
|
||||||
if relname
|
abort 'specfied tag already exists. check tag name and remove it if you want to force re-tagging'
|
||||||
branch_url = `svn info`[/URL: (.*)/, 1]
|
|
||||||
else
|
|
||||||
branch_url = "#{REPOS}branches/ruby_"
|
|
||||||
if v[0] < '2' || (v[0] == '2' && v[1] < '1')
|
|
||||||
abort 'patchlevel must be greater than 0 for patch release' if pl == '0'
|
|
||||||
branch_url << v.join('_')
|
|
||||||
else
|
|
||||||
abort 'teeny must be greater than 0 for patch release' if v[2] == '0'
|
|
||||||
branch_url << v.join('_').sub(/_\d+\z/, '')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
tag_url = "#{REPOS}tags/#{tagname}"
|
|
||||||
system('svn', 'info', tag_url, out: IO::NULL, err: IO::NULL)
|
|
||||||
if $?.success?
|
|
||||||
abort 'specfied tag already exists. check tag name and remove it if you want to force re-tagging'
|
|
||||||
end
|
|
||||||
execute('svn', 'cp', '-m', "add tag #{tagname}", branch_url, tag_url, interactive: true)
|
|
||||||
else
|
|
||||||
unless execute('git', 'tag', tagname)
|
|
||||||
abort 'specfied tag already exists. check tag name and remove it if you want to force re-tagging'
|
|
||||||
end
|
|
||||||
execute('git', 'push', ORIGIN, tagname, interactive: true)
|
|
||||||
end
|
end
|
||||||
|
execute('git', 'push', ORIGIN, tagname, interactive: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_tag(relname)
|
def remove_tag(relname)
|
||||||
@ -173,64 +141,33 @@ class << Merger
|
|||||||
tagname = relname
|
tagname = relname
|
||||||
end
|
end
|
||||||
|
|
||||||
if svn_mode?
|
execute('git', 'tag', '-d', tagname)
|
||||||
tag_url = "#{REPOS}tags/#{tagname}"
|
execute('git', 'push', ORIGIN, ":#{tagname}", interactive: true)
|
||||||
execute('svn', 'rm', '-m', "remove tag #{tagname}", tag_url, interactive: true)
|
execute('git', 'push', GITHUB, ":#{tagname}", interactive: true)
|
||||||
else
|
|
||||||
execute('git', 'tag', '-d', tagname)
|
|
||||||
execute('git', 'push', ORIGIN, ":#{tagname}", interactive: true)
|
|
||||||
execute('git', 'push', GITHUB, ":#{tagname}", interactive: true)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_revision_h
|
def update_revision_h
|
||||||
if svn_mode?
|
|
||||||
execute('svn', 'up')
|
|
||||||
end
|
|
||||||
execute('ruby tool/file2lastrev.rb --revision.h . > revision.tmp')
|
execute('ruby tool/file2lastrev.rb --revision.h . > revision.tmp')
|
||||||
execute('tool/ifchange', '--timestamp=.revision.time', 'revision.h', 'revision.tmp')
|
execute('tool/ifchange', '--timestamp=.revision.time', 'revision.h', 'revision.tmp')
|
||||||
execute('rm', '-f', 'revision.tmp')
|
execute('rm', '-f', 'revision.tmp')
|
||||||
end
|
end
|
||||||
|
|
||||||
def stat
|
def stat
|
||||||
if svn_mode?
|
`git status --short`
|
||||||
`svn stat`
|
|
||||||
else
|
|
||||||
`git status --short`
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def diff(file = nil)
|
def diff(file = nil)
|
||||||
if svn_mode?
|
command = %w[git diff --color HEAD]
|
||||||
command = %w[svn diff --diff-cmd=diff -x -upw]
|
|
||||||
else
|
|
||||||
command = %w[git diff --color HEAD]
|
|
||||||
end
|
|
||||||
IO.popen(command + [file].compact, &:read)
|
IO.popen(command + [file].compact, &:read)
|
||||||
end
|
end
|
||||||
|
|
||||||
def commit(file)
|
def commit(file)
|
||||||
if svn_mode?
|
current_branch = IO.popen(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], &:read).strip
|
||||||
begin
|
execute('git', 'add', '.') && execute('git', 'commit', '-F', file)
|
||||||
execute('svn', 'ci', '-F', file)
|
|
||||||
execute('svn', 'update') # svn ci doesn't update revision info on working copy
|
|
||||||
ensure
|
|
||||||
execute('rm', '-f', 'subversion.commitlog')
|
|
||||||
end
|
|
||||||
else
|
|
||||||
current_branch = IO.popen(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], &:read).strip
|
|
||||||
execute('git', 'add', '.') &&
|
|
||||||
execute('git', 'commit', '-F', file)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def svn_mode?
|
|
||||||
return @svn_mode if defined?(@svn_mode)
|
|
||||||
@svn_mode = system("svn info", %i(out err) => IO::NULL)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Prints the version of Ruby found in version.h
|
# Prints the version of Ruby found in version.h
|
||||||
def version
|
def version
|
||||||
v = p = nil
|
v = p = nil
|
||||||
@ -303,8 +240,6 @@ else
|
|||||||
revs.each do |rev|
|
revs.each do |rev|
|
||||||
git_rev = nil
|
git_rev = nil
|
||||||
case rev
|
case rev
|
||||||
when /\A\d{1,6}\z/
|
|
||||||
svn_rev = rev
|
|
||||||
when /\A\h{7,40}\z/
|
when /\A\h{7,40}\z/
|
||||||
git_rev = rev
|
git_rev = rev
|
||||||
when nil then
|
when nil then
|
||||||
@ -315,30 +250,20 @@ else
|
|||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
# Merge revision from Git patch or SVN
|
# Merge revision from Git patch
|
||||||
if git_rev
|
git_uri = "https://git.ruby-lang.org/ruby.git/patch/?id=#{git_rev}"
|
||||||
git_uri = "https://git.ruby-lang.org/ruby.git/patch/?id=#{git_rev}"
|
resp = Net::HTTP.get_response(URI(git_uri))
|
||||||
resp = Net::HTTP.get_response(URI(git_uri))
|
if resp.code != '200'
|
||||||
if resp.code != '200'
|
abort "'#{git_uri}' returned status '#{resp.code}':\n#{resp.body}"
|
||||||
abort "'#{git_uri}' returned status '#{resp.code}':\n#{resp.body}"
|
|
||||||
end
|
|
||||||
patch = resp.body.sub(/^diff --git a\/version\.h b\/version\.h\nindex .*\n--- a\/version\.h\n\+\+\+ b\/version\.h\n@@ .* @@\n(?:[-\+ ].*\n|\n)+/, '')
|
|
||||||
|
|
||||||
message = "#{(patch[/^Subject: (.*)\n---\n /m, 1] || "Message not found for revision: #{git_rev}\n")}"
|
|
||||||
message.gsub!(/\G(.*)\n( .*)/, "\\1\\2")
|
|
||||||
message = "\n\n#{message}"
|
|
||||||
|
|
||||||
puts '+ git apply'
|
|
||||||
IO.popen(['git', 'apply', '--3way'], 'wb') { |f| f.write(patch) }
|
|
||||||
else
|
|
||||||
default_merge_branch = (%r{^URL: .*/branches/ruby_1_8_} =~ `svn info` ? 'branches/ruby_1_8' : 'trunk')
|
|
||||||
svn_src = "#{Merger::REPOS}#{ARGV[1] || default_merge_branch}"
|
|
||||||
message = IO.popen(['svn', 'log', '-c', svn_rev, svn_src], &:read)
|
|
||||||
|
|
||||||
cmd = ['svn', 'merge', '--accept=postpone', '-c', svn_rev, svn_src]
|
|
||||||
puts "+ #{cmd.join(' ')}"
|
|
||||||
system(*cmd)
|
|
||||||
end
|
end
|
||||||
|
patch = resp.body.sub(/^diff --git a\/version\.h b\/version\.h\nindex .*\n--- a\/version\.h\n\+\+\+ b\/version\.h\n@@ .* @@\n(?:[-\+ ].*\n|\n)+/, '')
|
||||||
|
|
||||||
|
message = "#{(patch[/^Subject: (.*)\n---\n /m, 1] || "Message not found for revision: #{git_rev}\n")}"
|
||||||
|
message.gsub!(/\G(.*)\n( .*)/, "\\1\\2")
|
||||||
|
message = "\n\n#{message}"
|
||||||
|
|
||||||
|
puts '+ git apply'
|
||||||
|
IO.popen(['git', 'apply', '--3way'], 'wb') { |f| f.write(patch) }
|
||||||
|
|
||||||
commit_message << message.sub(/\A-+\nr.*/, '').sub(/\n-+\n\z/, '').gsub(/^./, "\t\\&")
|
commit_message << message.sub(/\A-+\nr.*/, '').sub(/\n-+\n\z/, '').gsub(/^./, "\t\\&")
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user