root/docs/shyouhei/ruby development/merger.rb @ 30518

Revision 30518, 3.5 kB (checked in by shyouhei, 6 years ago)

support for svn 1.5

Line 
1#! /bin/ruby
2
3require 'date'
4require 'tempfile'
5
6$repos = 'svn+ssh://svn@ci.ruby-lang.org/ruby/'
7
8def version
9  v = nil
10  p = nil
11  open 'version.h', 'rb' do |f|
12    f.each_line do |l|
13      case l
14      when /^#define RUBY_VERSION "(\d)\.(\d)\.(\d)"$/
15        v = $~.captures
16      when /^#define RUBY_PATCHLEVEL (\d+)$/
17        p = $1
18      end
19    end
20  end
21  return v, p
22end
23
24def interactive str
25  loop do
26    yield
27    STDERR.puts str
28    case STDIN.gets
29    when /\Aa/i then exit
30    when /\Ar/i then redo
31    when /\Ay/i then break
32    else exit
33    end
34  end
35end
36
37def version_up
38  d = Date.today
39  system *%w'svn revert version.h'
40  v, p = version
41
42  open 'version.h', 'r+b' do |f|
43    str = f.read
44    [%W[RUBY_VERSION      "#{v.join '.'}"],
45     %W[RUBY_VERSION_CODE  #{v.join ''}],
46     %W[RUBY_VERSION_MAJOR #{v[0]}],
47     %W[RUBY_VERSION_MINOR #{v[1]}],
48     %W[RUBY_VERSION_TEENY #{v[2]}],
49     %W[RUBY_RELEASE_DATE "#{d.strftime '%Y-%m-%d'}"],
50     %W[RUBY_RELEASE_CODE  #{d.strftime '%Y%m%d'}],
51     %W[RUBY_PATCHLEVEL    #{p.to_i.succ.to_s}],
52     %W[RUBY_RELEASE_YEAR  #{d.year}],
53     %W[RUBY_RELEASE_MONTH #{d.month}],
54     %W[RUBY_RELEASE_DAY   #{d.day}],
55    ].each do |(k, i)|
56      str.sub! /^(#define\s+#{k}\s+).*$/, "\\1#{i}"
57    end
58    f.rewind
59    f.write str
60  end
61end
62
63def tag intv_p = false
64  v, p = version
65  x = v.join('_')
66  y = $repos + 'branches/ruby_' + x
67  z = 'v' + x + '_' + p
68  w = $repos + 'tags/' + z
69  if intv_p
70    interactive "OK? svn cp -m \"add tag #{z}\" #{y} #{w} ([y]es|[a]bort|[r]etry)" do
71    end
72  end
73  system *%w'svn cp -m' + ["add tag #{z}"] + [y, w]
74end
75
76case ARGV[0]
77when "up", /\A(ver|version|rev|revision|lv|level|patch\s*level)\s*up/
78  version_up
79  system 'svn diff version.h'
80when "tag"
81  tag :interactive
82else
83  q = $repos + (ARGV[1] || 'branches/ruby_1_8')
84  revs = ARGV[0].split /,\s*/
85  log = ''
86  log_svn = ''
87
88  revs.each do |rev|
89    case rev
90    when /\A\d+:\d+\z/
91      r = ['-r', rev]
92    when /\A\d+\z/
93      r = ['-c', rev]
94    when nil then
95      puts "#$0 revision"
96      exit
97    end
98
99    l = IO.popen %w'svn diff' + r + %w'--diff-cmd=diff -x -pU0' + [File.join(q, 'ChangeLog')] do |f|
100      f.read
101    end
102
103    log << l
104    log_svn << l.lines.grep(/^\+\t/).join.gsub(/^\+/, '')
105
106    a = %w'svn merge --accept=postpone' + r + [q]
107    STDERR.puts a.join(' ')
108
109    system(*a)
110    system *%w'svn revert ChangeLog' if /^\+/ =~ l
111  end
112
113  if /^\+/ =~ log
114    system *%w'svn revert ChangeLog'
115    IO.popen %w'patch -p 0', 'wb' do |f|
116      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/,
117                       # this format-time-string was from the file local variables of ChangeLog
118                       '+'+Time.now.strftime('%a %b %e %H:%M:%S %Y'))
119    end
120    system *%w'touch ChangeLog' # needed somehow, don't know why...
121  else
122    STDERR.puts '*** You should write ChangeLog NOW!!! ***'
123  end
124
125  version_up
126  f = Tempfile.new 'merger.rb'
127  f.printf "merge revision(s) %s:\n", ARGV[0]
128  f.write log_svn
129  f.flush
130  f.close
131  f.open # avoid gc
132
133  interactive 'conflicts resolved? (y:yes, a:abort, r:retry, otherwise abort)' do
134    f.rewind
135    r, w = IO.pipe
136    fork do
137      w.close
138      STDIN.reopen r
139      exec 'lv'
140    end
141    r.close
142    w << f.read
143    w << "\n\n"
144    w << `svn stat`
145    w << `svn diff --diff-cmd=diff -x -upw`
146    w.close
147    Process.waitall
148  end
149
150  if system *%w'svn ci -F' + [f.path]
151    tag :interactive
152    system 'rm -f subversion.commitlog'
153  else
154    puts 'commit failed; try again.'
155  end
156
157  f.close
158end
Note: See TracBrowser for help on using the browser.