ruby-changes:73958
From: Nobuyoshi <ko1@a...>
Date: Wed, 12 Oct 2022 12:28:02 +0900 (JST)
Subject: [ruby-changes:73958] df588440ee (master): sync_default_gems: Replace the external URIs to docs with rdoc-ref
https://git.ruby-lang.org/ruby.git/commit/?id=df588440ee From df588440ee01e91d87cb815ff85dd6c785dc7827 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 12 Oct 2022 11:50:25 +0900 Subject: sync_default_gems: Replace the external URIs to docs with rdoc-ref --- tool/sync_default_gems.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb index 530ec6e7b3..3aabd3739c 100755 --- a/tool/sync_default_gems.rb +++ b/tool/sync_default_gems.rb @@ -84,6 +84,30 @@ def pipe_readlines(args, rs: "\0", chomp: true) https://github.com/ruby/ruby/blob/trunk/tool/sync_default_gems.rb#L84 end end +def replace_rdoc_ref(file) + src = File.binread(file) + src.gsub!(%r[\[\Khttps://docs\.ruby-lang\.org/en/master/(([A-Z]\w+(?:/[A-Z]\w+)*)|\w+_rdoc)\.html(\#\S+)?(?=\])]) do + name, mod, label = $1, $2, $3 + mod &&= mod.gsub('/', '::') + if label && (m = label.match(/\A\#(?:method-([ci])|(?:(?:class|module)-#{mod}-)?label)-([-+\w]+)\z/)) + scope, label = m[1], m[2] + scope = scope ? scope.tr('ci', '.#') : '@' + end + "rdoc-ref:#{mod || name.chomp("_rdoc") + ".rdoc"}#{scope}#{label}" + end or return false + File.rename(file, file + "~") + File.binwrite(file, src) + return true +end + +def replace_rdoc_ref_all + result = pipe_readlines(%W"git status porcelain -z -- *.c *.rb *.rdoc") + result.map! {|line| line[/\A.M (.*)/, 1]} + result.compact! + result = pipe_readlines(%W"git grep -z -l -F [https://docs.ruby-lang.org/en/master/ --" + result) + result.inject(false) {|changed, file| changed | replace_rdoc_ref(file)} +end + # 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] @@ -382,6 +406,7 @@ def sync_default_gems(gem) https://github.com/ruby/ruby/blob/trunk/tool/sync_default_gems.rb#L406 else sync_lib gem, upstream end + replace_rdoc_ref_all end IGNORE_FILE_PATTERN = @@ -508,6 +533,10 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil) https://github.com/ruby/ruby/blob/trunk/tool/sync_default_gems.rb#L533 next end + if replace_rdoc_ref_all + `git commit --amend --no-edit` + end + puts "Update commit message: #{sha}" IO.popen(%W[git filter-branch -f --msg-filter #{[filter, repo, sha].join(' ')} -- HEAD~1..HEAD], &:read) -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/