ruby-changes:55598
From: Takashi <ko1@a...>
Date: Mon, 29 Apr 2019 00:22:46 +0900 (JST)
Subject: [ruby-changes:55598] Takashi Kokubun:fad2825e42 (trunk): Support `tool/merger.rb tag` under Git repository
https://git.ruby-lang.org/ruby.git/commit/?id=fad2825e42 From fad2825e42d80145ca7047f840b9b0cea00d0ca9 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun <takashikkbn@g...> Date: Sun, 28 Apr 2019 23:51:43 +0900 Subject: Support `tool/merger.rb tag` under Git repository diff --git a/tool/merger.rb b/tool/merger.rb index d89a71f..db35ea6 100755 --- a/tool/merger.rb +++ b/tool/merger.rb @@ -10,6 +10,7 @@ require 'fileutils' https://github.com/ruby/ruby/blob/trunk/tool/merger.rb#L10 require 'tempfile' require 'net/http' require 'uri' +require 'shellwords' ENV['LC_ALL'] = 'C' @@ -49,7 +50,7 @@ module Merger https://github.com/ruby/ruby/blob/trunk/tool/merger.rb#L50 def interactive(str, editfile = nil) loop do - yield + yield if block_given? STDERR.puts "\e[1;33m#{str} ([y]es|[a]bort|[r]etry#{'|[e]dit' if editfile})\e[0m" case STDIN.gets when /\Aa/i then exit @@ -103,48 +104,52 @@ module Merger https://github.com/ruby/ruby/blob/trunk/tool/merger.rb#L104 File.unlink(fn) end -def tag intv_p = false, relname=nil - # relname: - # * 2.2.0-preview1 - # * 2.2.0-rc1 - # * 2.2.0 - v, pl = version - x = v.join('_') - if relname - 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 - pl = relname[/-(.*)\z/, 1] - curver = v.join('.') + (pl ? '-' + pl : '') - if relname != curver - abort "given relname '#{relname}' conflicts current version '#{curver}'" - 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 - 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 - end - tagname = 'v' + x + (v[0] < "2" || (v[0] == "2" && v[1] < "1") || /^(?:preview|rc)/ =~ pl ? '_' + pl : '') - tag_url = "#{REPOS}tags/#{tagname}" - system(*%w'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 - if intv_p - interactive "OK? svn cp -m \"add tag #{tagname}\" #{branch_url} #{tag_url}" do - # nothing to do here + def tag(relname) + # relname: + # * 2.2.0-preview1 + # * 2.2.0-rc1 + # * 2.2.0 + v, pl = version + if relname + 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 + pl = relname[/-(.*)\z/, 1] + curver = "#{v.join('.')}#{("-#{pl}" if pl)}" + if relname != curver + abort "given relname '#{relname}' conflicts current version '#{curver}'" + end + else + if pl == '-1' + abort 'no relname is given and not in a release branch even if this is patch release' + end + end + tagname = "v#{v.join('_')}#{("_#{pl}" if v[0] < "2" || (v[0] == "2" && v[1] < "1") || /^(?:preview|rc)/ =~ pl)}" + + if svn_mode? + if relname + 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}" + unless system('svn', 'info', tag_url, out: IO::NULL, err: IO::NULL) + 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 - end - system(*%w'svn cp -m', "add tag #{tagname}", branch_url, tag_url) -end def remove_tag intv_p = false, relname # relname: @@ -217,6 +222,14 @@ end https://github.com/ruby/ruby/blob/trunk/tool/merger.rb#L222 end return v, p end + + def execute(*cmd, interactive: false) + if interactive + Merger.interactive("OK?: #{cmd.shelljoin}") + end + puts "+ #{cmd.shelljoin}" + system(*cmd) + end end # class << self end # module Merger @@ -228,7 +241,7 @@ when "up", /\A(ver|version|rev|revision|lv|level|patch\s*level)\s*up\z/ https://github.com/ruby/ruby/blob/trunk/tool/merger.rb#L241 Merger.version_up Merger.diff('version.h') when "tag" - Merger.tag :interactive, ARGV[1] + Merger.tag(ARGV[1]) when /\A(?:remove|rm|del)_?tag\z/ Merger.remove_tag :interactive, ARGV[1] when nil, "-h", "--help" @@ -317,7 +330,6 @@ else https://github.com/ruby/ruby/blob/trunk/tool/merger.rb#L330 end if system(*%w'svn ci -F', f.path) - # tag :interactive # no longer needed. system 'rm -f subversion.commitlog' else puts 'commit failed; try again.' -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/