2013-02-22 23:51:12 -05:00
|
|
|
#!/bin/sh
|
|
|
|
# -*- ruby -*-
|
|
|
|
exec "${RUBY-ruby}" "-x" "$0" "$@" && [ ] if false
|
|
|
|
#!ruby
|
2010-08-19 06:16:35 -04:00
|
|
|
# This needs ruby 1.9 and subversion.
|
|
|
|
# run this in a repository to commit.
|
|
|
|
|
|
|
|
require 'date'
|
|
|
|
require 'tempfile'
|
|
|
|
|
|
|
|
$repos = 'svn+ssh://svn@ci.ruby-lang.org/ruby/'
|
|
|
|
ENV['LC_ALL'] = 'C'
|
|
|
|
|
|
|
|
def help
|
|
|
|
puts <<-end
|
|
|
|
simple backport
|
|
|
|
ruby #$0 1234
|
|
|
|
|
|
|
|
range backport
|
|
|
|
ruby #$0 1234:5678
|
|
|
|
|
|
|
|
backport from other branch
|
|
|
|
ruby #$0 17502 mvm
|
|
|
|
|
|
|
|
revision increment
|
|
|
|
ruby #$0 revisionup
|
|
|
|
|
2013-12-25 20:28:18 -05:00
|
|
|
tagging major release
|
|
|
|
ruby #$0 tag 2.2.0
|
|
|
|
|
|
|
|
tagging patch release (about 2.1.0 or later, it means X.Y.Z (Z > 0) release)
|
2010-08-19 06:16:35 -04:00
|
|
|
ruby #$0 tag
|
|
|
|
|
2012-11-01 15:24:21 -04:00
|
|
|
tagging preview/RC
|
2013-12-25 20:28:18 -05:00
|
|
|
ruby #$0 tag 2.2.0-preview1
|
2012-11-01 15:24:21 -04:00
|
|
|
|
2010-08-19 06:16:35 -04:00
|
|
|
* all operations shall be applied to the working directory.
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def version
|
|
|
|
v = p = nil
|
|
|
|
open 'version.h', 'rb' do |f|
|
|
|
|
f.each_line do |l|
|
|
|
|
case l
|
|
|
|
when /^#define RUBY_VERSION "(\d)\.(\d)\.(\d)"$/
|
|
|
|
v = $~.captures
|
|
|
|
when /^#define RUBY_PATCHLEVEL (-?\d+)$/
|
|
|
|
p = $1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return v, p
|
|
|
|
end
|
|
|
|
|
2012-03-25 23:57:07 -04:00
|
|
|
def interactive str, editfile = nil
|
2010-08-19 06:16:35 -04:00
|
|
|
loop do
|
|
|
|
yield
|
2012-03-25 23:57:07 -04:00
|
|
|
STDERR.puts "#{str} ([y]es|[a]bort|[r]etry#{'|[e]dit' if editfile})"
|
2010-08-19 06:16:35 -04:00
|
|
|
case STDIN.gets
|
|
|
|
when /\Aa/i then exit
|
|
|
|
when /\Ar/i then redo
|
|
|
|
when /\Ay/i then break
|
2012-03-25 23:57:07 -04:00
|
|
|
when /\Ae/i then system(ENV["EDITOR"], editfile)
|
2010-08-19 06:16:35 -04:00
|
|
|
else exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def version_up
|
2012-01-02 21:39:15 -05:00
|
|
|
d = DateTime.now
|
|
|
|
d = d.new_offset(Rational(9,24)) # we need server locale (i.e. japanese) time
|
2013-02-22 23:49:16 -05:00
|
|
|
system(*%w'svn revert version.h')
|
2010-08-19 06:16:35 -04:00
|
|
|
v, p = version
|
|
|
|
|
|
|
|
teeny = v[2]
|
|
|
|
case v
|
|
|
|
when %w/1 9 2/
|
|
|
|
teeny = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
p = p.to_i
|
|
|
|
if p != -1
|
|
|
|
p += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
str = open 'version.h', 'rb' do |f| f.read end
|
|
|
|
[%W[RUBY_VERSION "#{v.join '.'}"],
|
|
|
|
%W[RUBY_VERSION_CODE #{v.join ''}],
|
|
|
|
%W[RUBY_VERSION_MAJOR #{v[0]}],
|
|
|
|
%W[RUBY_VERSION_MINOR #{v[1]}],
|
|
|
|
%W[RUBY_VERSION_TEENY #{teeny}],
|
|
|
|
%W[RUBY_RELEASE_DATE "#{d.strftime '%Y-%m-%d'}"],
|
|
|
|
%W[RUBY_RELEASE_CODE #{d.strftime '%Y%m%d'}],
|
|
|
|
%W[RUBY_PATCHLEVEL #{p}],
|
|
|
|
%W[RUBY_RELEASE_YEAR #{d.year}],
|
|
|
|
%W[RUBY_RELEASE_MONTH #{d.month}],
|
|
|
|
%W[RUBY_RELEASE_DAY #{d.day}],
|
|
|
|
].each do |(k, i)|
|
2013-02-22 23:49:16 -05:00
|
|
|
str.sub!(/^(#define\s+#{k}\s+).*$/, "\\1#{i}")
|
2010-08-19 06:16:35 -04:00
|
|
|
end
|
2013-02-22 23:49:16 -05:00
|
|
|
str.sub!(/\s+\z/m, '')
|
2010-08-19 06:16:35 -04:00
|
|
|
fn = sprintf 'version.h.tmp.%032b', rand(1 << 31)
|
|
|
|
File.rename 'version.h', fn
|
|
|
|
open 'version.h', 'wb' do |f|
|
|
|
|
f.puts str
|
|
|
|
end
|
|
|
|
File.unlink fn
|
|
|
|
end
|
|
|
|
|
2012-11-01 15:24:21 -04:00
|
|
|
def tag intv_p = false, relname=nil
|
|
|
|
# relname:
|
2013-12-25 20:28:18 -05:00
|
|
|
# * 2.2.0-preview1
|
|
|
|
# * 2.2.0-rc1
|
|
|
|
# * 2.2.0
|
2012-11-01 15:24:21 -04:00
|
|
|
v, pl = version
|
2010-08-19 06:16:35 -04:00
|
|
|
x = v.join('_')
|
2012-11-01 15:24:21 -04:00
|
|
|
if relname
|
2013-12-25 20:28:18 -05:00
|
|
|
abort "patchlevel is not -1 but '#{pl}' for preview or rc" if pl != '-1' && /-(?:preview|rc)/ =~ relname
|
|
|
|
abort "patchlevel is not 0 but '#{pl}' for the first release" if pl != '0' && /-(?:preview|rc)/ !~ relname
|
2012-11-01 15:24:21 -04:00
|
|
|
pl = relname[/-(.*)\z/, 1]
|
2013-12-25 20:28:18 -05:00
|
|
|
curver = v.join('.') + (pl ? '-' + pl : '')
|
2012-11-01 15:24:21 -04:00
|
|
|
if relname != curver
|
2013-12-25 20:28:18 -05:00
|
|
|
abort "given relname '#{relname}' conflicts current version '#{curver}'"
|
2012-11-01 15:24:21 -04:00
|
|
|
end
|
|
|
|
branch_url = `svn info`[/URL: (.*)/, 1]
|
|
|
|
else
|
|
|
|
if pl == '-1'
|
|
|
|
abort "no relname is given and not in a release branch even if this is patch release"
|
|
|
|
end
|
2013-12-25 20:28:18 -05:00
|
|
|
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 << x
|
|
|
|
else
|
|
|
|
abort "teeny must be greater than 0 for patch release" if v[2] == "0"
|
|
|
|
branch_url << x.sub(/_\d+$/, '')
|
|
|
|
end
|
2012-11-01 15:24:21 -04:00
|
|
|
end
|
2013-12-25 20:28:18 -05:00
|
|
|
tagname = 'v' + x + (v[0] < "2" || (v[0] == "2" && v[1] < "1") || /^(?:preview|rc)/ =~ pl ? '_' + pl : '')
|
2012-11-01 15:24:21 -04:00
|
|
|
tag_url = $repos + 'tags/' + tagname
|
2010-08-19 06:16:35 -04:00
|
|
|
if intv_p
|
2012-11-01 15:24:21 -04:00
|
|
|
interactive "OK? svn cp -m \"add tag #{tagname}\" #{branch_url} #{tag_url}" do
|
2010-08-19 06:16:35 -04:00
|
|
|
end
|
|
|
|
end
|
2013-02-22 23:49:16 -05:00
|
|
|
system(*%w'svn cp -m', "add tag #{tagname}", branch_url, tag_url)
|
2010-08-19 06:16:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def default_merge_branch
|
2012-02-12 02:33:09 -05:00
|
|
|
%r{^URL: .*/branches/ruby_1_8_} =~ `svn info` ? 'branches/ruby_1_8' : 'trunk'
|
2010-08-19 06:16:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
case ARGV[0]
|
|
|
|
when "up", /\A(ver|version|rev|revision|lv|level|patch\s*level)\s*up/
|
|
|
|
version_up
|
|
|
|
system 'svn diff version.h'
|
|
|
|
when "tag"
|
2012-11-01 15:24:21 -04:00
|
|
|
tag :interactive, ARGV[1]
|
2010-08-19 06:16:35 -04:00
|
|
|
when nil, "-h", "--help"
|
|
|
|
help
|
|
|
|
exit
|
|
|
|
else
|
2012-02-07 20:04:07 -05:00
|
|
|
system 'svn up'
|
2012-02-06 07:55:56 -05:00
|
|
|
|
2012-09-23 22:23:48 -04:00
|
|
|
if /--ticket=(.*)/ =~ ARGV[0]
|
|
|
|
tickets = $1.split(/,/).map{|num| " [Backport ##{num}]"}
|
|
|
|
ARGV.shift
|
2012-10-12 03:07:10 -04:00
|
|
|
else
|
|
|
|
tickets = []
|
2012-09-23 22:23:48 -04:00
|
|
|
end
|
|
|
|
|
2010-08-19 06:16:35 -04:00
|
|
|
q = $repos + (ARGV[1] || default_merge_branch)
|
2014-02-26 23:10:03 -05:00
|
|
|
revstr = ARGV[0].delete('^, :\-0-9')
|
|
|
|
revs = revstr.split(/[,\s]+/)
|
2010-08-19 06:16:35 -04:00
|
|
|
log = ''
|
|
|
|
log_svn = ''
|
|
|
|
|
|
|
|
revs.each do |rev|
|
|
|
|
case rev
|
2014-02-26 23:10:03 -05:00
|
|
|
when /\A\d+:\d+\z/
|
2010-08-19 06:16:35 -04:00
|
|
|
r = ['-r', rev]
|
2014-02-26 23:10:03 -05:00
|
|
|
when /\A(\d+)-(\d+)\z/
|
2014-02-27 09:31:24 -05:00
|
|
|
rev = "#{$1.to_i-1}:#$2"
|
2014-02-26 23:10:03 -05:00
|
|
|
r = ['-r', rev]
|
|
|
|
when /\A\d+\z/
|
2010-08-19 06:16:35 -04:00
|
|
|
r = ['-c', rev]
|
|
|
|
when nil then
|
|
|
|
puts "#$0 revision"
|
|
|
|
exit
|
2014-02-26 23:10:03 -05:00
|
|
|
else
|
|
|
|
puts "invalid revision part '#{rev}' in '#{ARGV[0]}'"
|
|
|
|
exit
|
2010-08-19 06:16:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
l = IO.popen %w'svn diff' + r + %w'--diff-cmd=diff -x -pU0' + [File.join(q, 'ChangeLog')] do |f|
|
|
|
|
f.read
|
|
|
|
end
|
|
|
|
|
|
|
|
log << l
|
|
|
|
log_svn << l.lines.grep(/^\+\t/).join.gsub(/^\+/, '').gsub(/^\t\*/, "\n\t\*")
|
|
|
|
|
|
|
|
if log_svn.empty?
|
|
|
|
log_svn = IO.popen %w'svn log ' + r + [q] do |f|
|
|
|
|
f.read
|
2012-02-16 22:37:44 -05:00
|
|
|
end.sub(/\A-+\nr.*\n/, '').sub(/\n-+\n\z/, '').gsub(/^(?=\S)/, "\t")
|
2010-08-19 06:16:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
a = %w'svn merge --accept=postpone' + r + [q]
|
|
|
|
STDERR.puts a.join(' ')
|
|
|
|
|
|
|
|
system(*a)
|
2013-02-22 23:49:16 -05:00
|
|
|
system(*%w'svn revert ChangeLog') if /^\+/ =~ l
|
2010-08-19 06:16:35 -04:00
|
|
|
end
|
|
|
|
|
2013-02-21 03:31:45 -05:00
|
|
|
if `svn diff --diff-cmd=diff -x -upw`.empty?
|
|
|
|
interactive 'Only ChangeLog is modified, right?' do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-08-19 06:16:35 -04:00
|
|
|
if /^\+/ =~ log
|
2013-02-22 23:49:16 -05:00
|
|
|
system(*%w'svn revert ChangeLog')
|
2010-08-19 06:16:35 -04:00
|
|
|
IO.popen %w'patch -p0', 'wb' do |f|
|
|
|
|
f.write log.gsub(/\+(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [ 123][0-9] [012][0-9]:[0-5][0-9]:[0-5][0-9] \d\d\d\d/,
|
|
|
|
# this format-time-string was from the file local variables of ChangeLog
|
|
|
|
'+'+Time.now.strftime('%a %b %e %H:%M:%S %Y'))
|
|
|
|
end
|
2013-02-22 23:49:16 -05:00
|
|
|
system(*%w'touch ChangeLog') # needed somehow, don't know why...
|
2010-08-19 06:16:35 -04:00
|
|
|
else
|
|
|
|
STDERR.puts '*** You should write ChangeLog NOW!!! ***'
|
|
|
|
end
|
|
|
|
|
|
|
|
version_up
|
|
|
|
f = Tempfile.new 'merger.rb'
|
2014-02-26 23:10:03 -05:00
|
|
|
f.printf "merge revision(s) %s:%s\n", revstr, tickets.join
|
2010-08-19 06:16:35 -04:00
|
|
|
f.write log_svn
|
|
|
|
f.flush
|
|
|
|
f.close
|
|
|
|
|
2012-03-25 23:57:07 -04:00
|
|
|
interactive 'conflicts resolved?', f.path do
|
2012-03-25 23:57:03 -04:00
|
|
|
IO.popen(ENV["PAGER"] || "less", "w") do |g|
|
|
|
|
g << `svn stat`
|
|
|
|
g << "\n\n"
|
2012-03-25 23:57:07 -04:00
|
|
|
f.open
|
2012-03-25 23:57:03 -04:00
|
|
|
g << f.read
|
2012-03-25 23:57:07 -04:00
|
|
|
f.close
|
2012-03-25 23:57:03 -04:00
|
|
|
g << "\n\n"
|
|
|
|
g << `svn diff --diff-cmd=diff -x -upw`
|
2010-08-19 06:16:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-22 23:49:16 -05:00
|
|
|
if system(*%w'svn ci -F', f.path)
|
2010-08-19 06:16:35 -04:00
|
|
|
# tag :interactive # no longer needed.
|
|
|
|
system 'rm -f subversion.commitlog'
|
|
|
|
else
|
|
|
|
puts 'commit failed; try again.'
|
|
|
|
end
|
|
|
|
|
|
|
|
f.close
|
|
|
|
end
|