diff options
author | k0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-21 11:49:11 +0000 |
---|---|---|
committer | k0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-21 11:49:11 +0000 |
commit | de5378233b2ff5434f024ac66285e699794a321d (patch) | |
tree | ce559488396265f641e12de83be62b7e968cb868 /tool/merger.rb | |
parent | 47676e969e9ecb204e704f0221816167afa79362 (diff) |
tool/merger.rb: Support fetching patch from cgit
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool/merger.rb')
-rwxr-xr-x | tool/merger.rb | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/tool/merger.rb b/tool/merger.rb index ee716bac09..33d663c3cc 100755 --- a/tool/merger.rb +++ b/tool/merger.rb @@ -8,6 +8,8 @@ exec "${RUBY-ruby}" "-x" "$0" "$@" && [ ] if false require 'fileutils' require 'tempfile' +require 'net/http' +require 'uri' $repos = 'svn+ssh://svn@ci.ruby-lang.org/ruby/' ENV['LC_ALL'] = 'C' @@ -229,14 +231,17 @@ else end q = $repos + (ARGV[1] || default_merge_branch) - revstr = ARGV[0].delete('^, :\-0-9') + revstr = ARGV[0].delete('^, :\-0-9a-fA-F') revs = revstr.split(/[,\s]+/) - log_svn = '' + commit_message = '' revs.each do |rev| + git_rev = nil case rev - when /\A\d+\z/ - r = ['-c', rev] + when /\A\d{1,6}\z/ + svn_rev = rev + when /\A\h{7,40}\z/ + git_rev = rev when nil then puts "#$0 revision" exit @@ -245,14 +250,27 @@ else exit end - log_svn << IO.popen(%w'svn log ' + r + [q]) { |f| - f.read - }.sub(/\A-+\nr.*/, '').sub(/\n-+\n\z/, '').gsub(/^./, "\t\\&") + # Merge revision from Git patch or SVN + if git_rev + git_uri = "https://git.ruby-lang.org/ruby.git/patch/?id=#{git_rev}" + resp = Net::HTTP.get_response(URI(git_uri)) + if resp.code != '200' + abort "'#{git_uri}' returned status '#{resp.code}':\n#{resp.body}" + end + patch = resp.body + + message = "\n\n#{(patch.match(/^Subject: (.*)\n\ndiff --git/m)[1] || "Message not found for revision: #{git_rev}\n")}" + puts "+ git apply" + IO.popen(['git', 'apply'], 'w') { |f| f.write(patch) } + else + message = IO.popen(['svn', 'log', '-r', svn_rev, q], &:read) - a = %w'svn merge --accept=postpone' + r + [q] - STDERR.puts a.join(' ') + cmd = ['svn', 'merge', '--accept=postpone', '-r', svn_rev, q] + puts "+ #{cmd.join(' ')}" + system(*cmd) + end - system(*a) + commit_message << message.sub(/\A-+\nr.*/, '').sub(/\n-+\n\z/, '').gsub(/^./, "\t\\&") end if `svn diff --diff-cmd=diff -x -upw`.empty? @@ -263,7 +281,7 @@ else version_up f = Tempfile.new 'merger.rb' f.printf "merge revision(s) %s:%s", revstr, tickets - f.write log_svn + f.write commit_message f.flush f.close |