Skip to content

Commit

Permalink
sync_default_gems.rb: move default_branch to REPOSITORIES
Browse files Browse the repository at this point in the history
`sync_default_gems_with_commits` also needs the default branch.
  • Loading branch information
nobu committed Nov 28, 2022
1 parent 6559ba3 commit ee11090
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions tool/sync_default_gems.rb
Expand Up @@ -79,11 +79,26 @@ module SyncDefaultGems
pathname: "ruby/pathname",
digest: "ruby/digest",
error_highlight: "ruby/error_highlight",
syntax_suggest: "ruby/syntax_suggest",
syntax_suggest: ["ruby/syntax_suggest", "main"],
un: "ruby/un",
win32ole: "ruby/win32ole",
}

CLASSICAL_DEFAULT_BRANCH = "master"

class << REPOSITORIES
def [](gem)
repo, branch = super
return repo, branch || CLASSICAL_DEFAULT_BRANCH
end

def each_pair
super do |gem, (repo, branch)|
yield gem, [repo, branch || CLASSICAL_DEFAULT_BRANCH]
end
end
end

def pipe_readlines(args, rs: "\0", chomp: true)
IO.popen(args) do |f|
f.readlines(rs, chomp: chomp)
Expand Down Expand Up @@ -118,7 +133,7 @@ def replace_rdoc_ref_all

# We usually don't use this. Please consider using #sync_default_gems_with_commits instead.
def sync_default_gems(gem)
repo = REPOSITORIES[gem.to_sym]
repo, = REPOSITORIES[gem.to_sym]
puts "Sync #{repo}"

upstream = File.join("..", "..", repo)
Expand Down Expand Up @@ -465,7 +480,7 @@ def message_filter(repo, sha, input: ARGF)
# @param ranges [Array<String>] "before..after". Note that it will NOT sync "before" (but commits after that).
# @param edit [TrueClass] Set true if you want to resolve conflicts. Obviously, update-default-gem.sh doesn't use this.
def sync_default_gems_with_commits(gem, ranges, edit: nil)
repo = REPOSITORIES[gem.to_sym]
repo, default_branch = REPOSITORIES[gem.to_sym]
puts "Sync #{repo} with commit history."

IO.popen(%W"git remote") do |f|
Expand All @@ -478,7 +493,7 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil)
if ranges == true
pattern = "https://github\.com/#{Regexp.quote(repo)}/commit/([0-9a-f]+)$"
log = IO.popen(%W"git log -E --grep=#{pattern} -n1 --format=%B", &:read)
ranges = ["#{log[%r[#{pattern}\n\s*(?i:co-authored-by:.*)*\s*\Z], 1]}..#{gem}/master"]
ranges = ["#{log[%r[#{pattern}\n\s*(?i:co-authored-by:.*)*\s*\Z], 1]}..#{gem}/#{default_branch}"]
end

commits = ranges.flat_map do |range|
Expand Down Expand Up @@ -609,13 +624,8 @@ def sync_lib(repo, upstream = nil)

def update_default_gems(gem, release: false)

author, repository = REPOSITORIES[gem.to_sym].split('/')
default_branch = case gem
when 'syntax_suggest'
"main"
else
"master"
end
repository, default_branch = REPOSITORIES[gem.to_sym]
author, repository = repository.split('/')

puts "Update #{author}/#{repository}"

Expand Down Expand Up @@ -652,21 +662,21 @@ def update_default_gems(gem, release: false)
if ARGV[1]
update_default_gems(ARGV[1])
else
REPOSITORIES.keys.each{|gem| update_default_gems(gem.to_s)}
REPOSITORIES.each_key {|gem| update_default_gems(gem.to_s)}
end
when "all"
if ARGV[1] == "release"
REPOSITORIES.keys.each do |gem|
REPOSITORIES.each_key do |gem|
update_default_gems(gem.to_s, release: true)
sync_default_gems(gem.to_s)
end
else
REPOSITORIES.keys.each{|gem| sync_default_gems(gem.to_s)}
REPOSITORIES.each_key {|gem| sync_default_gems(gem.to_s)}
end
when "list"
ARGV.shift
pattern = Regexp.new(ARGV.join('|'))
REPOSITORIES.each_pair do |name, gem|
REPOSITORIES.each_pair do |name, (gem)|
next unless pattern =~ name or pattern =~ gem
printf "%-15s https://github.com/%s\n", name, gem
end
Expand Down

0 comments on commit ee11090

Please sign in to comment.