summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-03-28 13:57:48 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-03-28 14:02:31 +0900
commit38ea2306d2c3a1a698424f61dabdb42cda1a904b (patch)
tree592ac9fedf9bd54b58016af7b85eb2dcb67b3765
parentfb6ebe55d91187d9635e0183d47dbf38e95b1141 (diff)
sync_default_gems.rb: preserve Co-Authored-By:
-rw-r--r--tool/sync_default_gems.rb18
1 files changed, 15 insertions, 3 deletions
diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb
index 352bc0c..bd6d8d9 100644
--- a/tool/sync_default_gems.rb
+++ b/tool/sync_default_gems.rb
@@ -356,6 +356,13 @@ IGNORE_FILE_PATTERN =
|[A-Z]\w+file
)\z/x
+def message_filter(repo, sha)
+ log = STDIN.read
+ print "[#{repo}] ", log.sub(/\s*(?=(?i:\nCo-authored-by:.*)*\Z)/) {
+ "\n\n" "https://github.com/#{repo}/commit/#{sha[0,10]}\n"
+ }
+end
+
def sync_default_gems_with_commits(gem, ranges, edit: nil)
repo = REPOSITORIES[gem.to_sym]
puts "Sync #{repo} with commit history."
@@ -369,7 +376,7 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil)
if ranges == true
log = IO.popen(%W"git log --fixed-strings --grep=[#{repo}] -n1 --format=%B", &:read)
- ranges = ["#{log[%r[https://github\.com/#{Regexp.quote(repo)}/commit/(\h+)\s*\Z], 1]}..#{gem}/master"]
+ ranges = ["#{log[%r[https://github\.com/#{Regexp.quote(repo)}/commit/(\h+)\n\s*(?i:co-authored-by:.*)*\s*\Z], 1]}..#{gem}/master"]
end
commits = ranges.flat_map do |range|
@@ -396,6 +403,7 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil)
ENV["FILTER_BRANCH_SQUELCH_WARNING"] = "1"
+ filter = [ENV.fetch('RUBY', 'ruby'), File.realpath(__FILE__), "--message-filter"]
commits.each do |sha, subject|
puts "Pick #{sha} from #{repo}."
@@ -442,8 +450,7 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil)
puts "Update commit message: #{sha}"
- suffix = "https://github.com/#{repo}/commit/#{sha[0,10]}"
- `git filter-branch -f --msg-filter 'grep "" - | sed "1s|^|[#{repo}] |" && echo && echo #{suffix}' -- HEAD~1..HEAD`
+ IO.popen(%W[git filter-branch -f --msg-filter #{[filter, repo, sha].join(' ')} -- HEAD~1..HEAD], &:read)
unless $?.success?
puts "Failed to modify commit message of #{sha}"
break
@@ -520,6 +527,11 @@ when "list"
next unless pattern =~ name or pattern =~ gem
printf "%-15s https://github.com/%s\n", name, gem
end
+when "--message-filter"
+ ARGV.shift
+ abort unless ARGV.size == 2
+ message_filter(*ARGV)
+ exit
when nil, "-h", "--help"
puts <<-HELP
\e[1mSync with upstream code of default libraries\e[0m